result of OrderSelect(tckt,SELECT_BY_TICKET) if tckt was closed?

 

The situation:

an EA has opened two position with aTckt and bTckt and manages them (controlled Comment()).

Now I close manually one of them, e.g. aTckt.

But the following code neither set _LastError nor does OrderSelect() return false so that n is not incremented and the EA enters the branch: if( n<2)

Am I correct that:

...n=0;
   if ( OrderSelect(aTckt, SELECT_BY_TICKET) ) { n++; ..+(_LastError>1?(string)_LastError+" ":""); ...}   
   if ( OrderSelect(bTckt, SELECT_BY_TICKET) ) { n++; ..+(_LastError>1?(string)_LastError+" ":""); ...}   
   if ( n<2 ) { /* do something */    ...   }

Is that a feature (less error sensitive as too many beginners...?) or a bug?

Additionally I check this way whether a position is open, closed or not existing:

int isClsdPos( const int tckt ) {
   if ( OrderSelect(tckt,SELECT_BY_TICKET,MODE_TRADES) )  return( 1); // still something left
   if ( OrderSelect(tckt,SELECT_BY_TICKET,MODE_HISTORY) ) return(-1); // order was closed
   return(0);                                                         // ticket is unknown
}

But the manual closed position makes this function to return 0?

 

Why should this raise an error if the ticket is correct? You can select all open orders and all closed orders available in the history tab.

It works as documented.

There is a third parameter in OrderSelect() - "pool" which is used to differentiate between active and closed orders, but it is used only if you select by position.

From the OrderSelect() documentation:

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
OrderSelect - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSelect - Trade Functions - MQL4 Reference
 
Drazen Penic:

Why should this raise an error if the ticket is correct? You can select all open orders and all closed orders available in the history tab.

It works as documented.

There is a third parameter in OrderSelect() - "pool" which is used to differentiate between active and closed orders, but it is used only if you select by position.

From the OrderSelect() documentation:

It should raise an error if the position (its ticket) cannot be found in the pool!

MODE_TRADES (default)- order selected from trading pool(opened and pending orders),
MODE_HISTORY - order selected from history pool (closed and cancelled order).

So no pool means pool of open positions and an error if it was 'moved' to the pool of the closed position.

But even there it wasn't found??

 
Carl Schreiber:

It should raise an error if the position (its ticket) cannot be found in the pool!

So no pool means pool of open positions and an error if it was 'moved' to the pool of the closed position.

But even there it wasn't found??



It should raise an error if the position (its ticket) cannot be found in the pool!

No. Read the documentation, or that snippet I posted above.


So no pool means pool of open positions and an error if it was 'moved' to the pool of the closed position.

No. Pool parameter is used only when you read by position. If you read by ticket, pool parameter is ignored. Read the documentation, or that snippet I posted above. 


But even there it wasn't found??

I don't understand this one. If ticket exists in open trades or is visible in history trades, it should succeed. 

 
No. Pool parameter is used only when you read by position. If you read by ticket, pool parameter is ignored. Read the documentation, or that snippet I posted above. 

I got it and I remember - I have forgotten that. 

Reason: