How to close all opened positions in profit for the current symbol

 

Hi everybody,

A new challenge, i Need to close all the opened positions in profit, compliant with the minimum profit i want, for the current symbol only.

I read some related topics on this forum but i can't make it work.

Here is my code

void CloseAllProfit()
{
  double PositionProfit=PositionGetDouble(POSITION_PROFIT); // Calculate the position profit
  int PositionSwap=(int)PositionGetDouble(POSITION_SWAP);   // Calculate current position Swap
  double PositionNetProfit=PositionProfit+PositionSwap;     // Caclulate Position net profit
  for(int i=PositionsTotal()-1; i>=0; i--)                  //---Look at all positions
   {
   if(m_position.Symbol()==Symbol())
      {
      if(m_position.SelectByIndex(i))                       // selects the position by index for further access to its properties
         {
         if(PositionNetProfit=>CloseCondition)
            {     
            m_trade.PositionClose(m_position.Ticket());     // close a position by the specified symbol
            }
           }
          }
         }
}

If someone can help me...

 

I found the problem.

i replaced :

 if(PositionNetProfit=>CloseCondition
by
if(m_position.Profit()>=CloseCondition)