Backtesting- Not recognizing all possible trades & not exiting when it is supposed to

 
void OnTick()
  {
//---
  if(!CheckIfOpenOrdersByMagicNumber(MN))
 { 
   while (isNewBar() == true)
   {
      if (High[1] > High[2] && Close[1] < Close[2])//reversal params
   {
      Alert("Going short. Reversal Bar.");
      
      double stopLossPrice = High[1]+ Point;
      double takeProfitPrice = 0;
      double stoplevel = MarketInfo(NULL, MODE_STOPLEVEL)*GetPipValue();
      double entry = Bid;
      if (MathAbs(entry - stopLossPrice) < stoplevel)
      {entry = entry - (stoplevel-MathAbs(entry - stopLossPrice));}
     
      int OrderID = OrderSend(NULL,OP_SELL,lotsize(maxRiskPerTrade,entry,stopLossPrice),entry,5,stopLossPrice,takeProfitPrice,NULL,MN);
      
      if (OrderID < 0) Alert("order rejected. Order error: " + GetLastError());
      break;    
    }}}
   
for(int i = OrdersTotal()-1;i>=0;i--)
 { 
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
      if(OrderType() == OP_BUY && OrderMagicNumber() == MN && ChartSymbol() == Symbol())
      {
        while (isNewBar() == true)
         {
             bool res = OrderClose(OrderTicket(),OrderLots(),Bid,5);
      
             if (res != true)
              {
               int err = GetLastError(); Alert("LastError = ",err);
              }
      break;
      }
 }
   else if(OrderType() == OP_SELL && OrderMagicNumber() == MN && ChartSymbol() == Symbol())
     {
      while (isNewBar() == true)
         {
            bool res = OrderClose(OrderTicket(),OrderLots(),Ask,5);
      
             if (res != true)
              {
               int err = GetLastError(); Alert("LastError = ",err);
              }
      break;
      }
   }
    }}
    
      if (!CheckIfOpenOrdersByMagicNumber(MN))
     {
      while (isNewBar() == true)
      {
       if (Low[1] < Low[2] && Close[1] > Close[2]) //reversal params
       {
         Alert("Going long. Reversal Bar.");
      
      double stopLossPrice = Low[1] - Point;
      double takeProfitPrice = 0;
      double stoplevel = MarketInfo(NULL, MODE_STOPLEVEL)*GetPipValue();
      double entry = Ask;
      if (MathAbs(entry - stopLossPrice) < stoplevel)
      {entry = entry + (stoplevel -MathAbs(entry-stopLossPrice));}
      
      int OrderID = OrderSend(NULL,OP_BUY,lotsize(maxRiskPerTrade,entry,stopLossPrice),entry,5,stopLossPrice,takeProfitPrice,NULL,MN);
      
      if (OrderID < 0) Alert("order rejected. Order error: " + GetLastError());
      break;}}
      
      for(int i = OrdersTotal()-1;i>=0;i--)
 { 
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
      if(OrderType() == OP_BUY && OrderMagicNumber() == MN && ChartSymbol() == Symbol())
      {
        while (isNewBar() == true)
         {
             bool res = OrderClose(OrderTicket(),OrderLots(),Bid,5);
      
             if (res != true)
              {
               int err = GetLastError(); Alert("LastError = ",err);
              }
      break;
      }
 }
   else if(OrderType() == OP_SELL && OrderMagicNumber() == MN && ChartSymbol() == Symbol())
     {
      while (isNewBar() == true)
         {
            bool res = OrderClose(OrderTicket(),OrderLots(),Ask,5);
      
             if (res != true)
              {
               int err = GetLastError(); Alert("LastError = ",err);
              }
      break;
      }
   }
    }}}}
  

Hello, I am having issues when putting this into the backtester. When i run this EA without the reversal bar params(high[1] >high[2]etc.) and put a simple buy order in its place, the EA exits as it should at the open tick of a new bar. Why is it not working with the simple reversal params?? When i backtest it only recognizes 2 trades from the 9/28-10/28(2020) daily timeframe. there are at least 5 trades to take. the attachment below shows the trades it took. since those 2 trades in the backtest did close, it should have recognized the other possible trades. How can i correct this? And thank you for any help, it is much appreciated!! i have been spending a lot of time on thi and can't seem to crack it. 

 
   while (isNewBar() == true)
  1. For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
              New candle - MQL4 programming forum #3 2014.04.04

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum 2011.05.06

  2. Drop your loop. Return and wait for the next tick.
Reason: