profit calculation for only open buy orders

 

I am able to get the profit of the first buy trade but when I open another buy it does not sum it.
How can I calculate the profit for all open buy orders?
Thanks in advance.


  if(PositionSelect(_Symbol)==true)
     {
      double Profit_Sum=0;
      for(int i=PositionsTotal()-1; i>=0;i--)
        {
         
         string PositionSymbol=PositionGetString(POSITION_SYMBOL);
         double PositionProfit = PositionGetDouble(POSITION_PROFIT);
        
         if(PositionSymbol==_Symbol)
           {
            Profit_Sum+=PositionProfit;
           }
         
        }
      
      Comment(Profit_Sum);
     }
 
Ugur Karaes: I am able to get the profit of the first buy trade but when I open another buy it does not sum it. How can I calculate the profit for all open buy orders? Thanks in advance.

You have to select the position within the loop iterations ...

double Profit_Sum = 0;
for( int i = PositionsTotal() - 1; i >= 0; i-- )
{
   if( PositionGetSymbol( i ) == _Symbol )
      Profit_Sum += PositionGetDouble( POSITION_PROFIT );
};