OrderSelect(...MODE_HISTORY) returns true for pending orders


when i call this function with a ticket of a pending order

int check_ticket_status(ulong ticket)
    if(OrderSelect( ticket,SELECT_BY_TICKET,MODE_TRADES) == true)
         int otype=OrderType();
         if(otype == OP_BUY || otype == OP_SELL)
               Print("status filled");
               Print("status pending");
    if(OrderSelect( ticket,SELECT_BY_TICKET,MODE_HISTORY ) == true)
      Print("status closed");
      Print("status unknown");
     return 0;

it prints status pending and status closed to console. Shouldn’t OrderSelect(…MODE_HISTORY) return false ?

Thank you

No, when you select by ticket the mode is ignored.

From the documentation

“The pool parameter is ignored if the order is selected by the ticket number. The ticket number is a unique order identifier.”

Yes unique number, but argument is not clear to me. How to know, if order is filled or not ?

you may check order type in the closed or deleted

or ( not certain solution ) check order profit in the history if it was different from zero it might be filled order ( not pending )

To check when a Pending Order is triggered and becomes a market order, check the OrderType() to see if it has become a OP_BUY or an OP_SELL !

For a closed order, check the close time ( OrderCloseTime() != 0 ) .

Thank guys for your help. Good ideas will help