Calculating open orders

 

Hey guys,

I have written a for loop that returns whether there are any open orders, however, it returns, on occasion, no open orders even when there are open orders. Is there any way to make this more accurate? Below is my code, any help is appreciated.

int OpenOrdersThisPair(string pair)
  {
   int total=0;
   
   for(int b=OrdersTotal()-1; b>0; b--)
    {
     if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()==pair) total++;
    }
     return(total);
  }
 
for(int b=OrdersTotal()-1; b>=0; b--)
You are not checking the order with the index 0
 
GumRai:
You are not checking the order with the index 0
Wow! Haha, thanks! I was so flabbergasted by it. Thank you again. 
Reason: