Calculating open buy and sell trade profits separately for symbol

 

Hi Everyone

If somebody would please be so kind to help a new guy out here:

I started learning to code about 4 months ago and the more I try and practice, the more I learn but I'm stuck at the moment and maybe I'm interpreting it wrong but 

I want to get the total profit separately for Buy and Sell positions but no matter what I do, I keep getting only the first Position's information displayed.


I'm curious as to Where I'm going wrong as well as Why? if possible


The code I've got is as follows: and I will add the resulting image below as well if helps visually.

double totalBuyProfit        = 0.0;
double totalSellProfit       = 0.0;




void CountProfits() {

   totalBuyProfit = 0.0;   totalSellProfit = 0.0;
   
   int total=PositionsTotal();
     
   for(int i=total-1; i>=0;i--)
        {
        ulong ticket=PositionGetTicket(i);
         if(ticket==0)
            continue;
         ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
         datetime open_time=(datetime)PositionGetInteger(POSITION_TIME);
           
         if(PositionGetSymbol(i) == _Symbol && type == POSITION_TYPE_BUY)
           {                                                                                     
            totalBuyProfit =+ PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP);
            }
         if(PositionGetSymbol(i) == _Symbol && type == POSITION_TYPE_SELL)
           {
            totalSellProfit =+ PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP);
            } 
    }
Comment("Total Buy Profit  : ", totalBuyProfit, "\n",
        "Total Sell Profit : ", totalSellProfit, "\n"); 
    
}



Thank you in advance