OrdersTotal() not updating when I place an order!

Macintyre Sunde  

I am trying to backtest an expert advisor and limit the number of pending orders to 1. However, when I place an order using the CTrade class, OrdersTotal() is still returning 0. I found this forum post but to no avail. 

Here's the function I'm running and the output:

void Buy() {
   double sl = iOpen(Symbol(), Period(), 2);
   double ocur = iOpen(Symbol(), Period(), 0);
   double tp = (ocur - sl) * 2 + ocur;
   if (tp < sl || OrdersTotal() > 1) {
      return;
   }
   trade.Buy(Volume, Symbol(), symbol.Ask(), sl, tp);
   Print(CountOrders());
   DebugBreak();
}
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: