Count Buy and Sell Positions not working. Any advice?

 

I'm working on a script and it uses a form of martingale based on how many positions are open. The only problem is the code isn't working correctly. I've double checked it a million times but it just doesn't work correctly. Basically I'm trying to check if its buy or sell then count up each buy and sell but instead what is happening is its counting each open position as a "buy" even if its a sell. So my sells are always set to 0 and my buys seems to for some reason always represent how many total positions I have open. So if I have 6 trades open, 3 of them buy and 3 of them sell the script will return my values as 6 buys open and 0 sells. Here is the code, I'm almost 100% sure I wrote it correctly but apparently I didn't because the computer is saying otherwise.

// loop through all open trades and count open buys and sells
      for(int i=0; i<PositionsTotal(); i++)
        {
         PositionSelectByTicket(i);
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
           {
            gridMartingaleCountBuy+=1;
           }
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
           {
            gridMartingaleCountSell+=1;
           }
        }

printf("THE NUMBER OF MARTIN COUNTS ARE B/S "+gridMartingaleCountBuy+"/"+gridMartingaleCountSell);

I believe I have everything correct but its not calculating.