//+------------------------------------------------------------------+ //| SP 500 EA.mq4| //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern double Lots=0.1; int MagicNumber1=10500; int LastBars=0; double kline[3], dline[3]; extern int TrailingStopEntrance; extern int TrailingStop; extern int FastEMA=8; extern int SlowEMA=21; extern int TakeProfit=36; extern int StochLevel=20; extern int TotalOrders=1; extern int SLBars=100; extern int KPeriod=5; extern int DPeriod=3; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ int start() { // ONLY ONE TRADE PER TICK RefreshRates(); if(LastBars!=Bars) LastBars=Bars; else return(0); RefreshRates(); //BUY CONDITIONS bool TrendUp=false; //STOP LOSS int ShiftValue=iLowest(NULL,0,MODE_CLOSE,SLBars,0); double SLB=iLow(NULL,0,ShiftValue); double SL_BUY=NormalizeDouble(SLB,Digits); //TAKE PROFIT double TPB=(Ask+TakeProfit*100*Point); double TP_BUY=NormalizeDouble(TPB,Digits); //VARIABLES double EMA8=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,0); double EMA21=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,0); RefreshRates(); //TRAILING STOP for(int b=OrdersTotal()-1; b>=0; b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderType()==OP_BUY) { if(OrderOpenPrice()+(TrailingStopEntrance*100*_Point)< Bid && OrderStopLoss() < Bid - TrailingStop *100 * Point) OrderModify(OrderTicket(),OrderOpenPrice(), Bid-(TrailingStop*100*_Point),OrderTakeProfit(),0,clrAliceBlue); } } //BUY ORDER if(EMA8<EMA21) {TrendUp=true;} if(TrendUp==true) { for(int i = 0; i < 3; i++) { kline[i] = iStochastic(NULL, Period(),KPeriod,DPeriod,DPeriod, MODE_SMA, 0, MODE_MAIN, i); dline[i] = iStochastic(NULL, Period(), KPeriod,DPeriod,DPeriod, MODE_SMA, 0, MODE_SIGNAL, i); } if(OrdersTotal()<TotalOrders) if(kline[1] < StochLevel && kline[0] > StochLevel) { int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,SL_BUY,TP_BUY,NULL,MagicNumber1,0,clrGreen); if(openbuy>0) { if(OrderSelect(openbuy,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); } } { int i, iOrders = OrdersHistoryTotal() - 1; double OverallProfit= NormalizeDouble(0,2) ; int TotalOfTrades=0; double MonthlyProfit=0; double WinningPosition=0; double MaxDrawdown=0; double MaxProfit=0; for(i = iOrders; i >= 0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_HISTORY); if(Symbol() == OrderSymbol()) if(OrderMagicNumber()== MagicNumber1) { OverallProfit += OrderProfit()+OrderSwap()+OrderCommission(); TotalOfTrades=TotalOfTrades+1; if(TimeMonth(OrderCloseTime())==Month()) {MonthlyProfit += OrderProfit()+OrderSwap()+OrderCommission();} } if(OverallProfit>MaxProfit) {MaxProfit=OverallProfit;} double Drawdown=OverallProfit-MaxProfit; if(Drawdown<MaxDrawdown) {MaxDrawdown=Drawdown;} color Color0=White; if(OverallProfit>0) {Color0=Green;} else{Color0=Red;} color Color1=White; if(MonthlyProfit>0) {Color1=Green;} else{Color1=Red;} ObjectCreate("Rectangle",OBJ_RECTANGLE_LABEL,0,0,0); //--- set border type ObjectSet("Rectangle",OBJPROP_BORDER_TYPE,BORDER_RAISED); //--- set background color ObjectSet("Rectangle",OBJPROP_BGCOLOR,DarkBlue); //--- set label coordinates ObjectSet("Rectangle",OBJPROP_CORNER,0); ObjectSet("Rectangle",OBJPROP_XDISTANCE,5); ObjectSet("Rectangle",OBJPROP_YDISTANCE,20); //--- set label size ObjectSet("Rectangle",OBJPROP_CORNER,0); ObjectSet("Rectangle",OBJPROP_XSIZE,130); ObjectSet("Rectangle",OBJPROP_YSIZE,84); ObjectCreate("MaxDrawDown",OBJ_LABEL,0,0,0); ObjectCreate("MonthlyProfit",OBJ_LABEL,0,0,0); ObjectCreate("NumberOfTrades",OBJ_LABEL,0,0,0); ObjectCreate("OverallProfit",OBJ_LABEL,0,0,0); ObjectSetText("OverallProfit","OverallProfit="+DoubleToStr(OverallProfit,2),10,"Arial",Color0); ObjectSetText("MonthlyProfit","MonthlyProfit="+DoubleToStr(MonthlyProfit,2),10,"Arial",Color1); ObjectSetText("NumberOfTrades","NumberOfTrades="+DoubleToStr(TotalOfTrades,0),10,"Arial",White); ObjectSetText("MaxDrawDown","MaxDrawDown="+DoubleToStr(MaxDrawdown,2),10,"Arial",White); ObjectSet("OverallProfit",OBJPROP_CORNER,0); ObjectSet("OverallProfit",OBJPROP_XDISTANCE,10); ObjectSet("OverallProfit",OBJPROP_YDISTANCE,23); ObjectSet("MonthlyProfit",OBJPROP_CORNER,0); ObjectSet("MonthlyProfit",OBJPROP_XDISTANCE,10); ObjectSet("MonthlyProfit",OBJPROP_YDISTANCE,38); ObjectSet("NumberOfTrades",OBJPROP_CORNER,0); ObjectSet("NumberOfTrades",OBJPROP_XDISTANCE,10); ObjectSet("NumberOfTrades",OBJPROP_YDISTANCE,53); ObjectSet("MaxDrawDown",OBJPROP_CORNER,0); ObjectSet("MaxDrawDown",OBJPROP_XDISTANCE,10); ObjectSet("MaxDrawDown",OBJPROP_YDISTANCE,68); } } return(0);} //+------------------------------------------------------------------+
Same problem

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I would like some help please, like the title says my EA work perfectly fine on backtest but not on real account. I don't receive any error message from the terminal, except from "2021.02.19 17:55:27.350 SP 500 TR STOP TEST 2 [SP500],M5: zero divide in 'SP 500 TR STOP TEST 2.mq4' (145,52)". Which I believe wouldn't really stop the EA to work.
My AutoTrading is activated, the little smiley is there as well.
My EA worked on real account earlier this week, the only thing I added is all the codes to deal with Objectcreate and ObjectSet, I used to just used Comment() but I don't think that is the problem unless, I've read on an other post that all these ObjectSet and ObjectCreate use your CPU which I have no clue what is it... Sorry I may not be really Helpful I'm just trying to find a solution...
Pardon my English as well.
Thanks for your help.