Order Select Mode_Trades returns a CLOSED order!

To add comments, please log in or register
Stanislav Ivanov
6589
Stanislav Ivanov  

Hi All,

I have an interesting situation, where i need order select filtering the still opened from closed trades, via ticket in a loop.

This is the code i am using :

         if(!OrderSelect(tkt[i].last_ticket,SELECT_BY_TICKET))
            continue;
         if(OrderSymbol()==Symbol())

and from printing out values and many observations, the order select returns a non-existent order(a closed one), it returns its ticket correct, and all its properties, but its closed. 

Does anyone know how to fix this, or substitute it(give an alternative)?

Thanks

Stan 

nicholi shen
2392
nicholi shen  
If a trade is in the history pool then how could it still be open? 
Stanislav Ivanov
6589
Stanislav Ivanov  
Exactly! There is no sense in it
Alain Verleyen
38676
Alain Verleyen  
Stanislav Ivanov:
Exactly! There is no sense in it
SELECT_BY_TICKET returns from open OR history orders, whatever. If you want only closed or open orders you need to check OrderCloseTime(). Open orders have clos time = 0.
Fernando Carreiro
4982
Fernando Carreiro  
Stanislav Ivanov: Exactly! There is no sense in it

No! An OrderSelect() by SELECT_BY_TICKET will always select that order, irrespective of whether it is Open or Closed. The "pool" parameter is only valid when using SELECT_BY_POS.

EDIT: Looks like @Alain Verleyen posted it before me!

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...
Stanislav Ivanov
6589
Stanislav Ivanov  
Hmm, I see, thanks guys
To add comments, please log in or register