What am I missing?

 
the below code checks the conditions and double TP and SL or Returns to initial TP and SL. but when i run it, i get something like example,  1$,-1$,-2$,-2$,1$  but the way it should be is, 1$,-1$,-2$,-4$,-1$ So  basically it suppose to be doubling when it hits stop loss, unless the other condition are met, i need help please
//+------------------------------------------------------------------+
int reset()
  {
          
     
          //-----------------------------------------------------------------------------
      
      int cnt=1;
      string result1="";
      string result2="";
      string result3="";
      string result4="";
      string result5="";
      string result6="";
      
      for (int i=OrdersHistoryTotal()-1; i >= 0; i--)
      {
       
       if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY))

        
       if(OrderSymbol()==_Symbol)
       {
        if (i==OrdersHistoryTotal()-1 && OrderProfit() < 0)
         {
            result1="1 OFF";
      
         }      
        if (i==OrdersHistoryTotal()-2 && OrderProfit() < 0)
         { 
           result2="2 OFF";
        
         } 
        if (i==OrdersHistoryTotal()-3 && OrderProfit() < 0)
         { 
           result3="3 OFF";
        
         } 
        if (i==OrdersHistoryTotal()-1 && OrderProfit() > 0)
         {
            result4="1 ON";
      
         }      
        if (i==OrdersHistoryTotal()-2 && OrderProfit() > 0)
         { 
           result5="2 ON";
        
         } 
        if (i==OrdersHistoryTotal()-3 && OrderProfit() > 0)
         { 
           result6="3 ON";
        
         } 
        
            if(OrderProfit()>0)cnt=1;
            if(OrderProfit()<0)cnt=cnt*2;
            if(result1=="1 OFF" && result5=="2 ON" && result6=="3 ON")cnt=cnt*2;
            if(result4=="1 ON" && result5=="2 ON" && result6=="3 ON")cnt=1;
            if(result1=="1 OFF" && result2=="2 OFF" && result3=="3 OFF")cnt=1;
            if(result1=="1 OFF" && result5=="2 ON" && result3=="3 OFF")cnt=cnt*2;
            if(result4=="1 ON" && result2=="2 OFF" && result3=="3 OFF")cnt=1;
            if(result4=="1 ON" && result2=="2 OFF" && result6=="3 ON")cnt=1;
            if(result1=="1 OFF" && result2=="2 OFF" && result6=="3 ON")cnt=cnt*2;
            if(result4=="1 ON" && result5=="2 ON" && result3=="3 OFF")cnt=1;
           
            
        }  
 
      }
  
  }
//***************************//

ditions are met.
 

If your compiled file does not do what it should use the debugger and control the variables and conditions on each program step:

https://www.metatrader5.com/en/metaeditor/help/development/debug

Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
 
      for (int i=OrdersHistoryTotal()-1; i >= 0; i--)
      {
       
       if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY))

        
       if(OrderSymbol()==_Symbol)
  1. Do not assume history has only closed orders.
              OrderType() == 6, 7 in the history pool? - MQL4 programming forum #4 and #5 (2017)

  2. Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012)
              Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020)