By trying to delete pending orders from ticket number I got the error message "OrderDelete error 4108"

 

By trying to delete pending orders from ticket number I got the error message "OrderDelete error 4108"

Here is my code:


bool DeletePendingOrder(int ticket)
{
   double freezelevel     = (MarketInfo(Symbol(),MODE_FREEZELEVEL)+1)*Point;
   double openPrice, currentPrice;
   int orderType;
   
   if(!OrderSelect(ticket,SELECT_BY_TICKET))
   {
      return false;
   }
   
   orderType=OrderType();
   openPrice=OrderOpenPrice();
   
   if(OrderMagicNumber()!=MagicNumber) return false;
   
   if(orderType==OP_BUYSTOP)
      currentPrice=Ask;
   else if(orderType==OP_SELLSTOP)
      currentPrice=Bid;   
   else
      return false;
   

   if((orderType==OP_BUYSTOP && currentPrice>=openPrice-freezelevel) || 
      (orderType==OP_SELLSTOP && currentPrice<=openPrice+freezelevel))
   {
      return false;
   }
   
   double t=OrderDelete(ticket);   
   return true;
}
 
Dorian Baranes:

By trying to delete pending orders from ticket number I got the error message "OrderDelete error 4108"

Here is my code:


from mql help

error 4108 = invalid ticket

 
Eugenio Bravetti:

from mql help

error 4108 = invalid ticket

Hi Eugenio,

If you look at the code of my function before to call OrderDelete() I am checking that the ticket is existing and it is related to a pending order. So I do not understand why I get this error message.


Regards,


Dorian

 
Dorian Baranes:

Hi Eugenio,

If you look at the code of my function before to call OrderDelete() I am checking that the ticket is existing and it is related to a pending order. So I do not understand why I get this error message.


Regards,


Dorian

But you are not checking if it's already deleted (in history).
 
Dorian Baranes:

Hi Eugenio,

If you look at the code of my function before to call OrderDelete() I am checking that the ticket is existing and it is related to a pending order. So I do not understand why I get this error message.


Regards,


Dorian

OrderSelect function select order in open orders list but also in history orders list.

Add controll

if( OrderCloseTime() > 0 )
     return false;

after OrderSelect call

 

Thank you Eugenio and Alain. I thought the Order type value changed when the order is already deleted.

Regards,


Dorian

 
Dorian Baranes: I thought the Order type value changed when the order is already deleted.
  1. Order type changes when it opens.
  2. Don't use the ticket. EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.
 
Eugenio Bravetti:

OrderSelect function select order in open orders list but also in history orders list.

Add controll

after OrderSelect call


Is this still true in the latest release?
Isnt historyOrderSelect() used for getting history orders?
 
owneroxxor:

Is this still true in the latest release?
Isnt historyOrderSelect() used for getting history orders?

HistoryOrderSelect() does not exist in MQL4

 
Keith Watford:

HistoryOrderSelect() does not exist in MQL4

I mean for mql5
 
owneroxxor:
I mean for mql5

This is the MQL4 and MT4 sub forum.

Reason: