Test Abruptly Ends with "order canceled due end of test" - Can anybody help?

 

Hi,


I am trying to backtest a strategy with a custom symbol, I have imported tick data from a date range and the data displays just fine in the chart.

The strategy involves simply placing an order at 8:30AM.

However there is a point where one pending order at 8:30AM on 2022.08.17 gets canceled (at 2022.08.23 23:59:56 ) and the test is abruptly ended, although there is more tick data and the date range on the Settings tab is set up to 2022.09.30, but the backtest simply stops. 

I have also set an expiration of 15mins after the order so if the price is not reached it should simply keep going through the test, but still no good.



Log Lines:


2022.10.19 13:17:14.059 Core 1 2022.08.17 08:30:00   ------------------------START PLACE ORDER-------------------------

2022.10.19 13:17:14.059 Core 1 2022.08.17 08:30:00   High: 13896.8 - Low: 13866.8

2022.10.19 13:17:14.059 Core 1 2022.08.17 08:30:00   Expiration: 2022.08.17 08:45:00

2022.10.19 13:17:14.059 Core 1 2022.08.17 08:30:00   buy stop 1 GER40 at 13899.8 sl: 13856.8 tp: 13936.8 (13879.3 / 13880.3 / 13879.3)

2022.10.19 13:17:14.059 Core 1 2022.08.17 08:30:00   ------------------------END PLACE ORDER-------------------------

2022.10.19 13:17:14.059 Core 1 2022.08.23 23:59:56   order canceled due end of test [#2 buy stop 1 GER40 at 13899.8]

2022.10.19 13:17:14.059 Core 1 final balance 10000.00 GBP



Code that places the long order:

            double price_long = NormalizeDouble(high, _Digits);
            double sl_long_value = price_long - sl;
            double tp_long_value = price_long + tp;
           
            trReq.action = TRADE_ACTION_PENDING;
            trReq.type = ORDER_TYPE_BUY_STOP;
            trReq.price=price_long + GAP_OFFSET;                   
            trReq.sl=sl_long_value;           
            trReq.tp=tp_long_value;
            datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_M15);
            Print("Expiration: "+expiration);
            trReq.expiration = expiration;
            OrderSend(trReq,trRez);

Can anybody help me to figure out why the test stops abruptly?


Thank you again!


Creating and testing custom symbols in MetaTrader 5
Creating and testing custom symbols in MetaTrader 5
  • www.mql5.com
Creating custom symbols pushes the boundaries in the development of trading systems and financial market analysis. Now traders are able to plot charts and test trading strategies on an unlimited number of financial instruments.
 

Obviously when the test run ended, there was still a pending order open, which the tester then closed. There is nothing suspicious or wrong about that. That is normal.

If however, your test is ending before the expected date, then either you have set a premature end-date, or your EA is forcefully terminating the test from within the code itself, or there is corrupt data.

 
Fernando Carreiro #:

Obviously when the test run ended, there was still a pending order open, which the tester then closed. There is nothing suspicious or wrong about that. That is normal.

If however, your test is ending before the expect ed date, then either you have set a premature end-date, or your EA is forcefully terminating the test from within the code itself, or there is corrupt data.

Hi Fernando, thank you for your reply!


If I am setting an expiration date 15mins after the pending order is created, shouldnt the test continued? As above, I am setting the Expiration parameter on the order to 15mins after it was created, yet the script ends at 23:59:56. And the tick data is is just fine as it is displayed correctly, (see screenshot)


https://charts.mql5.com/34/156/ger40-m5-metaquotes-software-corp.png

 

Ok I found out myself. The issue was "type_time", which was not set to ORDER_TIME_SPECIFIED


Thank you again!