CPositionInfo bug

 

CPositionInfo::Type() gives always 0, for Buy and Sell positions.


      double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
      double bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits);            
      double P = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_POINT), _Digits);

      if (!done) {
         mTrade.SellStop(0.1, bid - 10*P, _Symbol, 0.0, 0.0, ORDER_TIME_GTC);
         mTrade.BuyStop(0.1, ask + 10*P, _Symbol, 0.0, 0.0, ORDER_TIME_GTC);
      }

      done = true;

      for(int i=PositionsTotal()-1; i>=0; i--) 
      if(mPosition.SelectByIndex(i)) 
      {  
         Print ("Position Type = ", mPosition.Type());
         mTrade.PositionClose(mPosition.Ticket());
      }

      return;
Documentation on MQL5: Standard Library / Trade Classes / CPositionInfo
Documentation on MQL5: Standard Library / Trade Classes / CPositionInfo
  • www.mql5.com
CPositionInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
You need to use PositionType() method, not Type().
 
Alain Verleyen #:
You need to use PositionType() method, not Type().

Thank you!!