MT5 gives different execution price at market at same time on different optimisation runs

 

Using my EA which runs multicurrency, re-running same optimisation or even same test will randomly result with slight variation in results once or twice in 10 times. I can sometimes repeat several times in a row, same result comes, then suddenly i repeat again and slightly different result.

When i look at per trade results for a short sample, i notice this seems to come from taking different execution price for entering an order for the odd runs, even though it is executed at same exact time and i use market execution. See photo, highlighted in yellow are the transactions where there is the difference, you can see this doesnt happen for any other tx as well.


Also attached my order entry code in case it helps.

// BUY AT MARKET WITH AN SL AND TP
bool OrderMarket(int SignalDirection, double UsedLotSize, int SlippageAccept, int EaMagicNumber, string CurrencyUsed)
  {
//Min and Max volumes possible for symbol
   double minLot =  SymbolInfoDouble(CurrencyUsed, SYMBOL_VOLUME_MIN);
   double maxLot =  SymbolInfoDouble(CurrencyUsed, SYMBOL_VOLUME_MAX);

// taking at least the min volume and at max the max volume
   UsedLotSize = MathMax(minLot, UsedLotSize);
   UsedLotSize = MathMin(maxLot, UsedLotSize);
   UsedLotSize = NormalizeDouble(UsedLotSize,2);

// execution prices
   double BuyPrice = SymbolInfoDouble(CurrencyUsed, SYMBOL_ASK);                                       // get buy prices for symbol
   double SellPrice = SymbolInfoDouble(CurrencyUsed, SYMBOL_BID);                                      // get sell prices for symbol

   if(SignalDirection==1)
     {
      //--- declare and initialize the trade request and result of trade request
      MqlTradeRequest request= {};
      MqlTradeResult  result= {};
      //--- parameters of request
      request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
      request.symbol   =CurrencyUsed;                          // symbol
      request.volume   =UsedLotSize;                           // variable volume
      request.type     =ORDER_TYPE_BUY;                        // order type
      request.price    =BuyPrice;                              // price for opening
      request.deviation=SlippageAccept;                        // allowed deviation from the price (in pips?)
      request.magic    =EaMagicNumber;                         // MagicNumber of the order
      //--- send the request
      if(!OrderSend(request,result))
         return(false);
      return(true);
     }
   else
      if(SignalDirection==-1)
        {
         //--- declare and initialize the trade request and result of trade request
         MqlTradeRequest request= {};
         MqlTradeResult  result= {};
         //--- parameters of request
         request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
         request.symbol   =CurrencyUsed;                          // symbol
         request.volume   =UsedLotSize;                           // variable volume
         request.type     =ORDER_TYPE_SELL;                       // order type
         request.price    =SellPrice;                             // price for opening
         request.deviation=SlippageAccept;                        // allowed deviation from the price (in pips?)
         request.magic    =EaMagicNumber;                         // MagicNumber of the order
         //--- send the request
         if(!OrderSend(request,result))
            return(false);
         return(true);
        }
      else
        {
         return(false);
        }
  }


Looking for help to debug this, anybody aware of any known issues that can cause something like that?

Again to reiterate, the strangest part is it seems to happen randomly, i could run 3 runs that have the same result only to get the 4th with the slightly different result.


Any ideas or suggestions would be very much appreciated. If you need any further info, also happy to share.

Some basic info: its a multicurrency EA as you can see from the trades, running OnTimer per 1 sec, on real by tick data from broker

 
Basim Al Rosan:

Using my EA which runs multicurrency, re-running same optimisation or even same test will randomly result with slight variation in results once or twice in 10 times. I can sometimes repeat several times in a row, same result comes, then suddenly i repeat again and slightly different result.

When i look at per trade results for a short sample, i notice this seems to come from taking different execution price for entering an order for the odd runs, even though it is executed at same exact time and i use market execution. See photo, highlighted in yellow are the transactions where there is the difference, you can see this doesnt happen for any other tx as well.


Also attached my order entry code in case it helps.


Looking for help to debug this, anybody aware of any known issues that can cause something like that?

Again to reiterate, the strangest part is it seems to happen randomly, i could run 3 runs that have the same result only to get the 4th with the slightly different result.


Any ideas or suggestions would be very much appreciated. If you need any further info, also happy to share.

Some basic info: its a multicurrency EA as you can see from the trades, running OnTimer per 1 sec, on real by tick data from broker

Additional info: if i run an optimisation, i get again a different in 1 out of every 10 runs, but then the slight difference will be in all the optimised values, for me that suggests that the issue could be data synch related but not sure how to solve that.

this is the code i use to load my symbol in the OnInit function, where the loadcheck function just stops the ea if there result is error and prints that. Am i doing something wrong here?

//CREATING LOOP TO INITIALISE INDICATOR ARRAYS FOR EACH SYMBOL
   for(int i=0; i<NumTradeableSymbols; i++)
     {
      // 1.0 GENERAL: LOADING SYMBOL
      bool loadSymbol =  SymbolSelect(SymbolArray[i],true);
      LoadCheck(loadSymbol, SymbolArray[i], "load symbol");
     }
 
It's not executed at the same time, but at the same second. Check the milliseconds of the tick at execution time.
 
Alain Verleyen #:
It's not executed at the same time, but at the same second. Check the milliseconds of the tick at execution time.

Thanks Alain for the reply. 

do you know a way to check the milliseconds of the tick at the execution time? (maybe i misunderstood the link you shared but couldnt find any explanation for that there)

It is still odd why would that specifically happen only on some trades and some simulations but not others.