//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool gestioneLicenze() { ArrayResize( listaLicenze, 0 ); //+------------------------------------------------------------------+ //| Aggiungere di seguito le licenze | //+------------------------------------------------------------------+ //aggiungiLicenza( "Piergiorgio Parigi", D'2100.04.10 00:00', 2100132316 ); //aggiungiLicenza( "Leoanardo Fasciano", D'2100.04.10 00:00', 31153130 ); //aggiungiLicenza( "Cristina Tarullo", D'2021.04.10 00:00', 2145722601 ); //aggiungiLicenza( "Pierfrancesco Rossi", D'2021.04.10 00:00', 2145724972 ); //aggiungiLicenza( "Pierfrancesco Rossi", D'2021.04.10 00:00', 2100132882 ); //aggiungiLicenza( "Giuseppe Bellotoma", D'2024.04.10 00:00', 99219 ); //aggiungiLicenza( "Raino Francesco", D'2024.04.10 00:00', 3387971 ); //aggiungiLicenza( "Raino Francesco", D'2024.04.10 00:00', 5947337 ); //aggiungiLicenza( "Niccolo Campa", D'2024.06.10 00:00', 2145710155 ); //aggiungiLicenza( "Barbara Pisana", D'2024.07.08 00:00', 9056637 ); //aggiungiLicenza( "Barbara Pisana", D'2024.06.10 00:00', 628782 ); //aggiungiLicenza( "Monica Brenna", D'2024.06.10 00:00', 137980 ); //aggiungiLicenza( "Patrick Bezzoli", D'2024.06.10 00:00', 2145718764 ); //aggiungiLicenza( "Meryl Tarazon", D'2024.07.08 00:00', 2100135242 ); //aggiungiLicenza( "Giovanni Valerio Casamento", D'2024.07.08 00:00', 2100130828 ); if( ArraySize( listaLicenze ) == 0 ) { return true; } //Controllo gestione licenze for( int i = 0; i < ArraySize( listaLicenze ); i++ ) { if( listaLicenze[i].conto1 == AccountInfoInteger( ACCOUNT_LOGIN ) || listaLicenze[i].conto2 == AccountInfoInteger( ACCOUNT_LOGIN ) || listaLicenze[i].conto3 == AccountInfoInteger( ACCOUNT_LOGIN ) || listaLicenze[i].conto4 == AccountInfoInteger( ACCOUNT_LOGIN ) || listaLicenze[i].conto5 == AccountInfoInteger( ACCOUNT_LOGIN ) ) { if( listaLicenze[i].timeScadenza > TimeCurrent() ) { return true; } else { return false; } } } return false; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void aggiungiLicenza( string _nome, datetime _timeScadenza, int conto1, int conto2 = 0, int conto3 = 0, int conto4 = 0, int conto5 = 0 ) { ArrayResize( listaLicenze, ArraySize( listaLicenze ) + 1); listaLicenze[ArraySize( listaLicenze ) -1 ].nome = _nome; listaLicenze[ArraySize( listaLicenze ) -1 ].timeScadenza = _timeScadenza; listaLicenze[ArraySize( listaLicenze ) -1 ].conto1 = conto1; listaLicenze[ArraySize( listaLicenze ) -1 ].conto2 = conto2; listaLicenze[ArraySize( listaLicenze ) -1 ].conto3 = conto3; listaLicenze[ArraySize( listaLicenze ) -1 ].conto4 = conto4; listaLicenze[ArraySize( listaLicenze ) -1 ].conto5 = conto5; } class Licenza { public : string nome; datetime timeScadenza; int conto1; int conto2; int conto3; int conto4; int conto5; }; Licenza listaLicenze[]; //+------------------------------------------------------------------+ //| EM_EA News.mq4 | //| Copyright 2024, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property strict enum ETipoIngresso { EBreakout, //Breakout EPostNews, //Post News EManuale, //Manuale (Data&Ora) }; enum ETipoTrailingStop { ETrailingInPunti, //Trailing in Points ETrailingMaxMinCandela, //Trailing su Max/Min barra }; enum ETipoCalcoloSize { ELottiFissi, //Lotti Fissi EPercentualeEquity, //% su Equity EPercentualeBalance, //% su Balance }; enum ETipoStopTarget { EFisicoSuOrdine, //Fisico sull'ordine EVirtuale, //Virtuale }; class News { public : datetime timeNews; string nomeNews; string valuta; string importanza; }; //parametro slippage massimo //Ingresso dopo rilascio della news //Ingresso a data e ora //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ input int Magic = 1; //Identificativo EA (Magic Number) int Magic2 = Magic * -1; input string eaOper35 = "----------------- News Settings --------------------"; //<> bool UseNewsFilter = true; //Use news Filter input bool mostraListaNews = true; //Show news list input bool UseHighImpact=true; //Use News High Impact input int MinutesBefore3Tori = 10; //Minutes Before High Impact input int MinutesAfter3Tori = 0; //Minutes After High Impact input bool UseMediumImpact=true; //Use News Medium Impact input int MinutesBefore2Tori = 10; //Minutes Before Medium Impact input int MinutesAfter2Tori = 0; //Minutes After Medium Impact input bool UseLowImpact=false; //Use News Low Impact input int MinutesBefore1Tori = 10; //Minutes Before Low Impact input int MinutesAfter1Tori = 0; //Minutes After Low Impact input string listaStrumenti = "GBP,USD,CAD,EUR,NZD,CHF,JPY,AUD"; //Currency List (separates by ,) input bool utilizzaCustomNews = false; //Use Custom News input string listaCustomNews = ""; //Custom news list (separates da ;) input int MinutesBeforeCustom = 30; //Minutes Before Custom News input int MinutesAfterCustom = 0; //Minutes After Custom News input string eaOper37 = "----------------- Impostazioni operatività --------------------"; //<> input ETipoIngresso tipoOperativita = EManuale; //Selezionare il tipo di operatività input int minutiRimozionePendentiNonFillati = 10; //Minuti rimozione pendenti non fillati input datetime timeIngressoManuale = D'2024.01.01 14:30'; //Time ingresso manuale input datetime timeFineSpostamentoManuale = D'2024.01.01 14:30'; //Time fine spostamento manuale input ETipoCalcoloSize tipoCalcoloSize = ELottiFissi; //Selezionare il tipo di calcolo della size input double lottiOrdine = 0.01; //Lotti ordine o rischio % input int slippageMassimo = 50; //Slippage massimo input int pointsDistanzaOrdini = 100; //Punti Distanza ordini input int pointsSpreadMassimo = 0; //Poins Spread massimo, 0 è illimitato input ETipoStopTarget tipoStoploss = EFisicoSuOrdine; //Selezionare il tipo di stoploss input int puntiStoploss = 200; //Points Stoploss input ETipoStopTarget tipoTakeprofit = EVirtuale; //Selezionare il tipo di takeprofit input int pointsTakeprofit = 100; //Takeprofit input double percentualeChiusuraAlTakeprofit = 50; //Percentuale chiusura al Takeprofit input int pointsPiazzamentoBreakeven = 0; //Points Piazzamento Breakeven, se 0 è disattivato input int pointsBreakeven = 20; //Points Breakeven input ETipoTrailingStop tipoTrailingStop = ETrailingInPunti; //Selezionare il tipo di trailing input int pointsTrailingStopStart = 0; //Points Trailing Stop Start, se 0 è disattivato input int pointsTrailingStop = 50; //Points Trailing Stop input int pointsTrailingStep = 20; //Points Trailing Step input int pointsAggiuntiviPerTrailing = 0; //Points aggiuntivi per Trailing su Max/Min barra input bool mostraStatistiche = false; //Mostra Statistiche input string exEA1 = "<---------- Allarmi ---------->"; //<> input string exEA2 = ""; //<--- Allarmi causa Errori ---> input bool utilizzaAllarmiErrore = true; //Allarmi EA per errori input bool utilizzaAlertErrore = true; //Utilizza Allarme per errori input bool utilizzaPopupErrore = true; //Utilizza Notifiche Push per errori input bool utilizzaMailErrore = true; //Utilizza Invio Mail per errori input string exEA3 = ""; //<--- Allarmi per Inserimento Ordini ---> input bool utilizzaAllarmiInserimentoOrdini = true; //Allarmi EA per inserimento ordini input bool utilizzaAlertInserimentoOrdini = true; //Utilizza Allarme per inserimento ordini input bool utilizzaPopupInserimentoOrdini = true; //Utilizza Notifiche Push per inserimento ordini input bool utilizzaMailInserimentoOrdini = true; //Utilizza Invio Mail per inserimento ordini input string exEA4 = ""; //<--- Allarmi per Modifica Ordini( Stoploss & Takeprofit )---> input bool utilizzaAllarmiModificaOrdini = true; //Allarmi EA per modifica ordini input bool utilizzaAlertModificaOrdini = true; //Utilizza Allarme per modifica ordini input bool utilizzaPopupModificaOrdini = true; //Utilizza Notifiche Push per modifica ordini input bool utilizzaMailModificaOrdini = true; //Utilizza Invio Mail per modifica ordini //+------------------------------------------------------------------+ //| Variabili Globali | //+------------------------------------------------------------------+ string Timeframe_Mail = ""; datetime dataInputEA = 0; string prefisso = "News EA"; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if( !gestioneLicenze() ) { Alert( "Attenzione, non si è in possesso della licenza per utilizzare questo strumento" ); return INIT_FAILED; } //reset lastcheck=0; ArrayResize( ar_symbol_, 0); ArrayResize( ar_impact_, 0); ArrayResize( ar_news_title_, 0); ArrayResize( ar_time_, 0); ArrayResize( listaNewsOperative, 0 ); diff_cur_news=0; last_load_date=0; mins_between_load=360; if( !MQLInfoInteger(MQL_TESTER) && UseNewsFilter ) { bool newsLocal = false; permessoNews( newsLocal ); } if( !controlloOnInit() ) { return INIT_FAILED; } statistiche(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectsDeleteAll( 0, prefisso, -1, -1 ); } //+------------------------------------------------------------------+ //| Controllo OnInit | //+------------------------------------------------------------------+ bool controlloOnInit() { Magic2 = Magic * -1; if( Magic <= 0 ) { Alert( "Errore, il Magic non può essere <= 0"); return false; } //Determino Timeframe switch( Period() ) { case 1 : Timeframe_Mail = "1 Minuto"; break; case 5 : Timeframe_Mail = "5 Minuti"; break; case 15 : Timeframe_Mail = "15 Minuti"; break; case 30 : Timeframe_Mail = "30 Minuti"; break; case 60 : Timeframe_Mail = "Orario"; break; case 240 : Timeframe_Mail = "4 Ore"; break; case 1440 : Timeframe_Mail = "Giornaliero"; break; case 10080 : Timeframe_Mail = "Settimanale"; break; case 43200 : Timeframe_Mail = "Mensile"; break; default : Timeframe_Mail = "null"; } if( dataInputEA == 0 ) dataInputEA = TimeCurrent(); creaLabel( prefisso + "magic", IntegerToString( Magic ), 5, 30, clrGray, 20, ANCHOR_RIGHT, 1 ); creaBottone( prefisso + "inserisciOrdine", "Inserisci ordini", 20, 50, 160, 35, clrLimeGreen, clrWhite, 10, CORNER_LEFT_LOWER ); return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void creaBottone( string _nomeBottone, string _scrittasulbottone, int _distanzaX, int _distanzaY, int _grandezzaX, int _grandezzaY, color _colorePulsante, color _ColoreScritta, int _grandezzaFONT, ENUM_BASE_CORNER _corner = CORNER_RIGHT_UPPER ) { ObjectCreate(0,_nomeBottone,OBJ_BUTTON,0,0,0); ObjectSetInteger(0,_nomeBottone,OBJPROP_XDISTANCE,(int)(_distanzaX * 1)); ObjectSetInteger(0,_nomeBottone,OBJPROP_CORNER, _corner); ObjectSetInteger(0,_nomeBottone,OBJPROP_YDISTANCE,(int)(_distanzaY * 1)); ObjectSetInteger(0,_nomeBottone,OBJPROP_XSIZE,(int)(_grandezzaX * 1)); ObjectSetInteger(0,_nomeBottone,OBJPROP_YSIZE,(int)(_grandezzaY * 1)); ObjectSetString(0,_nomeBottone,OBJPROP_TEXT,_scrittasulbottone); ObjectSetString(0,_nomeBottone,OBJPROP_FONT,"Dubai"); // ObjectSetText(_nomeBottone,_scrittasulbottone,12, "Estrangelo Edessa", _ColoreScritta); ObjectSetInteger(0,_nomeBottone,OBJPROP_COLOR,_ColoreScritta); ObjectSetInteger(0,_nomeBottone,OBJPROP_BGCOLOR,_colorePulsante); ObjectSetInteger(0,_nomeBottone,OBJPROP_BORDER_COLOR,_colorePulsante); ObjectSetInteger(0,_nomeBottone,OBJPROP_BORDER_TYPE,BORDER_RAISED); ObjectSetInteger(0,_nomeBottone,OBJPROP_HIDDEN,true); ObjectSetInteger(0,_nomeBottone,OBJPROP_STATE,false); ObjectSetInteger(0,_nomeBottone,OBJPROP_FONTSIZE,_grandezzaFONT); ObjectSetInteger(0,_nomeBottone,OBJPROP_BACK,false); } //+------------------------------------------------------------------+ //| Funzioni Grafiche | //+------------------------------------------------------------------+ void creaLabel(string _nome, string _stringa, int _xdistance, int _ydistance, color _colore, int _grandezzaFont, ENUM_ANCHOR_POINT _anchor, int _corner) { ObjectCreate(_nome, OBJ_LABEL, 0, 0, 0); ObjectSetText(_nome,_stringa, _grandezzaFont, "Bahnschrift Light", _colore); ObjectSet(_nome, OBJPROP_CORNER, _corner); ObjectSet(_nome, OBJPROP_XDISTANCE, _xdistance); ObjectSet(_nome, OBJPROP_YDISTANCE, _ydistance); ObjectSetInteger( 0, _nome, OBJPROP_ANCHOR, _anchor ); } //+------------------------------------------------------------------+ //| Funzioni Allarmi | //+------------------------------------------------------------------+ datetime tempoNotifica; void erroreAlertEAFunc(string _tipoSegnale, string _extra, int _errore) { if( utilizzaAllarmiErrore) { if( utilizzaAlertErrore ) { Alert( "Error " + DoubleToStr( _errore, 0) + " " +_tipoSegnale + " " + prefisso + " " + Symbol() + " on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } if( !IsTesting() ) { if( utilizzaPopupErrore && tempoNotifica != Time[0] ) { SendNotification( "Error " + DoubleToStr( _errore, 0) + " " +_tipoSegnale + " " + prefisso + " " + Symbol() + " on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } if( utilizzaMailErrore && tempoNotifica != Time[0] ) { SendMail( "Error " + Symbol() + "TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) , "Error " + DoubleToStr( _errore, 0) + " " +_tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } } tempoNotifica = Time[0]; } else { Print( "Error " + DoubleToStr( _errore, 0) + " " +_tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } } void AlertIngressoEAFunc(string _tipoSegnale, string _extra) { if( utilizzaAllarmiInserimentoOrdini) { if( utilizzaAlertInserimentoOrdini ) { Alert( _tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } if( !IsTesting() ) { if( utilizzaPopupInserimentoOrdini) { SendNotification( _tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } if( utilizzaMailInserimentoOrdini) { SendMail( _tipoSegnale + Symbol() + " TF " + Timeframe_Mail + " with ID (Magic Number) " + DoubleToStr(Magic, 0 ) , _tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } } } } void AlertModifcaOrdiniEAFunc(string _tipoSegnale, string _extra) { if( utilizzaAllarmiModificaOrdini) { if( utilizzaAllarmiModificaOrdini ) { Alert( _tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } if( !IsTesting() ) { if( utilizzaAllarmiModificaOrdini) { SendNotification( _tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } if( utilizzaAllarmiModificaOrdini) { SendMail( _tipoSegnale + Symbol() + " TF " + Timeframe_Mail + " with ID (Magic Number) " + DoubleToStr(Magic, 0 ) , _tipoSegnale + " " + prefisso + " " + Symbol() +" on TF " + Timeframe_Mail + " with ID " + DoubleToStr(Magic, 0 ) + _extra ); } } } } //+------------------------------------------------------------------+ //| Presente Ordine Mercato | //+------------------------------------------------------------------+ bool presenteOrdineMercato( int _magic ) { for( int i = OrdersTotal(); i >= 0; i-- ) { if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == _magic ) { return true; } } return false; } bool presenteOrdineMercato() { for( int i = OrdersTotal(); i >= 0; i-- ) { if( OrderSelect( i, SELECT_BY_POS ) && (OrderMagicNumber() == Magic || OrderMagicNumber() == Magic2) ) { return true; } } return false; } //+------------------------------------------------------------------+ //| Presente Ordine Chiuso | //+------------------------------------------------------------------+ bool presenteOrdineChiuso( int _magic ) { for( int i = OrdersHistoryTotal() - 1; i >= 0; i-- ) { if( OrderSelect( i, SELECT_BY_POS, MODE_HISTORY ) ) { if( OrderCloseTime() < dataInputEA ) { return false; } if( OrderMagicNumber() == _magic ) { if( iBarShift( Symbol(), 0, OrderOpenTime(), true ) == 0 || iBarShift( Symbol(), 0, OrderCloseTime(), true) == 0 ) { return true; } } } } return false; } //+------------------------------------------------------------------+ //| Ordine | //+------------------------------------------------------------------+ void inviaOrdine( int _magic, ENUM_ORDER_TYPE _tipoOrdine, double _size, double _prezzo, string _commento, color _colore, double _stoploss = 0.0, double _takeprofit = 0.0 ) { _size = NormalizeDouble( _size, 2 ); _prezzo = NormalizeDouble( _prezzo, Digits ); bool inseritoOrdine = false; int cntTentativi = 0; int massimiTentativi = 10; string tipoOrdine = ""; if( _magic == Magic ) { tipoOrdine = "Long"; } else if( _magic == Magic2 ) { tipoOrdine = "Short"; } while( !inseritoOrdine && cntTentativi < massimiTentativi ) { RefreshRates(); int ticket = 0; if( (ticket = OrderSend( Symbol(), _tipoOrdine, _size, _prezzo, slippageMassimo, _stoploss, _takeprofit, _commento, _magic, 0, _colore)) < 0 ) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento ordine " + tipoOrdine + " " + _commento, "", errore ); cntTentativi++; } else { AlertIngressoEAFunc( tipoOrdine + " " + _commento, "" ); inseritoOrdine = true; break; } cntTentativi++; Sleep( 300 ); } } //+------------------------------------------------------------------+ //| Funzione Stoploss | //+------------------------------------------------------------------+ void stoplossFunction( int _magic, double valoreLivello, string _commentoAggiuntivo ) { double stopLevel = NormalizeDouble( SymbolInfoInteger( Symbol(), SYMBOL_TRADE_STOPS_LEVEL ) * Point, Digits ); if( _magic == Magic ) { if( Bid - valoreLivello < stopLevel ) { valoreLivello = NormalizeDouble( Bid - stopLevel, Digits ); } } else if( _magic == Magic2 ) { if( valoreLivello - Ask < stopLevel ) { valoreLivello = NormalizeDouble( Ask + stopLevel, Digits ); } } if( !OrderModify( OrderTicket(), OrderOpenPrice(), valoreLivello, OrderTakeProfit(), 0, clrRed)) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento " + _commentoAggiuntivo + " Stoploss " , ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( valoreLivello, Digits ), errore ); } else { AlertModifcaOrdiniEAFunc( "Inserimento " + _commentoAggiuntivo + " Stoploss " + OrderComment() + " al prezzo " + DoubleToStr( valoreLivello, Digits ), ""); } } //+------------------------------------------------------------------+ //| Funzione Takeprofit | //+------------------------------------------------------------------+ bool takeprofitFunction( int _magic, double valoreLivello ) { double stopLevel = NormalizeDouble( SymbolInfoInteger( Symbol(), SYMBOL_TRADE_STOPS_LEVEL ) * Point, Digits ); if( _magic == Magic ) { if( valoreLivello - Bid < stopLevel ) { valoreLivello = NormalizeDouble( Bid + stopLevel, Digits ); } } else if( _magic == Magic2 ) { if( Ask - valoreLivello < stopLevel ) { valoreLivello = NormalizeDouble( Ask - stopLevel, Digits ); } } if( !OrderModify( OrderTicket(), OrderOpenPrice(), OrderStopLoss(), valoreLivello, 0, clrRed)) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento takeprofit " , ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( valoreLivello, Digits ), errore ); return false; } else { AlertModifcaOrdiniEAFunc( "Inserimento takeprofit " + OrderComment() + " al prezzo " + DoubleToStr( valoreLivello, Digits ), ""); return true; } return false; } //+------------------------------------------------------------------+ //| Arrontonda stoploss e tp | //+------------------------------------------------------------------+ bool arrotondaStoplossTakeprofit( double& _value, int _0Ribasso_1Rialzo ) { double tickSize = NormalizeDouble( SymbolInfoDouble( Symbol(), SYMBOL_TRADE_TICK_SIZE ), Digits); _value = NormalizeDouble( _value, Digits ); if( NormalizeDouble( MathMod( NormalizeDouble(_value * MathPow(10, Digits), 0 ), NormalizeDouble(tickSize * MathPow(10, Digits), 0) ), 2) == 0.0 ) { return true; } else { for( double i = 1; i < 100000; i++ ) { _value = _0Ribasso_1Rialzo == 0 ? (_value - 1 * Point) : (_value + 1 * Point); _value = NormalizeDouble( _value, Digits ); if( NormalizeDouble( MathMod( _value, tickSize ), 2) == 0 ) { //Print( "Round Done" ); return true; } } } return false; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool chiudiPerNews = false; //Chiudi posizioni per news bool nonEntrarePerTuttoIlGiornoNews3Tori = false; //Non Entrare per tutto il giorno con news a 3 Tori bool nonEntrarePerTuttoIlGiornoNews2Tori = false; //Non Entrare per tutto il giorno con news a 2 Tori datetime timeDisattivazioneTuttoIlGiorno = 0; string commentSTR = ""; //Per news datetime lastcheck=0; string ar_symbol_[]; string ar_impact_[]; string ar_news_title_[]; string ar_time_[]; datetime diff_cur_news=0; datetime last_load_date=0; int mins_between_load=360; News listaNewsOperative[]; //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ string GetHTMLElement(string HTML,string ElementStart,string ElementEnd) { string data=NULL; // Find start and end position for element int s = StringFind(HTML, ElementStart) + StringLen(ElementStart); int e = StringFind(StringSubstr(HTML, s), ElementEnd); // Return element content if(e!=0) data=StringSubstr(HTML,s,e); return(data); } //+------------------------------------------------------------------+ //| Splitta String | //+------------------------------------------------------------------+ void splittaString( string _toSplit, string _separatore, string& _array[] ) { string to_split = _toSplit; // A string to split into substrings string sep = _separatore; // A separator as a character ushort u_sep; // The code of the separator character //--- Get the separator code u_sep = StringGetCharacter(sep,0); //--- Split the string to substrings int k = StringSplit(to_split,u_sep,_array); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool presenteSymbol( string _symbol ) { string listaValute[]; splittaString( listaStrumenti, ",", listaValute); if( ArraySize( listaValute ) > 0 ) { for( int i = 0; i < ArraySize( listaValute ); i++ ) { if( _symbol == listaValute[i] ) { return true; } } } else { return true; } return false; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool presenteCustomNews( string _news ) { string listaNews[]; splittaString( listaCustomNews, ";", listaNews); if( ArraySize( listaNews ) > 0 ) { for( int i = 0; i < ArraySize( listaNews ); i++ ) { StringToUpper( _news ); StringToUpper( listaNews[i] ); if( StringFind(_news, listaNews[i] ) >= 0 ) { return true; } } } else { return true; } return false; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Push(string &ar[],string val) { ArrayResize(ar,ArraySize(ar)+1); ar[ArraySize(ar)-1]=val; } string listanews = ""; //+------------------------------------------------------------------+ bool NewsFilterEC(string symbolToFound,bool UseHigh,int BeforeHigh,int AfterHigh, bool UseMedium,int BeforeMedium,int AfterMedium, bool UseLow,int BeforeLow,int AfterLow, string& _newsCheHannoFiltrato) { listanews = ""; bool returnValue = false; int between=ArraySize(ar_time_); datetime newstime=TimeCurrent()-diff_cur_news; for(int z=0;z=1)lefttime=datetime(ar_time_[z-1]); if(lefttime giornoSuccessivo ) { continue; } if( !presenteSymbol(ar_symbol_[z] ) ) { continue; } if( utilizzaCustomNews ) { if( !presenteCustomNews(ar_news_title_[z]) ) { continue; } } s+=TimeToString(TimeCurrent()+(datetime(ar_time_[z])-newstime),TIME_MINUTES|TIME_DATE|TIME_SECONDS)+ " " + ar_symbol_[z]+ " " + ar_impact_[z] + " "+ar_news_title_[z]+" " + "\n"; ArrayResize( listaNewsOperative, ArraySize( listaNewsOperative ) + 1 ); listaNewsOperative[ArraySize( listaNewsOperative ) - 1].valuta = ar_symbol_[z]; listaNewsOperative[ArraySize( listaNewsOperative ) - 1].nomeNews = ar_news_title_[z]; listaNewsOperative[ArraySize( listaNewsOperative ) - 1].importanza = ar_impact_[z]; listaNewsOperative[ArraySize( listaNewsOperative ) - 1].timeNews = TimeCurrent()+(datetime(ar_time_[z])-newstime); if( mostraListaNews ) { if( partenza == 20 ) { creaLabel( prefisso + "newsInfolista", "Lista News", 25, partenza += deltaY , clrLime, 8, ANCHOR_LEFT, CORNER_LEFT_UPPER ); } creaLabel( prefisso + "newsInfo" + IntegerToString(z), TimeToString(timeCurrentNews,TIME_MINUTES|TIME_DATE|TIME_SECONDS) + " " + ar_symbol_[z]+ /*" " + ar_impact_[z] +*/ " "+ar_news_title_[z], 25, partenza += deltaY , (ar_impact_[z] == "High" ? clrRed : ar_impact_[z] == "Moderate" ? clrGold : clrLimeGreen), 8, ANCHOR_LEFT, CORNER_LEFT_UPPER ); } } /* s+="----------------------------------------------------"+"\n"; s+="NEWS operative"+"\n"; s += (_newsCheHannoFiltrato == "" ? "Nessuna" : _newsCheHannoFiltrato); //Comment(""); //Comment( s );*/ return returnValue; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string ReturnResult1(string HTML,int &k, string left_side,string right_side) { k=StringFind(HTML,left_side,k); if(k==-1)return ""; int end=StringFind(HTML,right_side,k+StringLen(left_side)); string res=StringSubstr(HTML,k+StringLen(left_side), end-k-StringLen(left_side)); if(end-k-StringLen(left_side)==0)return ""; return res; } //+------------------------------------------------------------------+ //| Funzione scrivi file | //+------------------------------------------------------------------+ void scriviFile( string _contenuto) { string nomeFileMasterLocal = "Test2" + ".txt"; string stringaFile = _contenuto; FileDelete( nomeFileMasterLocal, FILE_COMMON ); _contenuto = stringaFile; int file_handle=FileOpen( nomeFileMasterLocal,FILE_READ|FILE_WRITE|FILE_TXT|FILE_ANSI|FILE_COMMON); if(file_handle!=INVALID_HANDLE) { FileWrite(file_handle,stringaFile); //--- chiude il file FileClose(file_handle); } else { Print( nomeFileMasterLocal + "Attendo rilascio risorse..." + nomeFileMasterLocal + IntegerToString(GetLastError())); } } //+--------------------------- bool LoadData(string symbolToFound,bool UseHigh,int BeforeHigh,int AfterHigh, bool UseMedium,int BeforeMedium,int AfterMedium, bool UseLow,int BeforeLow,int AfterLow) { ArrayResize(ar_symbol_,0); ArrayResize(ar_impact_,0); ArrayResize(ar_news_title_,0); ArrayResize(ar_time_,0); string cookie=NULL,headers; char post[],result[]; int res; string google_url="https://sslecal2.investing.com/"; cookie = "Referer: https://www.investing.com/economic-calendar/\r\nUser-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1\r\n"; //--- обнуляем код последней ошибки ResetLastError(); //--- загрузка html-страницы с Google Finance int timeout=5000; //--- timeout менее 1000 (1 сек.) недостаточен при низкой скорости Интернета //res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers); char data[]; res= WebRequest("GET","https://sslecal2.investing.com/","Referer: https://www.investing.com/economic-calendar/\r\nUser-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1\r\n",15000,data,result,headers); //Pr //Print ( "Headers : " + headers ); //--- проверка ошибок if(res==-1) { int error=GetLastError(); if(error!=5203)Print("Error in WebRequest. Error code =",error); if(error==4060)MessageBox("Add the address '"+google_url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION); return false; } else { /* int filehandle=FileOpen("T.htm",FILE_WRITE|FILE_BIN); //--- проверка ошибки if(filehandle!=INVALID_HANDLE) { //--- сохраняем содержимое массива result[] в файл FileWriteArray(filehandle,result,0,ArraySize(result)); //--- закрываем файл FileClose(filehandle); }*/ string HTML=CharArrayToString(result); //Comment( HTML ); scriviFile( HTML ); string r="var currentDateTime = parseDateTime('"; string l="')"; string date1=GetHTMLElement(HTML,r,l); StringReplace(date1,"-","."); datetime newstime=(datetime)date1; // Print(newstime); //first datetime //symbol //volatility //event string left_datetime="event_timestamp=\""; string right_datetime="\""; string left_symbol=""; string right_symbol=""; string left_impact=""; string right_title=""; int i=0; datetime temp=0; int date=0,time=0,symbol=0,impact=0,news_title=0; while(true) { string DateTime=ReturnResult1(HTML,date,left_datetime,right_datetime); StringReplace(DateTime,"-","."); //Print( ReturnResult1(HTML,date,left_title,right_title) ); if(datetime(DateTime)1000)break; } diff_cur_news=TimeCurrent()-newstime; return true; } } //+------------------------------------------------------------------+ //| Permesso News | //+------------------------------------------------------------------+ void permessoNews( bool& news ) { if( !UseNewsFilter ) { news = true; return; } if( MQLInfoInteger(MQL_TESTER) ) { news = false; return; } news = false; string nomeNews = ""; if(!MQLInfoInteger(MQL_TESTER) && UseNewsFilter) if(TimeCurrent() - last_load_date>=mins_between_load*60) { if(LoadData(Symbol(),UseHighImpact,MinutesBefore3Tori,MinutesAfter3Tori, UseMediumImpact,MinutesBefore2Tori,MinutesAfter2Tori, UseLowImpact,MinutesBefore1Tori,MinutesAfter1Tori)) last_load_date=TimeCurrent(); else return;//eror in function skip this tick } if(!MQLInfoInteger(MQL_TESTER) && UseNewsFilter) { news=NewsFilterEC(Symbol(),UseHighImpact,MinutesBefore3Tori,MinutesAfter3Tori, UseMediumImpact,MinutesBefore2Tori,MinutesAfter2Tori, UseLowImpact,MinutesBefore1Tori,MinutesAfter1Tori, nomeNews); } if(Time[0]>lastcheck) { lastcheck=Time[0]; } /* if( !IsTesting() ) { CreaLabel( prefisso + "filtroNews", "Entry for news Allowed : " + (!news ? "Yes" : "No"), 20, 20, clrRed, 3 ); }*/ } //+------------------------------------------------------------------+ //| Calcola Contratti | //+------------------------------------------------------------------+ double calcolaContratti( double rischioPercentualeOperazione, double pointsStoploss ) { if( tipoCalcoloSize == ELottiFissi ) { return NormalizeDouble( rischioPercentualeOperazione, 2 ); } double valorePerPoint = SymbolInfoDouble( Symbol(), SYMBOL_TRADE_TICK_VALUE ) * Point / SymbolInfoDouble( Symbol(), SYMBOL_TRADE_TICK_SIZE ); double rischio = (tipoCalcoloSize == EPercentualeEquity ? AccountInfoDouble( ACCOUNT_EQUITY ) : AccountInfoDouble( ACCOUNT_BALANCE )) * rischioPercentualeOperazione / 100; double valoreSize = NormalizeDouble( rischio / (pointsStoploss * valorePerPoint), 2); //Arrotonda in base alla prima size disponibile for( double i = SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MIN ); i <= SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MAX ); i += SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_STEP ) ) { if( NormalizeDouble( i, 2 ) >= valoreSize ) { valoreSize = NormalizeDouble( i, 2 ); break; } } if( valoreSize > SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MAX ) ) { valoreSize = NormalizeDouble( SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MAX ), 2); } Print( "Valore per point inserimento operazione : " + DoubleToString( valorePerPoint, 2 )); return valoreSize; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void piazzaPendenti( bool usaMassimoMinimo = false ) { double buyStop = usaMassimoMinimo ? High[1] : NormalizeDouble( Ask + pointsDistanzaOrdini * Point, Digits); double sellStop = usaMassimoMinimo ? Low[1] : NormalizeDouble( Bid - pointsDistanzaOrdini * Point, Digits); //arrotondaStoplossTakeprofit( buyStop, 1 ); //arrotondaStoplossTakeprofit( sellStop, 0 ); double stoplossBuy = usaMassimoMinimo ? NormalizeDouble( High[1] - puntiStoploss * Point, Digits ) : NormalizeDouble( Ask - puntiStoploss * Point, Digits ); double takeprofitBuy = usaMassimoMinimo ? NormalizeDouble( High[1] + pointsTakeprofit * Point, Digits ) : NormalizeDouble( Ask + pointsTakeprofit * Point, Digits ); //arrotondaStoplossTakeprofit( stoploss, 0 ); inviaOrdine( Magic, OP_BUYSTOP, calcolaContratti( lottiOrdine, puntiStoploss ), buyStop, "BuyAuto", clrBlue, (tipoStoploss == EFisicoSuOrdine ? stoplossBuy : 0.0), (tipoTakeprofit == EFisicoSuOrdine ? takeprofitBuy : 0.0) ); double stoplossSell = usaMassimoMinimo ? NormalizeDouble( Low[1] + puntiStoploss * Point, Digits ) : NormalizeDouble( Bid + puntiStoploss * Point, Digits ); double takeprofitSell = usaMassimoMinimo ? NormalizeDouble( Low[1] - pointsTakeprofit * Point, Digits ) : NormalizeDouble( Bid - pointsTakeprofit * Point, Digits ); //arrotondaStoplossTakeprofit( stoploss, 0 ); inviaOrdine( Magic2, OP_SELLSTOP, calcolaContratti( lottiOrdine, puntiStoploss ), sellStop, "SellAuto", clrRed, (tipoStoploss == EFisicoSuOrdine ? stoplossSell : 0.0), (tipoTakeprofit == EFisicoSuOrdine ? takeprofitSell : 0.0) ); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void statistiche() { if( !mostraStatistiche) { return; } double profittoLordo = 0.0; double perditaLorda = 0.0; double profittoNetto = 0.0; double fattoreProfitto = 0.0; int numeroOperazioniGuadagno = 0; int numeroOperazioniPerdita= 0; double maggioreGuadagno = 0; double maggiorePerdita = 0; int buy = 0; int sell = 0; int buyProfitto = 0; int sellProfitto = 0; int buyPerdita = 0; int sellPerdita = 0; double sommaProfittiBuy = 0.0; double sommaProfittiSell = 0.0; double sommaPerditaBuy = 0.0; double sommaPerditaSell = 0.0; double vincitaMediaBuy = 0.0; double vincitaMediaSell= 0.0; double perditaMediaBuy = 0.0; double perditaMediaSell = 0.0; int massimeVinciteConsecutive = 0; double valmassimeVinciteConsecutive = 0; int massimePerditeConsecutive = 0; double valmassimePerditeConsecutive = 0; int mediaVinciteConsecutive = 0; double valmediaVinciteConsecutive = 0; int mediaPerditeConsecutive = 0; double valmediaPerditeConsecutive = 0; int numeroVinciteConsecutiveTemp = 0; double valVinciteConsecutiveTemp = 0; int numeroPerditeConsecutiveTemp = 0; double valPerditeConsecutiveTemp = 0; for( int i = OrdersHistoryTotal() -1; i >= 0; i-- ) { if( OrderSelect(i, SELECT_BY_POS, MODE_HISTORY ) ) { double pl = OrderProfit() + OrderSwap() + OrderCommission(); if( pl > 0 ) { if( numeroPerditeConsecutiveTemp > massimePerditeConsecutive ) { massimePerditeConsecutive = numeroPerditeConsecutiveTemp; valmassimePerditeConsecutive = valPerditeConsecutiveTemp; } mediaPerditeConsecutive = mediaPerditeConsecutive == 0 ? numeroPerditeConsecutiveTemp : (mediaPerditeConsecutive + numeroPerditeConsecutiveTemp) / 2; valmediaPerditeConsecutive = valmediaPerditeConsecutive == 0 ? valPerditeConsecutiveTemp : (valmediaPerditeConsecutive + valPerditeConsecutiveTemp ) / 2; numeroPerditeConsecutiveTemp = 0; valPerditeConsecutiveTemp = 0.0; numeroVinciteConsecutiveTemp++; valVinciteConsecutiveTemp += pl; } if( pl < 0 ) { if( numeroVinciteConsecutiveTemp > massimeVinciteConsecutive ) { massimeVinciteConsecutive = numeroVinciteConsecutiveTemp; valmassimeVinciteConsecutive = valVinciteConsecutiveTemp; } mediaVinciteConsecutive = mediaVinciteConsecutive == 0 ? numeroVinciteConsecutiveTemp : (mediaVinciteConsecutive + numeroVinciteConsecutiveTemp) / 2; valmediaVinciteConsecutive = valmediaVinciteConsecutive == 0 ? valVinciteConsecutiveTemp : (valmediaVinciteConsecutive + valVinciteConsecutiveTemp ) / 2; numeroVinciteConsecutiveTemp = 0; valVinciteConsecutiveTemp = 0.0; numeroPerditeConsecutiveTemp++; valPerditeConsecutiveTemp += pl; } //BUY if( OrderType() == OP_BUY ) { if( pl > maggioreGuadagno ) { maggioreGuadagno = pl; } if( pl < maggiorePerdita ) { maggiorePerdita = pl; } buy++; if( pl > 0 ) { profittoLordo += pl; numeroOperazioniGuadagno++; buyProfitto++; sommaProfittiBuy += pl; } else { perditaLorda += pl; numeroOperazioniPerdita++; buyPerdita++; sommaPerditaBuy += pl; } } //SELL if( OrderType() == OP_SELL ) { if( pl > maggioreGuadagno ) { maggioreGuadagno = pl; } if( pl < maggiorePerdita ) { maggiorePerdita = pl; } sell++; if( pl > 0 ) { profittoLordo += pl; numeroOperazioniGuadagno++; sellProfitto++; sommaProfittiSell += pl; } else { perditaLorda += pl; numeroOperazioniPerdita++; sellPerdita++; sommaPerditaSell += pl; } } } } int y = 260; int deltaX = 200; creaBottone( prefisso + "bg", "", 500 + deltaX + 210, y, 500 + deltaX + 190, y - 15, C'20,20,20', clrNONE, 10, CORNER_RIGHT_LOWER ); /* creaBottone( prefisso + "bg2", "", 500 + deltaX + 205, y - 5, 400, y - 15, C'50,50,50', clrNONE, 10, CORNER_RIGHT_LOWER );*/ creaLabel( prefisso + "profitto", "Profitto", 500 + deltaX, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "profittoLordo", "Profitto lordo : € " + DoubleToString( profittoLordo, 2 ), 700 + deltaX, y -= 40, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "perditaLorda", "Perdita Lorda : € " + DoubleToString( perditaLorda, 2 ), 700 + deltaX, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "profittoNetto", "Profitto Netto: € " + DoubleToString( profittoLordo - perditaLorda, 2 ), 700 + deltaX, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "fattoreProfitto", "Fattore Profitto: " + DoubleToString( MathAbs(profittoLordo / perditaLorda), 2 ), 700 + deltaX, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "vincite", "Vincite", 550 + deltaX, y -= 30, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "perdite", "Perdite", 380 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Consecutive", "Consecutive", 700 + deltaX, y-= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totconsec", "tot", 550 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totimporto", "Importo", 500 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totconsec2", "tot", 400 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totimporto2", "Importo", 350 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Massimo", "Massimo", 700 + deltaX, y-= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totconsecmassimo", IntegerToString(massimeVinciteConsecutive), 550 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totimportomassimo", "€ " + DoubleToString( valmassimeVinciteConsecutive, 2 ), 500 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totconsecmassimoperd", IntegerToString(massimePerditeConsecutive), 400 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totimportomassimoperd", "€ " + DoubleToString( valmassimePerditeConsecutive, 2 ), 350 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Media", "Media", 700 + deltaX, y-= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totconsecmassimoMed", IntegerToString(mediaVinciteConsecutive), 550 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totimportomassimoMed", "€ " + DoubleToString( valmediaVinciteConsecutive, 2 ), 500 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totconsecmassimoperdMed", IntegerToString(mediaPerditeConsecutive), 400 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totimportomassimoperdMed", "€ " + DoubleToString( valmediaPerditeConsecutive, 2 ), 350 + deltaX, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); y = 260; creaLabel( prefisso + "gaudagno", "Guadagno", 250, y -= 30, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "perdita", "Perdita", 100, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Operazioni", "Operazioni", 400, y -= 30, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "gudagnoNumero", IntegerToString( numeroOperazioniGuadagno), 160, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "perditaNumero", IntegerToString( numeroOperazioniPerdita), 35, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Operazioni%totale", "% del totale", 400, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "percgudagnoNumero", DoubleToString( ((double)numeroOperazioniGuadagno / ((double)numeroOperazioniGuadagno + (double)numeroOperazioniPerdita)) * 100, 2 ) + "%", 160, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "percperditaNumero", DoubleToString( ((double)numeroOperazioniPerdita / ((double)numeroOperazioniGuadagno + (double)numeroOperazioniPerdita)) * 100, 2 ) + "%", 35, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Maggiore (€)", "Maggiore (€)", 400, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "MaggioreGiad", "€" +DoubleToString( maggioreGuadagno, 2 ), 160, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Maggioreperd", "€" +DoubleToString( maggiorePerdita, 2 ), 35, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "buy", "Buy", 220, y -= 30, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "sell", "Sell", 80, y, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "Totale", "Totale", 400, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); int yDeltaSell= -20; creaLabel( prefisso + "totbuy", IntegerToString( buy ), 190, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totsell", IntegerToString( sell) , 55 + yDeltaSell, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "vinteTotale", "Vinte Tot.", 400, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totbuyVint", IntegerToString( buyProfitto ), 190, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totsellVint", IntegerToString( sellProfitto) , 55 + yDeltaSell, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "perseTotale", "Perse Tot.", 400, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totbuyperse", IntegerToString( buyPerdita ), 190, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totsellperse", IntegerToString( sellPerdita) , 55 + yDeltaSell, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "vincMedia", "Vincita media", 400, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totbuyvincMedia", "€" +DoubleToString( sommaProfittiBuy / buyProfitto, 2), 190, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totsellvincMedia", "€" +DoubleToString( sommaProfittiSell / sellProfitto, 2) , 55 + yDeltaSell, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "perdMedia", "Perdita media", 400, y -= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totbuyperdMedia", "€" +DoubleToString( sommaPerditaBuy / buyPerdita, 2), 190, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); creaLabel( prefisso + "totsellperdMedia", "€" +DoubleToString( sommaPerditaSell / sellPerdita, 2) , 55 + yDeltaSell, y, clrWhite, 10, ANCHOR_RIGHT , CORNER_RIGHT_LOWER); //creaLabel( prefisso + "Consecutive", "1" + " " + "€", 700, y-= 20, clrWhite, 10, ANCHOR_LEFT , CORNER_RIGHT_LOWER); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ datetime timeLastCurrent = 0; datetime timeIngressoLocal= 0; void ingressoAutomatico() { if( tipoOperativita == EManuale ) { if( timeLastCurrent != 0 && TimeCurrent() >= timeIngressoManuale && timeLastCurrent < timeIngressoManuale ) { piazzaPendenti(); } if( TimeCurrent() < timeFineSpostamentoManuale ) { spostaPendenti(); } timeLastCurrent = TimeCurrent(); if( timeUltimoSpostamento != 0 ) { if( TimeCurrent() - timeUltimoSpostamento >= minutiRimozionePendentiNonFillati * 60 ) { chiudiMagicPendenti(Magic, "Rimozione pendenti per timeout"); chiudiMagicPendenti(Magic2, "Rimozione pendenti per timeout"); timeUltimoSpostamento = 0; } } } if( tipoOperativita == EPostNews ) { if( timeUltimoSpostamento != 0 ) { if( TimeCurrent() - timeUltimoSpostamento >= minutiRimozionePendentiNonFillati * 60 ) { chiudiMagicPendenti(Magic, "Rimozione pendenti per timeout"); chiudiMagicPendenti(Magic2, "Rimozione pendenti per timeout"); timeUltimoSpostamento = 0; } } cancellaPendentiSeMarket(); string listaNewsLocal = ""; for( int i = 0; i < ArraySize( listaNewsOperative ); i++ ) { int secondsBefore = 0; int secondsAfter = 0; bool nonEntrareTuttoIlGiorno = false; if( listaNewsOperative[i].importanza == "Low" && UseLowImpact ) { secondsBefore = MinutesBefore1Tori * 60; secondsAfter = MinutesAfter1Tori * 60; } if( listaNewsOperative[i].importanza == "Moderate" && UseMediumImpact ) { secondsBefore = MinutesBefore2Tori * 60; secondsAfter = MinutesAfter2Tori * 60; nonEntrareTuttoIlGiorno = nonEntrarePerTuttoIlGiornoNews2Tori; } if( listaNewsOperative[i].importanza == "High" && UseHighImpact ) { secondsBefore = MinutesBefore3Tori * 60; secondsAfter = MinutesAfter3Tori * 60; nonEntrareTuttoIlGiorno = nonEntrarePerTuttoIlGiornoNews3Tori; } if( utilizzaCustomNews ) { secondsBefore = MinutesBeforeCustom * 60; secondsAfter = MinutesAfterCustom * 60; nonEntrareTuttoIlGiorno = false; } //Print( ar_news_title_[z] ); string symbolToFound = Symbol(); datetime timeCurrent = TimeCurrent(); datetime timeCurrentNews = listaNewsOperative[i].timeNews; if( StringToUpper( symbolToFound ) ) { if( StringFind( symbolToFound, listaNewsOperative[i].valuta ) >= 0 ) { listaNewsLocal += TimeToString(timeCurrentNews,TIME_MINUTES|TIME_DATE|TIME_SECONDS) + " " + " " + listaNewsOperative[i].valuta+ " " + listaNewsOperative[i].importanza + " "+ listaNewsOperative[i].nomeNews+" " + "\r\n"; int barraNews = iBarShift( Symbol(), PERIOD_CURRENT, listaNewsOperative[i].timeNews, true ); /* if( MathAbs(TimeCurrent() - listaNewsOperative[i].timeNews) <= 1000 ) { Print( "News trovata : " + listaNewsOperative[i].nomeNews + " "+ barraNews); }*/ if( barraNews == 1 && timeIngressoLocal != Time[0] ) { timeIngressoLocal = Time[0]; if( !presenteOrdineMercato()) { bool permessoSpread = pointsSpreadMassimo == 0 ? true : Ask - Bid <= pointsSpreadMassimo * Point; Print( "Piazzo su news : " + listaNewsOperative[i].nomeNews ); if( permessoSpread ) { piazzaPendenti(true); timeUltimoSpostamento = TimeCurrent(); } else { Print( "Spread superiore alla soglia massima consentita ") ; } } } } } } } if( tipoOperativita == EBreakout ) { if( timeUltimoSpostamento != 0 ) { if( TimeCurrent() - timeUltimoSpostamento >= minutiRimozionePendentiNonFillati * 60 ) { chiudiMagicPendenti(Magic, "Rimozione pendenti per timeout"); chiudiMagicPendenti(Magic2, "Rimozione pendenti per timeout"); timeUltimoSpostamento = 0; } } cancellaPendentiSeMarket(); string listaNewsLocal = ""; for( int i = 0; i < ArraySize( listaNewsOperative ); i++ ) { int secondsBefore = 0; int secondsAfter = 0; bool nonEntrareTuttoIlGiorno = false; if( listaNewsOperative[i].importanza == "Low" && UseLowImpact ) { secondsBefore = MinutesBefore1Tori * 60; secondsAfter = MinutesAfter1Tori * 60; } if( listaNewsOperative[i].importanza == "Moderate" && UseMediumImpact ) { secondsBefore = MinutesBefore2Tori * 60; secondsAfter = MinutesAfter2Tori * 60; nonEntrareTuttoIlGiorno = nonEntrarePerTuttoIlGiornoNews2Tori; } if( listaNewsOperative[i].importanza == "High" && UseHighImpact ) { secondsBefore = MinutesBefore3Tori * 60; secondsAfter = MinutesAfter3Tori * 60; nonEntrareTuttoIlGiorno = nonEntrarePerTuttoIlGiornoNews3Tori; } if( utilizzaCustomNews ) { secondsBefore = MinutesBeforeCustom * 60; secondsAfter = MinutesAfterCustom * 60; nonEntrareTuttoIlGiorno = false; } //Print( ar_news_title_[z] ); string symbolToFound = Symbol(); datetime timeCurrent = TimeCurrent(); datetime timeCurrentNews = listaNewsOperative[i].timeNews; if( StringToUpper( symbolToFound ) ) { if( StringFind( symbolToFound, listaNewsOperative[i].valuta ) >= 0 ) { listaNewsLocal += TimeToString(timeCurrentNews,TIME_MINUTES|TIME_DATE|TIME_SECONDS) + " " + " " + listaNewsOperative[i].valuta+ " " + listaNewsOperative[i].importanza + " "+ listaNewsOperative[i].nomeNews+" " + "\r\n"; if( (timeCurrent - timeCurrentNews < 0 && timeCurrent - timeCurrentNews >= -secondsBefore) || (timeCurrent - timeCurrentNews > 0 && timeCurrent - timeCurrentNews < secondsAfter ) ) { //Comment( ((int)(timeCurrent - timeCurrentNews)) + " " + secondsAfter ); if( !presenteOrdineMercato()) { bool permessoSpread = pointsSpreadMassimo == 0 ? true : Ask - Bid <= pointsSpreadMassimo * Point; Print( "Piazzo su news : " + listaNewsOperative[i].nomeNews ); if( permessoSpread ) { piazzaPendenti(); } else { Print( "Spread superiore alla soglia massima consentita ") ; } } else { //Sposta pendenti spostaPendenti(); } } } } } Comment( "");//TimeCurrent() + "\r\n" + listaNewsLocal ); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ datetime timeUltimoSpostamento = 0; void spostaPendenti() { Print( "aggiorno pendenti " + TimeToString( timeUltimoSpostamento, TIME_DATE|TIME_MINUTES|TIME_SECONDS ) ); for( int i = OrdersTotal() -1; i >= 0; i-- ) { if( OrderSelect( i, SELECT_BY_POS ) && (OrderMagicNumber() == Magic || OrderMagicNumber() == Magic2 ) && OrderType() > 1 ) { timeUltimoSpostamento = TimeCurrent(); double buyStop = NormalizeDouble( Ask + pointsDistanzaOrdini * Point, Digits); double sellStop = NormalizeDouble( Bid - pointsDistanzaOrdini * Point, Digits); double stoplossBuy = NormalizeDouble( Ask - puntiStoploss * Point, Digits ); double stoplossSell = NormalizeDouble( Bid + puntiStoploss * Point, Digits ); double takeprofitBuy = NormalizeDouble( Ask + pointsTakeprofit * Point, Digits ); double takeprofitSell = NormalizeDouble( Bid - pointsTakeprofit * Point, Digits ); if( OrderType() == OP_BUYSTOP && NormalizeDouble( OrderOpenPrice(), Digits ) != buyStop) { if( !OrderModify( OrderTicket(), buyStop, (tipoStoploss == EFisicoSuOrdine ? stoplossBuy : 0.0), (tipoTakeprofit == EFisicoSuOrdine ? takeprofitBuy : 0.0), 0, clrRed )) { erroreAlertEAFunc( "Aggiornamento ordine buystop", "", GetLastError() ); } else { AlertModifcaOrdiniEAFunc( "Aggiornamento ordine buystop", "" ); } } else if( OrderType() == OP_SELLSTOP && NormalizeDouble( OrderOpenPrice(), Digits ) != sellStop) { if( !OrderModify( OrderTicket(), sellStop, (tipoStoploss == EFisicoSuOrdine ? stoplossSell : 0.0), (tipoTakeprofit == EFisicoSuOrdine ? takeprofitSell : 0.0), 0, clrRed )) { erroreAlertEAFunc( "Aggiornamento ordine sellstop", "", GetLastError() ); } else { AlertModifcaOrdiniEAFunc( "Aggiornamento ordine sellstop", "" ); } } } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void cancellaPendentiSeMarket() { bool trovatoMarket = false; for( int i = OrdersTotal() -1; i >= 0; i-- ) { if( OrderSelect( i, SELECT_BY_POS ) && (OrderMagicNumber() == Magic || OrderMagicNumber() == Magic2 ) && OrderType() <= 1 ) { trovatoMarket = true; } } if( trovatoMarket ) { chiudiMagicPendenti(Magic, "Chiusura pending per ordine market" ); chiudiMagicPendenti(Magic2, "Chiusura pending per ordine market" ); } } //+------------------------------------------------------------------+ //| Chiudi Magic | //+------------------------------------------------------------------+ void chiudiMagicPendenti( int _magic, string _causale ) { for( int i = OrdersTotal(); i >= 0; i-- ) { if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == _magic && OrderType() > 1 ) { for( int k = 0; k < 10; k++ ) { RefreshRates(); if( !OrderDelete( OrderTicket(), clrRed )) { int errore = GetLastError(); erroreAlertEAFunc( _causale, "", errore ); } else { AlertModifcaOrdiniEAFunc( _causale, "" ); break; } } } } } //+------------------------------------------------------------------+ //| Breakeven | //+------------------------------------------------------------------+ void breakeven() { if( pointsPiazzamentoBreakeven == 0 ) { return; } for( int i = OrdersTotal(); i >= 0; i-- ) { //Long if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic && OrderType() == OP_BUY ) { if( Bid - OrderOpenPrice() >= pointsPiazzamentoBreakeven * Point && OrderStopLoss() < OrderOpenPrice() ) { double valoreStoploss = NormalizeDouble( OrderOpenPrice() + pointsBreakeven * Point, Digits ); if( arrotondaStoplossTakeprofit( valoreStoploss, 0 ) ) { if( !OrderModify( OrderTicket(), OrderOpenPrice(), valoreStoploss, OrderTakeProfit(), 0, clrRed )) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento breakeven ", ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( valoreStoploss, Digits ), errore ); } else { AlertModifcaOrdiniEAFunc( "Modificato breakeven : " + OrderComment() + " al prezzo " + DoubleToStr( valoreStoploss, Digits ), ""); } } } } //Short if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic2 && OrderType() == OP_SELL ) { if( OrderOpenPrice() - Ask >= pointsPiazzamentoBreakeven * Point && ( OrderStopLoss() > OrderOpenPrice() || OrderStopLoss() == 0.0 ) ) { double valoreStoploss = NormalizeDouble( OrderOpenPrice() - pointsBreakeven * Point, Digits ); if( arrotondaStoplossTakeprofit( valoreStoploss, 1 ) ) { if( !OrderModify( OrderTicket(), OrderOpenPrice(), valoreStoploss, OrderTakeProfit(), 0, clrRed )) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento breakeven ", ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( valoreStoploss, Digits ), errore ); } else { AlertModifcaOrdiniEAFunc( "Modificato breakeven : " + OrderComment() + " al prezzo " + DoubleToStr( valoreStoploss, Digits ), ""); } } } } } } //+------------------------------------------------------------------+ //| Trailing Stop | //+------------------------------------------------------------------+ void trailingStopPunti() { if( pointsTrailingStopStart == 0.0 ) { return; } for( int i = OrdersTotal(); i >= 0; i-- ) { //Long if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic && StringFind( OrderComment(), "from" ) >= 0 ) { if( Bid - OrderOpenPrice() > pointsTrailingStopStart * Point ) { if( Bid - OrderStopLoss() > (pointsTrailingStop + pointsTrailingStep) * Point ) { double prezzoStoploss = NormalizeDouble(Bid - pointsTrailingStop * Point, Digits); if( arrotondaStoplossTakeprofit( prezzoStoploss, 0 ) ) { if( !OrderModify( OrderTicket(), OrderOpenPrice(), prezzoStoploss, OrderTakeProfit(), 0, clrRed )) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento Trailing Stop buy", ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( prezzoStoploss, Digits ), errore ); } else AlertModifcaOrdiniEAFunc( "Modificato Trailing Stop ordine buy : " + OrderComment() + " al prezzo " + DoubleToStr( prezzoStoploss, Digits ), ""); } } } } //Short if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic2 && StringFind( OrderComment(), "from" ) >= 0 ) { if( OrderOpenPrice() - Ask > pointsTrailingStopStart * Point ) { if( OrderStopLoss() - Ask > (pointsTrailingStop + pointsTrailingStep) * Point || OrderStopLoss() == 0.0 ) { double prezzoStoploss = NormalizeDouble(Ask + pointsTrailingStop * Point, Digits); if( arrotondaStoplossTakeprofit( prezzoStoploss, 1 ) ) { if( !OrderModify( OrderTicket(), OrderOpenPrice(), prezzoStoploss, OrderTakeProfit(), 0, clrRed )) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento Trailing Stop sell", ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( prezzoStoploss, Digits ), errore ); } else AlertModifcaOrdiniEAFunc( "Modificato Trailing Stop ordine sell : " + OrderComment() + " al prezzo " + DoubleToStr( prezzoStoploss, Digits ), ""); } } } } } } //+------------------------------------------------------------------+ //| Trailing Stop | //+------------------------------------------------------------------+ void trailingStopMaxMin() { for( int i = OrdersTotal(); i >= 0; i-- ) { //Long if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic && StringFind( OrderComment(), "from" ) >= 0 ) { double valStopLocal = NormalizeDouble( Low[1] - pointsAggiuntiviPerTrailing * Point, Digits ); arrotondaStoplossTakeprofit( valStopLocal, 0 ); if( OrderStopLoss() < valStopLocal ) { if( !OrderModify( OrderTicket(), OrderOpenPrice(), valStopLocal, OrderTakeProfit(), 0, clrRed )) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento Trailing Stop buy", ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( valStopLocal, Digits ), errore ); } else AlertModifcaOrdiniEAFunc( "Modificato Trailing Stop ordine buy : " + OrderComment() + " al prezzo " + DoubleToStr( valStopLocal, Digits ), ""); } } //Short if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic2 && StringFind( OrderComment(), "from" ) >= 0 ) { double valStopLocal = NormalizeDouble( High[1] + pointsAggiuntiviPerTrailing * Point, Digits ); arrotondaStoplossTakeprofit( valStopLocal, 1 ); if( OrderStopLoss() > valStopLocal ) { if( !OrderModify( OrderTicket(), OrderOpenPrice(), valStopLocal, OrderTakeProfit(), 0, clrRed )) { int errore = GetLastError(); erroreAlertEAFunc( "inserimento Trailing Stop sell", ", commento ordine " + OrderComment() + " al prezzo " + DoubleToStr( valStopLocal, Digits ), errore ); } else AlertModifcaOrdiniEAFunc( "Modificato Trailing Stop ordine sell : " + OrderComment() + " al prezzo " + DoubleToStr( valStopLocal, Digits ), ""); } } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void takeprofit() { if( pointsTakeprofit == 0 ) { return; } if( tipoTakeprofit == EFisicoSuOrdine ) { return; } for( int i = OrdersTotal(); i >= 0; i-- ) { //Long if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic && StringFind( OrderComment(), "from" ) < 0 && OrderType() <= 1 ) { if( Bid - OrderOpenPrice() >= pointsTakeprofit * Point ) { double sizeDaChiudere = NormalizeDouble( OrderLots() * percentualeChiusuraAlTakeprofit / 100, 2 ); //Arrotonda in base alla prima size disponibile for( double k = SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MIN ); k <= SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MAX ); k += SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_STEP ) ) { if( NormalizeDouble( k, 2 ) >= sizeDaChiudere ) { sizeDaChiudere = NormalizeDouble( k, 2 ); break; } } if( !OrderClose( OrderTicket(), sizeDaChiudere, OrderClosePrice(), 20, clrRed )) { erroreAlertEAFunc( "Chiusura al TP", "", GetLastError() ); } else { AlertModifcaOrdiniEAFunc( "Chiusura al TP", "" ); } } } //Short if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == Magic2 && StringFind( OrderComment(), "from" ) < 0 && OrderType() <= 1 ) { if( OrderOpenPrice() - Ask >= pointsTakeprofit * Point ) { double sizeDaChiudere = NormalizeDouble( OrderLots() * percentualeChiusuraAlTakeprofit / 100, 2 ); //Arrotonda in base alla prima size disponibile for( double k = SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MIN ); k <= SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_MAX ); k += SymbolInfoDouble( Symbol(), SYMBOL_VOLUME_STEP ) ) { if( NormalizeDouble( k, 2 ) >= sizeDaChiudere ) { sizeDaChiudere = NormalizeDouble( k, 2 ); break; } } if( !OrderClose( OrderTicket(), sizeDaChiudere, OrderClosePrice(), 20, clrRed )) { erroreAlertEAFunc( "Chiusura al TP", "", GetLastError() ); } else { AlertModifcaOrdiniEAFunc( "Chiusura al TP", "" ); } } } } } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ datetime timeControlloLicenza = 0; bool permessoLicenza = true; void OnTick() { if( IsTradeAllowed() || IsTesting() ) {} else { return; } if( TimeToString( timeControlloLicenza, TIME_DATE) != TimeToString( Time[0], TIME_DATE) ) { timeControlloLicenza = Time[0]; if( !gestioneLicenze() ) { Alert( "Attenzione, non si è in possesso della licenza per utilizzare questo strumento" ); permessoLicenza = false; return; } } if( !permessoLicenza) { return; } statistiche(); //Controllo permesso News bool newsLocal = false; if( !MQLInfoInteger(MQL_TESTER) && UseNewsFilter ) { permessoNews( newsLocal ); if( TimeCurrent() < timeDisattivazioneTuttoIlGiorno ) { newsLocal = true; } } ingressoAutomatico(); breakeven(); takeprofit(); if( tipoTrailingStop == ETrailingInPunti ) { trailingStopPunti(); } if( tipoTrailingStop == ETrailingMaxMinCandela ) { trailingStopMaxMin(); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnChartEvent(const int id, // Event ID const long& lparam, // Parameter of type long event const double& dparam, // Parameter of type double event const string& sparam // Parameter of type string events ) { //+------------------------------------------------------------------+ //| Apertura Ordini | //+------------------------------------------------------------------+ if( sparam == prefisso + "inserisciOrdine" ) // Close button has been pressed { piazzaPendenti(); ObjectSetInteger(0, sparam,OBJPROP_STATE,false); } } //+------------------------------------------------------------------+