Sum of open position values ​​(mt5)

 

I am not able to get the sum of the open amounts. Can someone help me? Note: The sum of order quantity is ok.

#include <Trade\Trade.mqh>
CTrade trade;

void OnTick()

{ 

//+------------------------------------------------------------------+
//|  SELL POSITION - SUM AMOUNT OF OPEN ORDERS                       |
//+------------------------------------------------------------------+

   int SellVolume=0; 
   
   for (int i=PositionsTotal() -1; i>=0; i--)  // count all currency pair positions
      
      {
         string symbol=PositionGetSymbol(i); // get position currency pair symbol
         string SellQuant = PositionGetInteger(POSITION_TYPE);
         
         if (symbol==_Symbol && SellQuant==POSITION_TYPE_SELL) // if chart symbol equels position symbol
         {
            SellVolume+=1; // add 1 to counter
         } 
       } 

//+------------------------------------------------------------------+
//|  SELL POSITION - SUM OF OPEN POSITION VALUES                     |
//+------------------------------------------------------------------+

   int SellValor=0; 
   
   for (int i=PositionsTotal() -1; i>=0; i--)  // count all currency pair positions
      
      {
         string symbol=PositionGetSymbol(i); // get position currency pair symbol
         double SellResultado = PositionGetDouble(POSITION_PROFIT);
       
         if (symbol==_Symbol && SellResultado==POSITION_TYPE_SELL) // if chart symbol equels position symbol
         {
            SellValor+=1; // add 1 to counter
         } 
       } 
       
               
        Comment("\n",         
         "Sell  : Qt:",SellVolume,"  |  Vl: ", SellValor );
  }
 
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...
 

Your help is indescribable, thank you very much!

 
         string symbol=PositionGetSymbol(i); // get position currency pair symbol
         double SellResultado = PositionGetDouble(POSITION_PROFIT);

Select a position first. via CPositionInfo or directly.