the fastest possible during run-time: (as if there is no expert)
Inserted Code
ENUM_TIMEFRAMES TrendFrame = PERIOD_H4; ENUM_TIMEFRAMES TradingFrame; ENUM_APPLIED_PRICE applied_price = PRICE_CLOSE; ENUM_MA_METHOD ma_method = MODE_EMA; datetime time0=-1; datetime timeSuppresor=-1; int fast_ma_period=5; int slow_ma_period=7; int max_orders=1; int orderMagic=8164; string myComment="abo-amal"; double lots=0.01; int OnInit() { EventSetTimer(2); TradingFrame=ENUM_TIMEFRAMES(Period()); if(fast_ma_period>slow_ma_period) { int swap=fast_ma_period; fast_ma_period=slow_ma_period; slow_ma_period=swap; } return(INIT_SUCCEEDED); } int N=10; //extern int Nb; //not extern/buy candles counter int Ns; //not extern/sell ... .... void OnTimer() { if(TrendFrame>TradingFrame) { if(timeSuppresor!=Time[0]) { timeSuppresor=Time[0]; if(time0!=iTime(NULL,TrendFrame,0)) { int Bs=orders_total("B"); int Ss=orders_total("S"); Nb++; Ns++; if(Bs==0) { double H1=iHigh(NULL,TrendFrame,1); double H2=iHigh(NULL,TrendFrame,2); double H3=iHigh(NULL,TrendFrame,3); Nb=0; } if(Ss==0) { double L1=iLow(NULL,TrendFrame,1); double L2=iLow(NULL,TrendFrame,2); double L3=iLow(NULL,TrendFrame,3); Ns=0; } time0=iTime(NULL,TrendFrame,0); } if(Time[1]>time0) { if(H1>H2 && H2>H3) { if(Nb<=N) { int BUYS=orders_total("B"); if(BUYS<max_orders) { double ma5_1=iMA(NULL, TradingFrame ,fast_ma_period,0, ma_method , applied_price ,1); double ma5_2=iMA(NULL, TradingFrame ,fast_ma_period,0, ma_method , applied_price ,2); double ma7_1=iMA(NULL, TradingFrame ,slow_ma_period,0, ma_method , applied_price ,1); double ma7_2=iMA(NULL, TradingFrame ,slow_ma_period,0, ma_method , applied_price ,2); if(ma5_1<=ma7_1 && ma5_2>=ma7_2) { entry_process("B",H1); } } } } else if(L1<L2 && L2<L3) { if(Ns<=N) { int SELLS=orders_total("S"); if(SELLS<max_orders) { ma5_1=iMA(NULL, TradingFrame ,fast_ma_period,0, ma_method , applied_price ,1); ma5_2=iMA(NULL, TradingFrame ,fast_ma_period,0, ma_method , applied_price ,2); ma7_1=iMA(NULL, TradingFrame ,slow_ma_period,0, ma_method , applied_price ,1); ma7_2=iMA(NULL, TradingFrame ,slow_ma_period,0, ma_method , applied_price ,2); if(ma5_2<=ma7_2 && ma5_1>=ma7_1) { entry_process("S",L1); } } } } } } } } int orders_total(string signature) { int orders=0; for(int j=OrdersTotal()-1; j>=0; j--) { if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)) { if(OrderComment()==myComment) { if(OrderSymbol()==Symbol()) { if(OrderMagicNumber()==orderMagic) { if(signature=="B") { if(OrderType()==OP_BUY) { orders++; } } else if(signature=="S") { if(OrderType()==OP_SELL) { orders++; } } } } } } } return orders; } void entry_process(string signature,double TP_PRICE) { if(signature=="B") { int ticketB=OrderSend(Symbol(),OP_BUY ,lots,Ask,3, 0,0, myComment, orderMagic,0,clrLime); if(ticketB<0) { Print("OrderSend failed with error #",GetLastError()); } else { if(OrderSelect(ticketB, SELECT_BY_TICKET)==true) { double SL_PRICEB=double(DoubleToString(OrderOpenPrice()-0.5*(TP_PRICE-OrderOpenPrice()),_Digits)); bool ordModifyB=OrderModify(OrderTicket(),OrderOpenPrice(),SL_PRICEB,TP_PRICE,0,clrBlue); } } } else if(signature=="S") { int ticketS=OrderSend(Symbol(),OP_SELL ,lots,Bid,3, 0,0, myComment, orderMagic,0,clrRed); if(ticketS<0) { Print("OrderSend failed with error #",GetLastError()); } else { if(OrderSelect(ticketS, SELECT_BY_TICKET)==true) { double SL_PRICES=double(DoubleToString(OrderOpenPrice()+0.5*(OrderOpenPrice()-TP_PRICE),_Digits)); bool ordModifyS=OrderModify(OrderTicket(),OrderOpenPrice(),SL_PRICES,TP_PRICE,0,clrBlue); } } } }
Be yourself