OrderDelete() error number 4108

 
     if( OrderSelect(sticket, SELECT_BY_TICKET)==true ){
         order_type=OrderType();
         Alert("ticket : ",sticket," order : ",order_type," bticket : ", bticket);     
                  if(order_type == 1){
                     OrderDelete(bticket);
                     Alert("error:",GetLastError());
                  }
         } 

hi, i wrote this code, it mean if order sell goes active, delete buy position ...

but i got ( error:4108 ), it means : ERR_INVALID_TICKET (4108) ;

but when i check it, ticket number is right !

so what can i do for it ?

thanks

 
if( OrderSelect(sticket, SELECT_BY_TICKET)==true ){
         order_type=OrderType();
         Alert("ticket : ",sticket," order : ",order_type," bticket : ", bticket);     
                  if(order_type == 1){
                     OrderSelect(bticket, SELECT_BY_TICKET);
                     OrderDelete(bticket);
                     Alert("error:",GetLastError());
                  }
         } 
 
still didn't work, I've test it in Union Forex broker
 
4ng3l:
still didn't work, I've test it in Union Forex broker


put an alert("bticket is: ", bticket);

c what happens

 
PLEASE USE OrderClose() not OrderDelete() for open orders. Orderdelete() is for pending orders. Thanks.
 
4ng3l:

hi, i wrote this code, it mean if order sell goes active, delete buy position ...

but i got ( error:4108 ), it means : ERR_INVALID_TICKET (4108) ;

but when i check it, ticket number is right !

so what can i do for it ?

thanks


It is very bad practice to hard code explicit values which are defined using #define

For example you are comparing OrderType() to 1. You should compare it to OP_BUY, OP_BUYLIMIT or something like that. It makes the code much more readable and you are less likely to make mistakes.