Multi-symbol EA - For loop gets ignored almost completely

 

Hello MQL5 forum I have a problem with my code. Hope someone can help.

When I run it through the debugger, I can see that the only line that gets executed in the for loop is the first line. The EA then ignores 'if(PositionGetSymbol(i) == SymbolOne){' and the rest of the first loop. It's a similar case for the second loop, where 'if(OrderGetString(ORDER_SYMBOL) == SymbolOne){' and the rest of the loop gets ignored. 

input int magicNumberS1LongOne = 11100;
input int magicNumberS1ShortOne = 12100;
input int magicNumberS2LongOne = 21100;
input int magicNumberS2ShortOne = 22100;

string SymbolOne = "AUDUSD.pro";

   double currentSlOne = 0;
   double currentPosUnitOne = 0;

void OnTick(){

   // Create integer variable for total long and short positions.
   int totalPositionsOne = 0;
   int totalPositionsLongOne = 0;
   int totalPositionsShortOne = 0; 
    
   //Create double variable for highest opening price for long positions and lowest opening price for short positions
   double highestAskOne = 0.0;
   double lowestBidOne = 1000000.0;
   
   // Use for loop to find total amount of long and short positions. 
   // The highest long positions and lowest short positions are also found.
   // Current Position Unit SL is set. 
   for(int i=PositionsTotal() - 1; i >= 0; i--){
      if(PositionGetSymbol(i) == SymbolOne){
         if(PositionsTotal() > 0){
            totalPositionsOne++;
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY){
               totalPositionsLongOne++;
               if(PositionGetInteger(POSITION_MAGIC) == magicNumberS1LongOne){
                  s1LongBreakoutOne = 1;
               }else if(PositionGetInteger(POSITION_MAGIC) == magicNumberS2LongOne){
                  s2LongBreakoutOne = 1;
               }
               double posAskPriceOne = PositionGetDouble(POSITION_PRICE_OPEN);
               if(posAskPriceOne >= highestAskOne){
                  highestAskOne = posAskPriceOne;
                  currentSlOne = PositionGetDouble(POSITION_SL);
                  currentPosUnitOne = NormalizeDouble(((highestAskOne - currentSlOne) / 2), 5);
                  
               }
            }else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL){
               totalPositionsShortOne++;
               if(PositionGetInteger(POSITION_MAGIC) == magicNumberS1ShortOne){
                  s1ShortBreakoutOne = 1;
               }else if(PositionGetInteger(POSITION_MAGIC) == magicNumberS2ShortOne){
                  s2ShortBreakoutOne = 1;
               }
               double posBidPriceOne = PositionGetDouble(POSITION_PRICE_OPEN);
               if(posBidPriceOne <= lowestBidOne){
                  lowestBidOne = posBidPriceOne;
                  currentSlOne = PositionGetDouble(POSITION_SL);
                  currentPosUnitOne = NormalizeDouble(((currentSlOne - lowestBidOne) / 2), 5);
               }
            }   
         }else if(PositionsTotal() == 0){
            s1LongBreakoutOne = 0;
            s2LongBreakoutOne = 0;
            s1ShortBreakoutOne = 0;
            s2ShortBreakoutOne = 0;
         }
      }
   }   
   
   // Create integer variable for total long and short orders
   int totalOrdersOne = 0;
   int totalOrdersLongOne = 0;
   int totalOrdersShortOne = 0;
   
   //Create double variable for highest opening price for long positions and lowest opening price for short positions
   double orderHighestAskOne = 0.0;
   double orderLowestBidOne = 1000000.0;
   
   double currentSlOneLongOrder = 0;
   double currentLongOrderUnitOne = 0;
   
   double currentSlOneShortOrder = 0;
   double currentShortOrderUnitOne = 0;
   
   // Use for loop to find total amount of long and short orders.
   for(int i = OrdersTotal() - 1; i >= 0; i--){
      if(OrderGetString(ORDER_SYMBOL) == SymbolOne){
         totalOrdersOne++;
         if(OrderGetTicket(ORDER_TYPE) == ORDER_TYPE_BUY_STOP){
            totalOrdersLongOne++;
            double orderAskPriceOne = OrderGetDouble(ORDER_PRICE_OPEN);
            if(orderAskPriceOne >= orderHighestAskOne){
               orderHighestAskOne = orderAskPriceOne;
               currentSlOneLongOrder = OrderGetDouble(ORDER_SL);
               currentLongOrderUnitOne = NormalizeDouble(((orderHighestAskOne - currentSlOneLongOrder) / 2), 5);
            }
         }
         if(OrderGetTicket(ORDER_TYPE) == ORDER_TYPE_SELL_STOP){
            totalOrdersShortOne++;
            double orderBidPriceOne = OrderGetDouble(ORDER_PRICE_OPEN);
            if(orderBidPriceOne <= orderLowestBidOne){
               orderLowestBidOne = orderBidPriceOne;
               currentSlOneShortOrder = OrderGetDouble(ORDER_SL);
               currentShortOrderUnitOne = NormalizeDouble(((orderLowestBidOne - currentSlOneShortOrder) / 2), 5);
            }
         }
      }
   }
   
   // Create integer variable for total long and short positions and orders.
   int totalPositionsAndOrdersLongOne = totalPositionsLongOne + totalOrdersLongOne;
   int totalPositionsAndOrdersShortOne = totalPositionsShortOne + totalOrdersShortOne;

}