Wrong symbol for Pending Order ticket during EA backtesting - page 2

 
ForexTraingRobot01:

I am actually testing stuff right now so it is greyed out but these are my settings.

Most likely, the reason for this.


 
fxsaber:

Most likely, the reason for this.



Can you explain why?

 
ForexTraingRobot01:

Without the problem.

#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

bool OrderScan( const string Symb )
{
  bool Res = false;
  
  for (int i = OrdersTotal() - 1; (i >= 0) && !Res; i--)
    Res = OrderSelect(i, SELECT_BY_POS) && (OrderSymbol() == Symb);
  
  return(Res);
}

void OnInit()
{
  MqlTick Tick;  
  SymbolInfoTick("GBPUSD", Tick);
}

void OnTick()
{
  if ((TimeCurrent() == D'2018.11.28 12:30') && !OrderScan("EURGBP"))
    OrderSend("EURGBP", OP_BUYSTOP, 1, 0.88422, 0, 0, 0);
  else if ((TimeCurrent() == D'2018.11.28 14:30') && !OrderScan("GBPUSD"))
    OrderSend("GBPUSD", OP_SELLSTOP, 1, 1.27879, 0, 0, 0);
  else if ((TimeCurrent() == D'2018.11.28 14:33:58') && OrderScan("GBPUSD") && (OrderType() == OP_SELL) && !OrderStopLoss())
  {
    OrderModify(OrderTicket(), OrderOpenPrice(), 1.32878, 0, 0);
    
    if (OrderScan("EURGBP"))
      OrderModify(OrderTicket(), 0.88262, 0, 0, 0);    
  }
}


Result

2018.11.28 12:30:00   buy stop 1.00 EURGBP at 0.88422 (0.88354 / 0.88372 / 0.88354)
2018.11.28 14:30:00   sell stop 1.00 GBPUSD at 1.27879 (1.27929 / 1.27948 / 1.27929)
2018.11.28 14:33:58   order [#3 sell stop 1.00 GBPUSD at 1.27879] triggered
2018.11.28 14:33:58   deal #2 sell 1.00 GBPUSD at 1.27878 done (based on order #3)
2018.11.28 14:33:58   deal performed [#2 sell 1.00 GBPUSD at 1.27878]
2018.11.28 14:33:58   order performed sell 1.00 at 1.27878 [#3 sell stop 1.00 GBPUSD at 1.27879]
2018.11.28 14:33:58   position modified [#3 sell 1.00 GBPUSD 1.27878 sl: 1.32878]
2018.11.28 14:33:58   order modified [#2 buy stop 1.00 EURGBP at 0.88262]
 
fxsaber:

Without the problem.


Result


I am not sure what this has proven. You made one order modification only.

Can you replicate the problem with 32 ms or more AND trying to modify mutiple pending orders at the same time?


When I was running with trade.OrderModify(..) most of the modifications where successfull but once in a while I had this problem. It wasn't a problem in ALL modifications.

However the problem dissapeared when I switched to OrderSend(), and the 38ms delay to the server was still the same.

 

Anyway it doesn't really matter.

I found a workaround using OrderSend() so I am fine.

If you can replicate my problem then we can discuss it further,  otherwise let's move on and note it down as a potential bug.


Maybe someone else who get's this problem can find the answer here.


Thanks

 
ForexTraingRobot01:

When I was running with trade.OrderModify(..) most of the modifications where successfull but once in a while I had this problem. It wasn't a problem in ALL modifications.

I see

#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006
#include <Trade\Trade.mqh>

bool OrderScan( const string Symb )
{
  bool Res = false;
  
  for (int i = OrdersTotal() - 1; (i >= 0) && !Res; i--)
    Res = OrderSelect(i, SELECT_BY_POS) && (OrderSymbol() == Symb);
  
  return(Res);
}

void OnInit()
{
  MqlTick Tick;  
  SymbolInfoTick("GBPUSD", Tick);
}

void OnTick()
{
  if ((TimeCurrent() == D'2018.11.28 12:30') && !OrderScan("EURGBP"))
    OrderSend("EURGBP", OP_BUYSTOP, 1, 0.88422, 0, 0, 0);
  else if ((TimeCurrent() == D'2018.11.28 14:30') && !OrderScan("GBPUSD"))
    OrderSend("GBPUSD", OP_SELLSTOP, 1, 1.27879, 0, 0, 0);
  else if ((TimeCurrent() == D'2018.11.28 14:33:58') && OrderScan("GBPUSD") && (OrderType() == OP_SELL) && !OrderStopLoss())
  {
    OrderModify(OrderTicket(), OrderOpenPrice(), 1.32878, 0, 0);
    
    if (OrderScan("EURGBP"))
    {
//      OrderModify(OrderTicket(), 0.88262, 0, 0, 0);    

      CTrade trade;
      trade.OrderModify(OrderTicket(), 0.88262, 0, 0, ORDER_TIME_GTC, 0, 0);      
    }
  }
}


2018.11.28 12:30:00   buy stop 1.00 EURGBP at 0.88422 (0.88354 / 0.88372 / 0.88354)
2018.11.28 14:30:00   sell stop 1.00 GBPUSD at 1.27879 (1.27929 / 1.27948 / 1.27929)
2018.11.28 14:33:58   order [#3 sell stop 1.00 GBPUSD at 1.27879] triggered
2018.11.28 14:33:58   deal #2 sell 1.00 GBPUSD at 1.27878 done (based on order #3)
2018.11.28 14:33:58   deal performed [#2 sell 1.00 GBPUSD at 1.27878]
2018.11.28 14:33:58   order performed sell 1.00 at 1.27878 [#3 sell stop 1.00 GBPUSD at 1.27879]
2018.11.28 14:33:58   position modified [#3 sell 1.00 GBPUSD 1.27878 sl: 1.32878]
2018.11.28 14:33:58   failed modify order #2 buy stop 1.00 GBPUSD at 0.88422 sl: 0.00000 tp: 0.00000 -> 0.88262, sl: 0.00000 tp: 0.00000 [Invalid price]
2018.11.28 14:33:58   CTrade::OrderSend: modify #2 at 0.88262 (sl: 0.00000 tp: 0.00000) [invalid price]
 
ForexTraingRobot01:

Maybe someone else who get's this problem can find the answer here.

Try this

//+------------------------------------------------------------------+
//| Modify specified pending order                                   |
//+------------------------------------------------------------------+
bool CTrade::OrderModify(const ulong ticket,const double price,const double sl,const double tp,
                         const ENUM_ORDER_TYPE_TIME type_time,const datetime expiration,const double stoplimit)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- clean
   ClearStructures();   
   m_request.symbol = ::OrderSelect(ticket) ? ::OrderGetString(ORDER_SYMBOL) : NULL;
//--- setting request
   m_request.action      =TRADE_ACTION_MODIFY;
   m_request.magic       =m_magic;
   m_request.order       =ticket;
   m_request.price       =price;
   m_request.stoplimit   =stoplimit;
   m_request.sl          =sl;
   m_request.tp          =tp;
   m_request.type_time   =type_time;
   m_request.expiration  =expiration;
//--- action and return the result
   return(OrderSend(m_request,m_result));
  }
 
fxsaber:

I see



There you go. So it may be a bug after all.

I am glad you could replicate it.

 
fxsaber:

Try this


Hi,

if you have seen my response in the previous page I have already tried this and it works.


So the problem must be somewhere in

trade.OrderModify()
 
ForexTraingRobot01:

So the problem must be somewhere in 

Change Trade.mqh

Forum on trading, automated trading systems and testing trading strategies

Wrong symbol for Pending Order ticket during EA backtesting

fxsaber, 2019.05.29 22:30

//+------------------------------------------------------------------+
//| Modify specified pending order                                   |
//+------------------------------------------------------------------+
bool CTrade::OrderModify(const ulong ticket,const double price,const double sl,const double tp,
                         const ENUM_ORDER_TYPE_TIME type_time,const datetime expiration,const double stoplimit)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- clean
   ClearStructures();   
   m_request.symbol = ::OrderSelect(ticket) ? ::OrderGetString(ORDER_SYMBOL) : NULL;
//--- setting request
   m_request.action      =TRADE_ACTION_MODIFY;
   m_request.magic       =m_magic;
   m_request.order       =ticket;
   m_request.price       =price;
   m_request.stoplimit   =stoplimit;
   m_request.sl          =sl;
   m_request.tp          =tp;
   m_request.type_time   =type_time;
   m_request.expiration  =expiration;
//--- action and return the result
   return(OrderSend(m_request,m_result));
  }
Reason: