PositionGetInteger(POSITION_TYPE) always get

 

PositionGetInteger(POSITION_TYPE) returns 0, when the function fail, and when the position type is BUY.

the coding result always returns 0, regardless of buy position, sell position.

How to correct this problem?

// Order placement
   if(newBar == true && timerOn == true)
      {

      bool select=PositionSelect(_Symbol);
      if(select==true) 
      {
         ENUM_POSITION_TYPE type=PositionGetInteger(POSITION_TYPE);
         if(type==POSITION_TYPE_BUY) positionType=1;
         if(type==POSITION_TYPE_SELL) positionType=-1;
      }
      else positionType=0;
...}


 

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position ticket. Unique number assigned to each newly opened position. It usually matches the ticket of an order used to open the position except when the ticket is changed as a result of service operations on the server, for example, when charging swaps with position re-opening. To find an order used to open a position, apply the...
 
Kan Kan :

PositionGetInteger( POSITION_TYPE ) returns 0, when the function fail, and when the position type is BUY.

the coding result always returns 0, regardless of buy position, sell position.

How to correct this problem?


You must abandon the construction:

 bool select=PositionSelect(_Symbol);


you need to go through all positions in the loop:

   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
 
How to start with MQL5
How to start with MQL5
  • 2020.03.12
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 

thanks, i will try.

Reason: