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

 

Hello,

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");
         else
               Print("status pending");
    }
    if(OrderSelect( ticket,SELECT_BY_TICKET,MODE_HISTORY ) == true)
      Print("status closed");
    else
      Print("status unknown");
     return 0;
}

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

Thank you

 
chinaski:

Hello,

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

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." 

 
Keith Watford:

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 )

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

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 ).

OrderCloseTime - Trade Functions - MQL4 Reference
OrderCloseTime - Trade Functions - MQL4 Reference
  • docs.mql4.com
Close time for the currently selected order. If order close time is not 0, then the order selected and has been closed and retrieved from the account history. Open and pending orders close time is equal to 0.
 
Thank guys for your help. Good ideas will help