How to check if last 3/2 orders were closed at a loss, and if so, reverse positioning.

 

Hello, I have been trying to optimise my code so that if 2/3 orders were closed at a loss, then reverse direction of the order. I got this code from another thread and I do not understand it fully, what does the count++ function do and how does adding count == 3 mean that it counts for the last 3 orders? It does not seem to be working and it does not give any errors either. Any help would be greatly appreciated. 

void OnTick()
{
   int count=0,countInLoss=0;
   int last_3_orders=0;
   bool LastTradesLossBuy = false;
   bool LastTradesLossSell = false;



   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      if(OrderSymbol()==Symbol())
      if(OrderType() == OP_SELL)
        {
         count++;
         if(OrderProfit()<0)
            countInLoss++;
         if(count==3)
            break;
            LastTradesLossBuy == true;
        }
        
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      if(OrderSymbol()==Symbol())
      if(OrderType() == OP_BUY)
        {
         count++;
         if(OrderProfit()<0)
            countInLoss++;
         if(count==3)
            break;
            LastTradesLossSell == true;
        }
     }
}
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.