//+------------------------------------------------------------------+ //| high_frequency.mq5 | //+------------------------------------------------------------------+ #define propVersion "1.55" #define propDescription "high_frequency" #property copyright "Copyright 2024 Enry, Gian & Luca" #property description propDescription #property version propVersion #include CTrade trade; string Notifica_4H=propDescription; string gvp; string Commom_gvp; //variabili medie mobili e variabili x tutti i trend double MediaHull []; int MHull; double MediaHull_2 []; int MHull_2; int input Periodo_Hull = 2; int input Deviazione_Hull = 2; int input Periodo_Hull_2 = 50; int input Deviazione_Hull_2 = 2; double Open_Alto; double Close, High, myPrice_4H, myLOW, ASK, BID, Spread; double PrezzoMedioCarico; bool Result = false; string Mercato=""; bool Buy_2_L=false; //variabili per condizioni BUY //ulong input Magic=27042021; ulong MagicN; int input N_Barre=9; int Segnale=0; //NOT BUY int input SpreadValue=100; bool Conto_Hedging = false; double SL; //variabili entrata a mercato int NumberOfDeals=0; double input PrimaEntrata=0.25; //double input TP=400;//Takeprofit int input TP_2_L=50; //Breackeven Buy 2 Lotti int input SL_2_L=80; //StopLoss Buy 2 Lotti int input TralingStop=10; int input Punti_Buy_2_Lotti=50; //Punti X Buy 2 Lotti ulong Ticket; double open=-1; double pipDivisor =_Point; double LottiinPancia=NormalizeDouble(0.0,_Digits); int P_StopProfit_CT_4H=0; input bool UsingTradingHour = true; //Filtro Time //input int UsingTimeStop = 60; //Minuti Time Stop double StartHour = 1; //Start Hour double EndHour = 23; //End Hour // Invio Mail e Notifiche input bool Send_Email = true; input bool Audible_Alerts = true; input bool Push_Notifications = true; bool debug = true; bool debug_filtri = true; bool debugPosTOT=false;//true; // Variabili NewBar datetime lastbar,prevBar; datetime dataDv,dataCandela; bool resettaVarGlobali = true; unsigned long TKTinvioMail=9999999; //int NumeroMaxEntrate = 6; bool AlertPerSpread = true; bool debugSMAcross=true; int Rates_3Barre=5000; double volume_inpancia; bool debug_CK_posizione = true; bool Posizione_EA_Aperta=false; bool debug_Uscita_Step = true; string TipoConto=""; bool CloseEA=false; //+------------------------------------------------------------------+ //| Funzione di INIZIALIZZAZIONE | //+------------------------------------------------------------------+ int OnInit(){ if(debug) Print("\n\n-------------------------------------------------------------\nNew Run"); if(debug) Print("\nVersione: " + propVersion); // Direzione dell'indicizzazione (Index) //spostato da OIntick a OnInit ArraySetAsSeries (MediaHull, true); ArraySetAsSeries (MediaHull_2, true); Print("PeriodSeconds=",PeriodSeconds(PERIOD_CURRENT)); if(debug && Conto_Hedging ==true ) Print(//"Init Posizioni=",NumberOfPosition, " deal=", NumberOfDeals," Lotti aperti=", LottiinPancia); if(debug && Conto_Hedging ==false )Print(//"Init Posizioni=",NumberOfPosition, " Lotti aperti=", LottiinPancia); if(debug) Print("Conversione del simbolo in ASCII"); char simbolo[6]; char simbolo_EA[10]; StringToCharArray(_Symbol,simbolo,0,-1,0); StringToCharArray(Notifica_4H,simbolo_EA,0,-1,0); int count1=0; int primoPezzo=0,secondoPezzo=0; int count2=0; int terzoPezzo=0,quartoPezzo=0; for (int pos=0 ; pos= 0; h--) { ulong ticket = 0; if((ticket = PositionGetTicket(h)) != 0 && StringCompare(PositionGetSymbol(h),Symbol(),false)==0 && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && PositionGetInteger(POSITION_MAGIC) ==MagicN) { GetPositionOpenPrice(); GetAllTradingValues(); if(LottiinPancia==0) { Buy_2_L=false;fGVS("_Buy_2_L",Buy_2_L);}// se lotti 0 setto Buy 2 Lotti a false BID= NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_BID),_Digits); double Valore_Ingresso_buy_2_Lotti = open-Punti_Buy_2_Lotti * _Point; if(LottiinPancia>0 && open>0) { if (Buy_2_L){ gestioneTakeprofit(); } if (!Buy_2_L){ Manfrina_Uscite_a_Step(); } //if(myLow StartHour && TimeNow.hour < EndHour ) CheckHour = true; if ( StartHour > EndHour ) if ( TimeNow.hour > StartHour || TimeNow.hour < EndHour ) CheckHour = true; if ( StartHour == EndHour ) if ( TimeNow.hour == StartHour ) CheckHour = true; // Check All if ( UsingTradingHour && CheckHour ) Result_Time_CK = true; // if ( UsingTradingHour && CheckDay && CheckHour ) Result = true; if ( !UsingTradingHour ) Result_Time_CK = true; //if ( !UsingTradingHour && CheckDay ) Result = true; return(Result_Time_CK); } //+------------------------------------------------------------------+ //| FUNZION_BUY_2LOTTI | //+------------------------------------------------------------------+ void FUNZION_BUY_2_LOTTI (){ ASK= NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_ASK),_Digits); for(int h = PositionsTotal() -1; h >= 0; h--) { ulong ticket = 0; if((ticket = PositionGetTicket(h)) != 0 && StringCompare(PositionGetSymbol(h),Symbol(),false)==0 && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && PositionGetInteger(POSITION_MAGIC) ==MagicN) { volume_inpancia = PositionGetDouble( POSITION_VOLUME) ; if (debug_CK_posizione) {Print("Volume in pancia x MagicN: " + IntegerToString(MagicN) + " --- " + DoubleToString(volume_inpancia) + " --- " + Notifica_4H);} trade.SetExpertMagicNumber(MagicN); if(!trade.Buy(volume_inpancia*2,NULL,ASK,0,0, Notifica_4H)) PrintError("Entrata " + Notifica_4H); else{ Ticket= trade.ResultOrder(); // Memorizzo numero del Ticket open = trade.ResultPrice(); // Memorizzo Prezzo di apertura Buy_2_L=true; GetAllTradingValues(); fGVS("_Buy_2_L",Buy_2_L); myAlert ("BUY 2 LOTTI --- Lotti=" + DoubleToString(LottiinPancia)); } trade.SetExpertMagicNumber(MagicN); int n=0; int NumeroPosizioni=PositionsTotal(); for(int h=0; h0) { if(!trade.PositionModify(TK,NormalizeDouble((PrezzoMedioCarico-SL_2_L*_Point),_Digits),NormalizeDouble((PrezzoMedioCarico + TP_2_L*_Point),_Digits))) { PrintError("Modifica BreakEven per 2° Entrata"); } else { myAlert("impostato take profit a BreakEven per 2° Entrata"); } } else { } } } } GetPositionOpenPrice(); } } //+------------------------------------------------------------------+ //| Manfrina_Uscite_a_Stepp | //+------------------------------------------------------------------+ void Manfrina_Uscite_a_Step() { ASK= NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_ASK),_Digits); BID= NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_BID),_Digits); Spread=NormalizeDouble(ASK-BID,_Digits); GetAllTradingValues(); GetPositionOpenPrice(); for(int h = PositionsTotal() -1; h >= 0; h--) { ulong ticket = 0; if(Spread <= (SpreadValue*_Point) ) { if((ticket = PositionGetTicket(h)) != 0 && StringCompare(PositionGetSymbol(h),Symbol(),false)==0 && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && PositionGetInteger(POSITION_MAGIC) ==MagicN) { if(LottiinPancia>0) { //Print("Manfrina_Uscite_a_Step" + P_StopProfit_CT_4H); if(BID >= NormalizeDouble((open + (TralingStop*_Point)),_Digits) && P_StopProfit_CT_4H==1 ){ ChiusuraPosizioniMultiple_A(); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H);} if(BID >= NormalizeDouble((open + ((TralingStop*2)*_Point)),_Digits) && P_StopProfit_CT_4H==2 ){ ChiusuraPosizioniMultiple_A(); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H);} if(BID >= NormalizeDouble((open + ((TralingStop*3)*_Point)),_Digits) && P_StopProfit_CT_4H==3 ){ ChiusuraPosizioniMultiple_A(); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H);} if(BID >= NormalizeDouble((open + ((TralingStop*4)*_Point)),_Digits) && P_StopProfit_CT_4H==4 ){ ChiusuraPosizioniMultiple_B(1); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H);} if(BID >= NormalizeDouble((open + ((TralingStop*5)*_Point)),_Digits) && P_StopProfit_CT_4H==5 ){ ChiusuraPosizioniMultiple_B(1); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H);} if(BID >= NormalizeDouble((open + ((TralingStop*6)*_Point)),_Digits) && P_StopProfit_CT_4H==6 ){ ChiusuraPosizioniMultiple_B(2); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H);} if(BID >= NormalizeDouble((open + ((TralingStop*7)*_Point)),_Digits) && P_StopProfit_CT_4H==7 ){ ChiusuraPosizioniMultiple_B(3); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H);} if(BID >= NormalizeDouble((open + ((TralingStop*8)*_Point)),_Digits) && P_StopProfit_CT_4H==8 ){ ChiusuraPosizioniMultiple_A(); P_StopProfit_CT_4H++; if(debug_Uscita_Step) {Print("P_StopProfit_CT_4H >>> " + IntegerToString(P_StopProfit_CT_4H));} fGVS("_P_StopProfit_CT_4H",P_StopProfit_CT_4H); } } } } } } //+------------------------------------------------------------------+ //| Funzione per StopProfit Protettivo | //+------------------------------------------------------------------+ void ModificaStopProfitProtettivo(int ValoreTraling) { int NumeroPosizioni=PositionsTotal(); for(int h=0; h>> " + DoubleToString(open + TralingStop*_Point));} else { myAlert("impostato StopProfit Protettivo >>> " + DoubleToString(open + TralingStop*_Point)); } } } } //+------------------------------------------------------------------+ //| Funzione per Chiusura Posizioni Multiple | //+------------------------------------------------------------------+ void ChiusuraPosizioniMultiple_A() { int NumeroPosizioni=PositionsTotal(); for(int h=0; h= 0; i-- ) { ulong ticket = 0; if((ticket = PositionGetTicket(i)) != 0 && PositionGetInteger(POSITION_MAGIC) == MagicN ) { pmc += PositionGetDouble(POSITION_PRICE_OPEN) * PositionGetDouble(POSITION_VOLUME ); sommaSize += PositionGetDouble( POSITION_VOLUME) ; } } if( sommaSize != 0 ) { pmc /= sommaSize; pmc = NormalizeDouble( pmc, _Digits ); double valoreTakeprofit = pmc + TP_2_L * _Point; valoreTakeprofit = NormalizeDouble( valoreTakeprofit, _Digits ); for( int i = PositionsTotal() -1; i >= 0; i-- ) { ulong ticket = 0; if((ticket = PositionGetTicket(i)) != 0 && PositionGetInteger(POSITION_MAGIC) == MagicN) { if( NormalizeDouble( PositionGetDouble( POSITION_TP), _Digits ) != valoreTakeprofit ) { //Print( "Aggiorno takeprofit : " + DoubleToString( valoreTakeprofit, _Digits ) ); impostaStoplossTakeprofit( PositionGetDouble( POSITION_SL ), valoreTakeprofit, ticket, MagicN, PositionGetString(POSITION_COMMENT) ); } } } } } //+------------------------------------------------------------------+ //| Visualizza_comment | //+------------------------------------------------------------------+ void Visualizza_comment() { Comment("\n" + Notifica_4H + "\nMagicN: " + IntegerToString(MagicN) + "\nTipo di Conto: " + TipoConto + "\nVersione: " + propVersion + "\nControllo Spread: " + IntegerToString(SpreadValue) + "\nHull 1: " + IntegerToString(Periodo_Hull) + "\nHull 2: " + IntegerToString(Periodo_Hull_2) + "\nOpen: " + DoubleToString(open) + " >>> " + IntegerToString(P_StopProfit_CT_4H)+ "\nLotti: " + DoubleToString(PrimaEntrata,2)); } //+------------------------------------------------------------------+ //| Elimina EA dal grafico | //+------------------------------------------------------------------+ void CK_Chiusura_EA() { GetAllTradingValues(); if(PositionGetInteger(POSITION_MAGIC) ==MagicN && LottiinPancia==0) { Print("EA Tolto x chiusura totale posizini..."); ExpertRemove(); } }