Download MetaTrader 5

How to count number of opened orders in mql5

To add comments, please log in or register
Tonny Obare
Tonny Obare 2011.07.10 16:40 

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

  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
Trade Functions / OrdersTotal - Documentation on MQL5
Alexander Piechotta
Alexander Piechotta 2011.07.10 21:20  
How to use the OrdersTotal() correctly?
In my demo account, I always get "0" when I use the function to get the total orders of the account.
To add comments, please log in or register