OrdersTotal() not working for pending orders in backtester

 

One more issue with pending orders and backtester...

I put 2 pending orders and then OrdersTotal() = 0

when 1 of the pending orders is opened OrdersTotal() = 1.

According to the MQL5 reference OrdersTotal() should give the number of all orders including pending orders not only the open positions, isn't it? Positio0nsTotal() is for open positions.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
jlpi:

One more issue with pending orders and backtester...

I put 2 pending orders and then OrdersTotal() = 0

when 1 of the pending orders is opened OrdersTotal() = 1.

According to the MQL5 reference OrdersTotal() should give the number of all orders including pending orders not only the open positions, isn't it? Positio0nsTotal() is for open positions.

Hello, 

I think its working. Below is the result of a test I just carried out, check it and see that its working...

 

 

You can also try it yourself.

add the function below to your code

//+------------------------------------------------------------------+
//|  Count Total Orders for this expert/symbol                             |
//+------------------------------------------------------------------+
int CountOrders()
{
   int mark=0;
   
   for (int i=OrdersTotal(); i>0; i--)
   {
      if (myorder.Select(OrderGetTicket(i)))
      {
          if (myorder.Magic()==EA_Magic && myorder.Symbol()==_Symbol) mark++;
          Alert("Order ", i ," is ",myorder.TypeDescription(), " with ticket No: ", myorder.Ticket());
      }
   }
   return(mark);
}

Somewhere at the upper part of your code, before your input parameters section add the following lines

//--- The OrderInfo Class
#include <Trade\OrderInfo.mqh>

//--- The OrderInfo Class Object
COrderInfo myorder;

The somewhere in your code, in the OnTick() section, add the following code after you have checked for a new bar so that it does not run on every Tick.

 if (CountOrders()>1) 
     {
        Alert("Total Pending Orders now is :", CountOrders() ,"!!");
     }

Compile and test your code again and see the journal for whatever info is displayed. 

Reason: