OrderDelete() returning "invalid parameters", MT4 bug?

 

Hi,

In rare cases I am getting a "invalid parameters" error for OrderDelete() which only needs the orderticket to do it´s job. This is for OP_BUYSTOP or OP_SELLSTOP order types. Before each run for OrderDelete(), I am browsing through OrdersTotal(), check them for OrderType() (only processing OP_BUYSTOP and OP_SELLSTOP types), get the ticket and then run OrderDelete(ticket). Still I get:


03:36:42 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407

03:36:42 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]


Now one of the reasons could be that the BUYSTOP order got active directly at the time the EA tries to delete it, but, the EA checks that on the next run (above mentioned loop) and then tried to delete this order again because according to OrderTotal() it was still a pending BUY_STOP order. It again got a Invalid Parameters error. However, I´ve checked with the broker and he sent me the MT4 Server log for this order. Interesting is: at the time the EA tries to delete the order, it was already opened at the MT4 server, and so all subsequent tries to delete it of course failed, but still MT4 client was reporting that this order is still a pending OP_BUYSTOP order, for over 20 seconds (in which the EA tried to delete the order all the time, but always getting invalid parameters error).

So to me this looks like a unsync bug between MT4 Terminal and MT4 Server, since OrdersTotal() was still returning that this ticket is a OP_BUYSTOP and not an open BUY Order, while at the broker server it was a buy order already for over 20 seconds. And the OrderDelete() function in my EA works fine in 99% of the cases, but then, a few times, the above described error happens and MT4 Terminal simply doesn´t get told by the MT4 Server that the order is already active.

Anyone else experienced that? How can I report it to Metaquotes?


Thanks.

 
geektrader:

Hi,

In rare cases I am getting a "invalid parameters" error for OrderDelete() which only needs the orderticket to do it´s job. This is for OP_BUYSTOP or OP_SELLSTOP order types. Before each run for OrderDelete(), I am browsing through OrdersTotal(), check them for OrderType() (only processing OP_BUYSTOP and OP_SELLSTOP types), get the ticket and then run OrderDelete(ticket). Still I get:


03:36:42 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407

03:36:42 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]

Did you get the ticket ?  did you check the return value ?

Trap the return value from the OrderDelete()  and if it is false the OrderDelete() has failed . . .   if it is false use Print() to write the following info to the log . . .

  • select the order by ticket and  print it's return value,  i.e. true or false
  • the ticket number
  • the Order type 
 
Yes, It´s doing all that, error checking is every extensive in the EA. It checks if the Ticket is not 0 after browsing through OrdersTotal() which would be an un-needed check anyway, but it still does it, then checks if the OrderSelect() function returned true when selecting the ticket, then checks if the OrderType is OP_BUYSTOP or OP_SELLSTOP (so a pending order) and only then runs OrderDelete(Ticket). I think all is right from my side. And as I said, I see from the exact time values (seconds resolution) that while OrdersTotal() in my MT4 Terminal reported the OP_BUYSTOP as not being open, at the same time the MT4 Server logs of the broker (seconds resolution) shows THAT is was opened already (ticket number matches between my EA and the log of the broker), and it was unsync for over 20 seconds between MT4 Server and MT4 Terminal before MT4 Terminal also returned that it is a OP_BUY now.
 
geektrader:
Yes, It´s doing all that, error checking is every extensive in the EA. It checks if the Ticket is not 0 after browsing through OrdersTotal() which would be an un-needed check anyway, but it still does it, then checks if the OrderSelect() function returned true when selecting the ticket, then checks if the OrderType is OP_BUYSTOP or OP_SELLSTOP (so a pending order) and only then runs OrderDelete(Ticket). I think all is right from my side. And as I said, I see from the exact time values (seconds resolution) that while OrdersTotal() in my MT4 Terminal reported the OP_BUYSTOP as not being open, at the same time the MT4 Server logs of the broker (seconds resolution) shows THAT is was opened already, and it was unsync for over 20 seconds between MT4 Server and MT4 Terminal before MT4 Terminal also returned that it is a OP_BUY now.
If it's doing all that can you show the output to the log,  copy and paste it here please.
 
One other thought . . .  is this in a loop going through all the open orders ?
 

Just look, the order is opened at the broker while MT4 is still reporting it as an OP_BUYSTOP:


MT4 Terminal Log:

03:36:40 'XXXX': pending order buy stop 0.65 EURJPY at 102.923 sl: 102.884 tp: 103.382
03:36:40 'XXXX': request was accepted by server
03:36:40 'XXXX': request in process
03:36:40 'XXXX': order was opened : #7720748 buy stop 0.65 EURJPY at 102.923 sl: 102.884 tp: 103.382
03:36:41 'XXXX': modify pending order #7720748 buy stop 0.65 EURJPY at 102.923 sl: 102.884 tp: 103.382 -> price: 102.914 sl: 102.873 tp: 103.414
03:36:41 'XXXX': request was accepted by server
03:36:41 'XXXX': request in process
03:36:41 'XXXX': pending order #7720748 buy stop 0.65 EURJPY was modified -> price: 102.914 sl: 102.873 tp: 103.414
03:36:41 'XXXX': modify pending order #7720748 buy stop 0.65 EURJPY at 102.914 sl: 102.873 tp: 103.414 -> price: 102.911 sl: 102.876 tp: 103.411
03:36:41 'XXXX': request was accepted by server
03:36:41 'XXXX': request in process
03:36:41 'XXXX': pending order #7720748 buy stop 0.65 EURJPY was modified -> price: 102.911 sl: 102.876 tp: 103.411
03:36:41 'XXXX': modify pending order #7720748 buy stop 0.65 EURJPY at 102.911 sl: 102.876 tp: 103.411 -> price: 102.907 sl: 102.867 tp: 103.407
03:36:42 'XXXX': request was accepted by server
03:36:42 'XXXX': request in process
03:36:42 'XXXX': pending order #7720748 buy stop 0.65 EURJPY was modified -> price: 102.907 sl: 102.867 tp: 103.407
03:36:42 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:42 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:42 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:43 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:43 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:43 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:43 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:43 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:43 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:43 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:43 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:43 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:43 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:43 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:44 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:44 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:44 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:44 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:44 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:44 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:44 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:44 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:44 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:44 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:45 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:45 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:45 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:45 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:45 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:45 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:46 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:46 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:46 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:46 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:46 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:46 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:46 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:46 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:46 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:46 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:48 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:48 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:48 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:48 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:48 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:48 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:48 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:48 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:49 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:49 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:49 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:49 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:49 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:49 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:49 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:49 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:49 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:49 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:50 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:50 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:50 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:50 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:50 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:50 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:51 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:51 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:51 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407
03:36:51 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]
03:36:51 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407

03:36:51 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]


Brokers MT4 Server log:

2012.10.30 03:36:42 XXX.XXX.XXX.XXX 'XXXX': order #7720748  buy stop 0.65 EURJPY at 102.92300    
2012.10.30 03:36:43 XXX.XXX.XXX.XXX 'XXXX': modify order #7720748  buy stop 0.65 EURJPY at 102.92300  sl: 102.88400 tp: 103.38200 -> 102.91400  sl: 102.87300 tp: 103.41400 exp: never
2012.10.30 03:36:43 XXX.XXX.XXX.XXX 'XXXX': modified #7720748  buy stop 0.65 EURJPY at 102.91400  sl: 102.87300 tp: 103.41400  
2012.10.30 03:36:43 XXX.XXX.XXX.XXX 'XXXX': modify order #7720748  buy stop 0.65 EURJPY at 102.91400  sl: 102.87300 tp: 103.41400 -> 102.91100  sl: 102.87600 tp: 103.41100 exp: never
2012.10.30 03:36:43 XXX.XXX.XXX.XXX 'XXXX': modified #7720748  buy stop 0.65 EURJPY at 102.91100  sl: 102.87600 tp: 103.41100  
2012.10.30 03:36:43 XXX.XXX.XXX.XXX 'XXXX': modify order #7720748  buy stop 0.65 EURJPY at 102.91100  sl: 102.87600 tp: 103.41100 -> 102.90700  sl: 102.86700 tp: 103.40700 exp: never
2012.10.30 03:36:43 XXX.XXX.XXX.XXX 'XXXX': modified #7720748  buy stop 0.65 EURJPY at 102.90700  sl: 102.86700 tp: 103.40700  

2012.10.30 03:36:43   'XXXX': order #7720748  buy 0.65 EURJPY is opened at 102.90700



You see, all runs in sync with the modifications to the pending order, but then it got out of sync as the order was opened at the broker, but MT4 Terminal still reported it as a BUY_STOP that is pending. And if it wouldn´t be still a BUYSTOP order for the MT4 Terminal it would not say "delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407". The fact that it still says "buy stop" in MT4 Terminal shows that something has got out of sync here and MT4 Terminal still sees it as a BUYSTOP order. Otherwise it would not say"buy stop" for the OrderDelete() command in the journal.


The code that does the OrderDelete is this, it´s all correct as it works 99,9% of the cases:


void DeleteStopOrders()
  {
   OrderSelectLoopOp(OSL_DELETESTOPORDERS);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool _DeleteStopOrders()
  {
   
if((OrderType()==OP_BUYSTOP) || (OrderType()==OP_SELLSTOP))
   {
  
   if(CheckTradeContext()<0)
   {
   Print(GetPrintPrefix(),"Trade context was busy and the deletion of the pending order was abandoned.");
   AnErrorOccured=true;
   return(false);
   }
     
      OrderDelete(OrderTicket());
      int err=GetLastError();
      if (err==0 || err==1) return(true);
      AnErrorOccured=true;
      return(false);
      }
    return(false);
  }

bool OrderSelectLoopOp(int callback,int mode=MODE_TRADES,int first=0,int limit=-1)
  {
   bool result;

   if(limit<0)
     {
      switch(mode)
        {
         case MODE_TRADES:  limit = OrdersTotal ();        break;
         case MODE_HISTORY: limit = OrdersHistoryTotal (); break;
        }
     }

   for(int i=first; i<limit; i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,mode)) break;
      if(OrderTicket()==0) break;

      if(((OrderSymbol()==Symbol()) || (AllPairs))
         && (OrderMagicNumber()==MagicNumber || OrderMagicNumber()==PlanBMagicNumber))
        {

         // Call back to the appropriate processing function.
         switch(callback)
           {
            case OSL_DELETESTOPORDERS:    result = _DeleteStopOrders ();    break;
           }

         if(!result) return(false);
        }
     }

   return(true);
  }

 
geektrader:

The code that does the OrderDelete is this, it´s all correct as it works 99,9% of the cases:

Your code is incorrect . . . .  when you are deleting or closing orders within a order position loop you MUST count down . . . NOT up,  read this thread:  Loops and Closing or Deleting Orders
 

You are right, but this doesn´t matter in this case since there is always only 1 (pending) order by the EA at anytime. And nevertheless you see that the ticket numbers do match, so I am not trying to delete the wrong ticket or something.

And did you look at the actual MT4 Servers logs (I got them from the broker directly) / MT4 Terminal logs (logged by me) I´ve posted? You see that the broker has opened the order at:


2012.10.30 03:36:43   'XXXX': order #7720748  buy 0.65 EURJPY is opened at 102.90700


But MT4 Terminal still reports 8 seconds later after this order was opened by the broker that exactly this ticket is still a pending buy stop order?:


03:36:51 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]


MT4 Terminal clearly says "delete pending order #7720748 buy stop", if MT4 Terminal wouldn´t see it as a "buy stop" order, it wouldn´t say "buy stop" as the OrderDelete() funtion does not have the ability to tell it in which direction the order was, so the "buy stop" is coming from MT4 Terminal and this proves MT4 Terminal still sees it as a "buy stop" at the time it was already opened at the MT4 Server of the broker.

 
geektrader:

You are right, but this doesn´t matter in this case since there is always only 1 pending order.

And did you look at the actual MT4 Servers logs / MT4 Terminal logs I´ve posted? You see that the broker has opened the order at:

No,  not really . . .   I'm happy to try and help,  add the debugging info I requested if you would like me to try and help,  if not that is fine.  Don't make assumptions . . .  print the relevant info so you have the facts at the time the error was generated,  then you will have some idea of what is actually going on not just what you think is going on.

You aren't even checking if the OrderDelete() worked or not  . . . . just checking Get:LastError() checks what the last error was . . .  it may well not belong to the OrderDelete().  You need to check the return value from OrderDelete() . . . it is a bool it will be true or false . . .

 

Use this . . .

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool _DeleteStopOrders()
   {
   
   if((OrderType()==OP_BUYSTOP) || (OrderType()==OP_SELLSTOP))
      {
  
      if(CheckTradeContext()<0)
         {
         Print(GetPrintPrefix(),"Trade context was busy and the deletion of the pending order was abandoned.");
         AnErrorOccured=true;
         return(false);
         }
     
      if( ! OrderDelete(OrderTicket()) )
         {
         int err=GetLastError();
         
         Print("Order Delete failed # ", err);
         if(OrderSelect()) 
            {
            Print("OrderSelect worked for order # , OrderTicket() );
            Print("Order Type is ", OrderType());
            }
         else Print("OrderSelect failed . . . " ); 
         if (err==0 || err==1) return(true);
         AnErrorOccured=true;
         return(false);
         }
   return(false);
   }
 
Thanks for your help Raptor, I will consider this for the code, however, that this is a unsync bug that can happen during fast market movements (this is where my EA trades) was just confirmed by Metaquotes after given them the log of MT4 Terminal against the MT4 Server log. They say, it´s clear that MT4 Server had opened the order while MT4 Terminal still was in the assumption that it is a pending "buy stop" order since the ticket numbers also did exactly match, otherwise MT4 Terminal wouldn´t have returned "buy stop" for that ticketnumber which was already opened 8 seconds ago at the broker. And it will be fixed in the next release;) Thank you anyway.
 
geektrader:
Thanks for your help Raptor, I will consider this for the code, however, that this is a unsync bug that can happen during fast market movements (this is where my EA trades) was just confirmed by Metaquotes after given them the log of MT4 Terminal against the MT4 Server log. They say, it´s clear that MT4 Server had opened the order while MT4 Terminal still was in the assumption that it is a pending "buy stop" order since the ticket numbers also did exactly match, otherwise MT4 Terminal wouldn´t have returned "buy stop" for that ticketnumber which was already opened 8 seconds ago at the broker. And it will be fixed in the next release;) Thank you anyway.

Here's another case https://www.mql5.com/en/forum/139992 no solution over there :(