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

To add comments, please log in or register
Dorian Baranes
23272
Dorian Baranes  

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;
}
Eugenio Bravetti
1808
Eugenio Bravetti  
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

Dorian Baranes
23272
Dorian Baranes  
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

Alain Verleyen
38714
Alain Verleyen  
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).
Eugenio Bravetti
1808
Eugenio Bravetti  
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

Dorian Baranes
23272
Dorian Baranes  

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

Regards,


Dorian

William Roeder
20233
William Roeder  
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.
owneroxxor
46
owneroxxor  
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?
Keith Watford
Moderator
20526
Keith Watford  
owneroxxor:

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

HistoryOrderSelect() does not exist in MQL4

owneroxxor
46
owneroxxor  
Keith Watford:

HistoryOrderSelect() does not exist in MQL4

I mean for mql5
Keith Watford
Moderator
20526
Keith Watford  
owneroxxor:
I mean for mql5

This is the MQL4 and MT4 sub forum.

To add comments, please log in or register