MT5 OrdersTotals() for active pending orders does't works in backtest strategy

 

Hello,

i have a problem with pendings orders in backtest, this is my code

int OrdiniApertiPending()
  {
   ulong    ticket;
   int    Magic;
   int Totale=0; 
   string type;
   int  iOrders=OrdersTotal(), i;
   for(i=iOrders-1; i>=0; i--)
     {
      ticket=OrderGetTicket(i); 
      if(ticket!=0)// if the order was successfully copied into the cache, work with it
        { 
         Magic = OrderGetInteger(ORDER_MAGIC);
         int tipo = OrderGetInteger(ORDER_TYPE); 
         if(Magic == Period() && tipo  >0 && Symbol() ==  OrderGetString(ORDER_SYMBOL))
           {
            Totale= Totale +1; 
          }
        }  
     } 
    
   return Totale;
  }


OrdersTotal() return always 0 even if there is some pending orders active as you can see below:




how i can solved this problem?

Thanks


Davide

 
termi_80 :

Hello,

i have a problem with pendings orders in backtest , this is my code

Now describe in detail WHAT YOU DO: WHERE do you run this code - in the strategy tester or in the terminal?

 
https://www.mql5.com/en/code/7607

try that
 
Vladimir Karputov:

Now describe in detail WHAT YOU DO: WHERE do you run this code - in the strategy tester or in the terminal?

I use strategy tester and i doesn't work.. Always return 0 as you can see in the image, tomorow 
i Will post pics in real account and so you can see the difference
 
termi_80:

Hello,

i have a problem with pendings orders in backtest, this is my code


OrdersTotal() return always 0 even if there is some pending orders active as you can see below:




how i can solved this problem?

Thanks


Davide

No idea how you are doing that. OrdersTotal() works fine in the Strategy Tester, just checked.

+ +

 
Davide:
I use strategy tester and i doesn't work.. Always return 0 as you can see in the image, tomorow 
i Will post pics in real account and so you can see the difference
You should avoid using 2 accounts, you are risking a ban.
 
Alain Verleyen :

I seem to understand what the user is doing: he wants to access pending orders on a real account from the strategy tester (launching debugging on historical data).

 
Vladimir Karputov:

I seem to understand what the user is doing: he wants to access pending orders on a real account from the strategy tester (launching debugging on historical data).

i create expert advisor, i tested in stategy tester and in strategy tester orderstotal() return me always 0

 
termi_80 :

i create expert advisor, i tested in stategy tester and in strategy tester orderstotal() return me always 0

Where is your full MQL5 code? Without code, it's not clear what you are doing.

From the tester in the "debug on history" mode, there is NO access to a real account.

 

i try to explain better:

as you can see into strategy tester visualition (from 01/01/2019 to 2019.12.12)  pics my expert has opened on 02/01/2019 at 11:00:06:

1 pending order ticket 3

1 position ticket 2


i lunched strategy tester straight from metaeditor with blue botton  



when i called OrdersTotal() (iOrders) return 0 even if ticket 3 is pending order (buy limit)



-------------------------------------------------------------------------------------------------------


after i do another test on real account i made a stupid script:



this is the result :



OrdersTotal() works without problem

i hope to have been clear.


I use mt5 of icmarkets latest build


Thanks Davide

 
termi_80:


Forum on trading, automated trading systems and testing trading strategies

MT5 OrdersTotals() for active pending orders does't works in backtest strategy

Vladimir Karputov, 2019.12.23 11:26

Where is your full MQL5 code? Without code, it's not clear what you are doing.

From the tester in the "debug on history" mode, there is NO access to a real account.