Need help calculating Profit for buy position only and sell position spready

 

Hey guys need help please


Is it possible to calculate the profit for the open position either buy or sell separately. I'm using AccountInfoDouble(ACCOUNT_PROFIT) to get the profit but I cannot get the profit for the buy position only or the profit for the sell position only. It gives the total profit. I'm trying to calculate the profit for the opened buy position  only or sell position only so at certain lose point I reopen an opposite new position order to minimize the lose either a sell or a buy positions.

I used this from other posts but it doesn't work

POSITION_VOLUME * SYMBOL_TRADE_TICK_VALUE * (POSITION_PRICE_CURRENT - POSITION_PRICE_OPEN) / SYMBOL_TRADE_TICK_SIZE;


Any help much appreciated thank you in advance 

 
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Monitor_trade() ;
  }
//+------------------------------------------------------------------+
void Monitor_trade() 
{ 

  double bprofit=0, blots=0, sprofit=0, slots=0 ;
  int bpos=0, spos=0 ;
   for(int i=0; i<PositionsTotal(); i++)
     {
       if(m_position.SelectByIndex(i))
        {
         if(m_position.Symbol() == _Symbol && m_position.Magic() == Magic_Ea)
           {
                                                                                     
            if(m_position.PositionType() == POSITION_TYPE_BUY )
              {
               bprofit        += m_position.Profit() + m_position.Swap();           // for Check current BUY Profit $
               blots          += m_position.Volume();                               // for Check current BUY Lot 
               bpos += 1;                                                           // for Check current BUY  total
              }
            if(m_position.PositionType() == POSITION_TYPE_SELL )
              {
               sprofit        += m_position.Profit() + m_position.Swap();           // for Check current SELL Profit $
               slots          += m_position.Volume();                               // for Check current SELL Lot 
               spos += 1;                                                           // for Check current SELL total
              } 
           }
        }
     } 
     
  } 

try this.