How to count number of opened orders in mql5

 

Hi i used to count number of open orders using OrdersTotal but in mql5 the code is not working well. Here is my mql4 code that now doesnt work in mql5


if(OrdersTotal()>0){
  for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          if(OrderMagicNumber()==0001) {int halt1=1;}
          if(OrderMagicNumber()==0002) {int halt2=1;}
          if(OrderMagicNumber()==0003) {int halt3=1;}
          if(OrderMagicNumber()==0004) {int halt4=1;}
          if(OrderMagicNumber()==0005) {int halt5=1;}
        }
     }

}

if(halt1!=1){ //do something }


How can i implement such a script in mql5?

Documentation on MQL5: Trade Functions / OrdersTotal
  • www.mql5.com
Trade Functions / OrdersTotal - Documentation on MQL5
 
How to use the OrdersTotal() correctly?
  • www.mql5.com
In my demo account, I always get "0" when I use the function to get the total orders of the account.