Expert disparity problem.Backtest orders normal but live account diffrent.

 

Expert disparity problem.Backtest orders normal but live account diffrent.


Hello

Expert using MA for open trades.I check the Backtest it's open only 5 position and not close anything.But live account open position and close after 5 min then open another position.This orders not seen in the backtest.Of course live account may diffrent to backtest but this is not something like.Seems the diffrent bug.What's wrong this ea ?

Account :Tickmill Demo

Leverage: 1/500

Deposit : 50 usd



Files:
 
MerTurk:

Expert disparity problem.Backtest orders normal but live account diffrent.


Hello

Expert using MA for open trades.I check the Backtest it's open only 5 position and not close anything.But live account open position and close after 5 min then open another position.This orders not seen in the backtest.Of course live account may diffrent backtest but this is not something like.Seems the diffrent bug.What's wrong this ea ?

Account :Tickmill Demo

Leverage: 1/500

Deposit : 50 usd



I am on mobile niw
But do u know about modelling quality
 
Mohammad Soubra:
I am on mobile niw
But do u know about modelling quality

Model : Every tick

quality: %90

 
Share the code. Otherwise you will not find the Bug. 
 
Rinor Memeti:
Share the code. Otherwise you will not find the Bug. 

You can see the attach mql file at the first message.But I share as code right now.




/*-----------------------------+
|                              |
| Shared by www.Aptrafx.com    |
|                              |
+------------------------------*/

#property copyright "pengie, Braindancer"
#property link      "http://www.forex-tsd.com"

extern string EAName = "TrendStrengthEMA";
extern int magic = 2703;

extern int SL = 0;
extern int TP = 0;

extern int slippage = 3;
extern double lots = 0.1;

datetime prevTime, curTime;
int ticket;

int init()
{
   prevTime = Time[0];
   magic = GenerateMagicNumber(magic, Symbol(), Period());
        EAName = GenerateComment(EAName, magic, Period());
        
        int maxOrders = OrdersTotal();
        int t_index;
        for (t_index=0; t_index<maxOrders; t_index++)
        {
                OrderSelect(t_index, SELECT_BY_POS, MODE_TRADES);
                if (magic==OrderMagicNumber())
                {                       
                        ticket = OrderTicket();
                        break;
                }       
        }       
   return (0);
}

int deinit()
{
   return (0);
}

int start()
{
   curTime = Time[0];
   
   if (prevTime != curTime)
   {
      prevTime = curTime;
      
      double tmp = iMA(NULL,0,11,0,MODE_EMA,PRICE_CLOSE,2);     
      double ma1 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2); 
      double ma2 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2); 
      double ma3 = tmp-iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,2); 
      double ma4 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2);  
      double ma5 = tmp-iMA(NULL,0,6,0,MODE_EMA,PRICE_CLOSE,2);
      double ma6 = tmp-iMA(NULL,0,4,0,MODE_EMA,PRICE_CLOSE,2);
      double ma7 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2);
     
      double prevTS = (ma1+ma2+ma3+ma4+ma5+ma6+ma7)/7; 
      
      tmp = iMA(NULL,0,11,0,MODE_EMA,PRICE_CLOSE,1);     
      ma1 = tmp-iMA(NULL,0,40,0,MODE_EMA,PRICE_CLOSE,1); 
      ma2 = tmp-iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1); 
      ma3 = tmp-iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,3); 
      ma4 = tmp-iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,1);  
      ma5 = tmp-iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,5);
      ma6 = tmp-iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1);
      ma7 = tmp-iMA(NULL,0,16,0,MODE_EMA,PRICE_CLOSE,2);
      
      double curTS = (ma1+ma2+ma3+ma4+ma5+ma6+ma7)/7;
      double stoploss, takeprofit;
      if (prevTS<0 && curTS>0)
      {
         OrderClose(ticket, lots, Ask, slippage, CLR_NONE);
         stoploss = 0;
         if (SL != 0) stoploss = Ask-SL*Point;
         takeprofit = 0;
         if (TP != 0) takeprofit = Ask+TP*Point;
         ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, stoploss, takeprofit, EAName, magic, 0, CLR_NONE);         
      }
      else if (prevTS>0 && curTS<0)
      {
         OrderClose(ticket, lots, Bid, slippage, CLR_NONE);
         stoploss = 0;
         if (SL != 0) stoploss = Bid+SL*Point;
         takeprofit = 0;
         if (TP != 0) takeprofit = Bid-TP*Point;
         ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, stoploss, takeprofit, EAName, magic, 0, CLR_NONE);         
      }
   }
   return (0);
}

int GenerateMagicNumber(int seed, string symbol, int timeFrame)
{
   int isymbol = 0;
   if (symbol == "EURUSD") isymbol = 1;
   else if (symbol == "GBPUSD") isymbol = 2;
   else if (symbol == "USDJPY") isymbol = 3;
   else if (symbol == "USDCHF") isymbol = 4;
   else if (symbol == "AUDUSD") isymbol = 5;
   else if (symbol == "USDCAD") isymbol = 6;
   else if (symbol == "EURGBP") isymbol = 7;
   else if (symbol == "EURJPY") isymbol = 8;
   else if (symbol == "EURCHF") isymbol = 9;
   else if (symbol == "EURAUD") isymbol = 10;
   else if (symbol == "EURCAD") isymbol = 11;
   else if (symbol == "GBPUSD") isymbol = 12;
   else if (symbol == "GBPJPY") isymbol = 13;
   else if (symbol == "GBPCHF") isymbol = 14;
   else if (symbol == "GBPAUD") isymbol = 15;
   else if (symbol == "GBPCAD") isymbol = 16;
   return (StrToInteger(StringConcatenate(seed, isymbol, timeFrame)));
}

string GenerateComment(string EAName, int magic, int timeFrame)
{
   return (StringConcatenate(EAName, "-", magic, "-", timeFrame));
}
Forex TSD Trading Strategies, Software and Brokers Forum
Forex TSD Trading Strategies, Software and Brokers Forum
  • www.mql5.com
Forex TSD: Trading Strategies, Software and Brokers Forum
 
Check expert logs for errors.
 
Stanislav Korotky:
Check expert logs for errors.


Logs from backtest

2016.07.15 13:44:07.764    2016.07.14 23:55  zzzz-1-ilk-duzenleme EURUSD,M5: OrderClose error 4051

2016.07.15 13:44:07.764    2016.07.14 23:55  zzzz-1-ilk-duzenleme EURUSD,M5: invalid ticket for OrderClose function
2016.07.15 13:44:07.764    2016.07.14 23:50  zzzz-1-ilk-duzenleme EURUSD,M5: OrderSend error 134


Live error logs

2016.07.15 13:46:12.519    zzzz-1-ilk-duzenleme EURUSD,M1: invalid ticket for OrderClose function

 
Developer says:

"I have made an EA based on it. If SL and TP is set to 0, EA will close order when the histogram reverses and open another one"

But expert diffrent work on Backtest

 
If this EA is developed for you and you know the author, you should ask him to fix the errors, I think. Just from the glance, the code is buggy because it does not handle all possible variants between prevTS and curTS, so saved ticket number can be wrong.
 
Stanislav Korotky:
If this EA is developed for you and you know the author, you should ask him to fix the errors, I think. Just from the glance, the code is buggy because it does not handle all possible variants between prevTS and curTS, so saved ticket number can be wrong.

Thank you Stanislav.I found this expert on forextsd.So not developed for me.Developer last activity 2007 on forum :D

I was change the spread 0.4 to 0.1 and same works via live account.I think I set fixed to spread 0.4 on live ( no I can't )


I need a open orders from backtest.I wait on computer and rip start button every 5 min.

 

fix error

/*-----------------------------+
|                              |
| Shared by www.Aptrafx.com    |
|                              |
+------------------------------*/

#property copyright "pengie, Braindancer"
#property link      "http://www.forex-tsd.com"

extern string EAName = "TrendStrengthEMA";
extern int magic = 2703;

extern int SL = 0;
extern int TP = 0;

extern int slippage = 3;
extern double lots = 0.1;

datetime prevTime, curTime;
int ticket;

int init()
{
   prevTime = Time[0];
   magic = GenerateMagicNumber(magic, Symbol(), Period());
        EAName = GenerateComment(EAName, magic, Period());
        
        int maxOrders = OrdersTotal();
        int t_index;
        for (t_index=0; t_index<maxOrders; t_index++)
        {
                OrderSelect(t_index, SELECT_BY_POS, MODE_TRADES);
                if (magic==OrderMagicNumber())
                {                       
                        ticket = OrderTicket();
                        break;
                }       
        }       
   return (0);
}

int deinit()
{
   return (0);
}

int start()
{
   curTime = Time[0];
   
   if (prevTime != curTime)
   {
      prevTime = curTime;
      
      double tmp = iMA(NULL,0,11,0,MODE_EMA,PRICE_CLOSE,2);     
      double ma1 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2); 
      double ma2 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2); 
      double ma3 = tmp-iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,2); 
      double ma4 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2);  
      double ma5 = tmp-iMA(NULL,0,6,0,MODE_EMA,PRICE_CLOSE,2);
      double ma6 = tmp-iMA(NULL,0,4,0,MODE_EMA,PRICE_CLOSE,2);
      double ma7 = tmp-iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2);
     
      double prevTS = (ma1+ma2+ma3+ma4+ma5+ma6+ma7)/7; 
      
      tmp = iMA(NULL,0,11,0,MODE_EMA,PRICE_CLOSE,1);     
      ma1 = tmp-iMA(NULL,0,40,0,MODE_EMA,PRICE_CLOSE,1); 
      ma2 = tmp-iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1); 
      ma3 = tmp-iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,3); 
      ma4 = tmp-iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,1);  
      ma5 = tmp-iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,5);
      ma6 = tmp-iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1);
      ma7 = tmp-iMA(NULL,0,16,0,MODE_EMA,PRICE_CLOSE,2);
      
      double curTS = (ma1+ma2+ma3+ma4+ma5+ma6+ma7)/7;
      double stoploss, takeprofit;
      if (prevTS<0 && curTS>0)
      {
         if( ticket>0 && !(OrderSelect(ticket,SELECT_BY_TICKET) && OrderClose(ticket, OrderLots(), OrderClosePrice(), slippage, CLR_NONE)) ) return;
         stoploss = 0;
         if (SL != 0) stoploss = Ask-SL*Point;
         takeprofit = 0;
         if (TP != 0) takeprofit = Ask+TP*Point;
         ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, stoploss, takeprofit, EAName, magic, 0, CLR_NONE);         
      }
      else if (prevTS>0 && curTS<0)
      {
         if( ticket>0 && !(OrderSelect(ticket,SELECT_BY_TICKET) && OrderClose(ticket, OrderLots(), OrderClosePrice(), slippage, CLR_NONE)) ) return;
         stoploss = 0;
         if (SL != 0) stoploss = Bid+SL*Point;
         takeprofit = 0;
         if (TP != 0) takeprofit = Bid-TP*Point;
         ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, stoploss, takeprofit, EAName, magic, 0, CLR_NONE);         
      }
   }
   return (0);
}

int GenerateMagicNumber(int seed, string symbol, int timeFrame)
{
   int isymbol = 0;
   if (symbol == "EURUSD") isymbol = 1;
   else if (symbol == "GBPUSD") isymbol = 2;
   else if (symbol == "USDJPY") isymbol = 3;
   else if (symbol == "USDCHF") isymbol = 4;
   else if (symbol == "AUDUSD") isymbol = 5;
   else if (symbol == "USDCAD") isymbol = 6;
   else if (symbol == "EURGBP") isymbol = 7;
   else if (symbol == "EURJPY") isymbol = 8;
   else if (symbol == "EURCHF") isymbol = 9;
   else if (symbol == "EURAUD") isymbol = 10;
   else if (symbol == "EURCAD") isymbol = 11;
   else if (symbol == "GBPUSD") isymbol = 12;
   else if (symbol == "GBPJPY") isymbol = 13;
   else if (symbol == "GBPCHF") isymbol = 14;
   else if (symbol == "GBPAUD") isymbol = 15;
   else if (symbol == "GBPCAD") isymbol = 16;
   return (StrToInteger(StringConcatenate(seed, isymbol, timeFrame)));
}

string GenerateComment(string EAName, int magic, int timeFrame)
{
   return (StringConcatenate(EAName, "-", magic, "-", timeFrame));
}
Reason: