How to use the OrdersTotal() correctly?

 

I tried many times to check OrdersTotal(), but I found it did not work.

In my demo account, I always get "0" when I use the function to get the total orders of the account.

So what's the problem? How to use the function correctly?

Any information will be appreciated. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Account Properties - Documentation on MQL5
 
futurefan:

I tried many times to check OrdersTotal(), but I found it did not work.

In my demo account, I always get "0" when I use the function to get the total orders of the account.

So what's the problem? How to use the function correctly?

Any information will be appreciated. 

In MT-5, OrdersTotal(0) returns number of pending orders, where  OrdersTotal() in MT-4 returned number of both market and pending orders.

Try using PositionsTotal() for number of open positions.

To find open position for specific Symbol(), try this.

int OpenPos()
{
   int total=PositionsTotal();
   int count=0;
   for (int cnt=0; cnt<=total; cnt++) 
      {
         if(PositionSelect(Symbol()) )
            {
               if(PositionGetInteger(POSITION_MAGIC)==MagicNumber)
                  {
                     count++; 
                  }
            }
      }

    return(count);
}
OrdersTotal - MQL4 Documentation
  • docs.mql4.com
OrdersTotal - MQL4 Documentation
 
wackena:

In MT-5, OrdersTotal(0) returns number of pending orders, where  OrdersTotal() in MT-4 returned number of both market and pending orders.

Try using PositionsTotal() for number of open positions.

To find open position for specific Symbol(), try this.



 

I got it. Thanks a lot. 

 
int OpenPos()
{
   int total=PositionsTotal();
   int count=0;
   for (int cnt=0; cnt<=total-1; cnt++) 
      {
         if(PositionSelect(Symbol()) )
            {
               if(PositionGetInteger(POSITION_MAGIC)==MagicNumber)
                  {
                     count++; 
                  }
            }
      }

    return(count);
}
Reason: