Download MetaTrader 5

Calculating open orders

To add comments, please log in or register
DeanDeV
330
DeanDeV  

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);
  }
Keith Watford
Moderator
10569
Keith Watford  
for(int b=OrdersTotal()-1; b>=0; b--)
You are not checking the order with the index 0
DeanDeV
330
DeanDeV  
GumRai:
You are not checking the order with the index 0
Wow! Haha, thanks! I was so flabbergasted by it. Thank you again. 
To add comments, please log in or register