why 'OrderSelect' function return true to closed orders too?

 

Hi

I have this code and i select order #12345, OrderSelect function always return true even when order closed with takeprofit

Why?


Print(OrderSelect(12345,SELECT_BY_TICKET, MODE_TRADES));
 
Ali D32:

Hi

I have this code and i select order #12345, OrderSelect function always return true even when order closed with takeprofit

Why?


Because it is a bool value which returns only true or faluse

see below

bool  OrderSelect(
   int     index,            // index or order ticket
   int     select,           // flag
   int     pool=MODE_TRADES  // mode
   );

https://docs.mql4.com/trading/orderselect

OrderSelect - Trade Functions - MQL4 Reference
OrderSelect - Trade Functions - MQL4 Reference
  • docs.mql4.com
To find out from what list the order has been selected, its close time must be analyzed. If the order close time equals to 0, the order is open or pending and taken from the terminal open orders list. One can distinguish an opened order from a pending order by the order type. If the order close time does not equal to 0, the order is a closed...
 
Ali D32: i select order #12345, OrderSelect function always return true even when order closed with takeprofit
Perhaps you should read the manual.
The pool parameter is ignored if the order is selected by the ticket number. The ticket number is a unique order identifier.
          OrderSelect - Trade Functions - MQL4 Reference
 
Mohammad Soubra:

Because it is a bool value which returns only true or faluse

see below

https://docs.mql4.com/trading/orderselect

It shouldn't return false when i select order that closed ?!

If not how can i know order closed with tp or sl ???

 
Ali D32:

It shouldn't return false when i select order that closed ?!

If not how can i know order closed with tp or sl ???

However, your code is not shown
Show your code
Or at least the full part you have the problem on
Otherwise, we cannot help
 
Ali D32:

It shouldn't return false when i select order that closed ?!

If not how can i know order closed with tp or sl ???

  1. OrderSelect() returns true if the function succeeds (if it could select the order), otherwise false (in your case if the ticket doesn't exist). It has nothing to do with opened/closed order
  2. If you want to know if the order was closed by TP or SL you have to find out if the order is closed first by OrderCloseTime() and then you can compare OrderClosePrice() with your SL and TP.
 
When you specify the ticket number the pool parameter is complete ignored, so when you use the ticket number and the order is closed you are selecting it from the MODE_HISTORY pool. It's returning true because the order functions are correctly pointed to it now. 
 
Ali D32: It shouldn't return false when i select order that closed ?!

If not how can i know order closed with tp or sl ???

  1. It doesn't.
    1. If you select by position in the trade pool you get open and pending orders.
    2. If you select by position in the history pool you get closed, deleted and adjustments.
    3. If you select by ticket you get the ticket. PERIOD. It may be pending, open, closed, or deleted - you must check.
    4. You only get false if you use a non-existent position or ticket.

  2. In MT5 you can find out. There isn't anything in MT4. Best you can do is see if the OrderClosePrice is nearer to TP or SL.
 
Emma Schwatson:
When you specify the ticket number the pool parameter is complete ignored, so when you use the ticket number and the order is closed you are selecting it from the MODE_HISTORY pool. It's returning true because the order functions are correctly pointed to it now. 

Ty Emma, it's my answer. i understand my mistake about pool parameter...

ty everybody that help me