OrderSelect BY_POS in MQL5

To add comments, please log in or register
David Diez
1207
David Diez  

As far as I could see, there's no PositionSelect by index in MQL5, so how can this be done?

   for(int i=OrdersTotal()-1;i>=0;i--){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
Konstantin Nikitin
12189
Konstantin Nikitin  

Something like this...

   for(int i=0; i<(int)PositionsTotal(); i++)
     {
      ulong ticket=PositionGetTicket(i);
      if(ticket                              ==0)                   continue;
      if( PositionGetString(POSITION_SYMBOL) != _Symbol )           continue;
      if( PositionGetInteger(POSITION_MAGIC) != 12345 )             continue;
      if( PositionGetInteger(POSITION_TYPE)  != POSITION_TYPE_BUY &&
          PositionGetInteger(POSITION_TYPE)  != POSITION_TYPE_SELL) continue;
/* work */
     }
Or CPositionInfo
David Diez
1207
David Diez  
Konstantin Nikitin:

Something like this...

But that ticket=0 will work only in Startegy Tester, tickets have different number on broker operation.
Konstantin Nikitin
12189
Konstantin Nikitin  
David Diez:
But that ticket=0 will work only in Startegy Tester, tickets have different number on broker operation.

PositionGetTicket

The ticket of the position. Returns 0 if the function fails.

You can use PositionGetSymbol
David Diez
1207
David Diez  
Konstantin Nikitin:

PositionGetTicket

The ticket of the position. Returns 0 if the function fails.

Ok, thank you.
To add comments, please log in or register