mt5 not found an open position in MQL5

 

Hi all,

I used this code for get the position information:


   for(int i = PositionsTotal() - 1; i >= 0; i--) //---Look at all positions
     {
      if(m_position.SelectByIndex(i))  // selects the position by index for further access to its properties
        {
       Print("POS_symbol ", m_position.Symbol());

        }
     }

But sometimes it is missing some symbols on the position. I don't know why?

The problem was solved when I changed 

m_position.Symbol()

to 

PositionGetSymbol(i)

Is there a bug?

 

But sometimes it is missing some symbols on the position.

It's difficult to know what you are talking about ?

The problem was solved when I changed 

These 2 statements are doing very different things.

 
Cuong Le VanIs there a bug?

Please, read the documentation carefully.

m_position.Symbol() : Simply gets the name of position symbol.

PositionGetSymbol() : Returns the symbol corresponding to the open position and automatically selects the position for further working with it using functions PositionGetDoublePositionGetIntegerPositionGetString.

 
Miguel Angel Vico Alba #:

Please, read the documentation carefully.

m_position.Symbol() : Simply gets the name of position symbol.

PositionGetSymbol() : Returns the symbol corresponding to the open position and automatically selects the position for further working with it using functions PositionGetDoublePositionGetIntegerPositionGetString.

How about 

PositionGetString(POSITION_SYMBOL);

It makes me confused.

With mql4, only need  OrderSymbol() 

 
Cuong Le Van #:

How about 

It makes me confused.

With mql4, only need  OrderSymbol() 

Everything you need to know is here:

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.

Reason: