Backtesting weird market error help?

 

I have been currently testing my EA with difffernt brokers to gather data. However I got this weird error: [market closed]

With metatrader demo, it was working fine.

Below was for Oanda demo, but I had the same with Vantage demo as well. Build version 3550. For extra info I did create the demo acocunts and tested soon after.

Happens to other pairs as well, for the entire duration of the test(multiple years not just 2011), so it shouldn't be because of off market time. 


2023.02.15 14:23:28.305 2011.01.10 00:00:00   failed market buy 0.5 USDJPY sl: 82.163 [Market closed]

2023.02.15 14:23:28.305 2011.01.10 00:00:00   CTrade::OrderSend: market buy 0.50 USDJPY sl: 82.163 [market closed]


I saw other posts but wasnt able to get a clear answer, does anyone know what's wrong, as how can the market be closed when im just back testing data?

 

That means that this trade couldn't be opened at 00:00:00 because the market is closed in all GMT+2 brokers (GMT+3 in the summer) at that time.

If you check the strategy tester journal you will see that the trade is finally opened a few seconds or a couple of minutes later, if your EA keeps trying.

 
Eleni Anna Branou #:

That means that this trade couldn't be opened at 00:00:00 because the market is closed in all GMT+2 brokers (GMT+3 in the summer) at that time.

If you check the strategy tester journal you will see that the trade is finally opened a few seconds or a couple of minutes later, if your EA keeps trying.

Unfortunatly it did not go through after as the ea only sends one trade order and not multiple if it fails the trade.

this was the rest:(this was for a different pair, but same issue)

2023.02.16 10:33:09.121 2011.01.11 00:00:00   failed market buy 0.23 GBPUSD sl: 1.53533 tp: 1.57185 [Market closed]

2023.02.16 10:33:09.121 2011.01.11 00:00:00   CTrade::OrderSend: market buy 0.23 GBPUSD sl: 1.53533 tp: 1.57185 [market closed]

2023.02.16 10:33:09.121 2011.01.11 00:00:00   Trade Processed For GBPUSD OrderType 0 Lot Size 0.23 Ticket 0

.....

I did try in metaquotes again to double check and the trades went through fine with no issues.

However would it have to do with my code in the onTick() function?

the below code in in the onTick() and does it just once as long its a new day

bool isNewCandle = false;
//this should essentially just take trades/check info once per day
    if(TimeLastTickProcessed!=iTime(Symbol(),Period(),0))
    {
        isNewCandle = true; //so there is a new candle
        
        TimeLastTickProcessed = iTime(Symbol(),Period(),0);
    }
    
    if(isNewCandle == true)
    {
 
dsadsa322 #: However would it have to do with my code in the onTick() function?

No, it is because the market is closed for trading at the time. It is as simple as that.

You can only trade when it is open. Your EA needs to check and wait until it is open again and then reevaluate the conditions to decide if it should place a trade or not.

EDIT: Every day, at the end of the day, on many assets, the market closes for retail trading during some time for swaps to be calculated and applied.

 
Fernando Carreiro #:

No, it is because the market is closed for trading at the time. It is as simple as that.

You can only trade when it is open. Your EA needs to check and wait until it is open again and then reevaluate the conditions to decide if it should place a trade or not.

EDIT: Every day, at the end of the day, on many assets, the market closes for retail trading during some time for swaps to be calculated and applied.

Sure, ill modify my EA to take trades a little bit after and run some tests till it takes the trades. Im assuming metaquotes is running fine because of the different broker times then.

Just confused as to why backtesting needed the market times to be open, but I suppose it is testing real market environments and you need to be during when market is open.

Thanks for the info.

 
dsadsa322 #:

Sure, ill modify my EA to take trades a little bit after and run some tests till it takes the trades. Im assuming metaquotes is running fine because of the different broker times then.

Just confused as to why backtesting needed the market times to be open, but I suppose it is testing real market environments and you need to be during when market is open.

Thanks for the info.

If you choose (Every tick) simulation then it passes the closed market automatically and you can reach the end of backtest period.

I really dont know why but it works for me.

 
@Yashar Seyyedin #: If you choose (Every tick) simulation then it passes the closed market automatically and you can reach the end of backtest period. I really dont know why but it works for me.

That is incorrect. The market can be closed for retail trading but still have quotes due to trading at the institutional level, and this is correctly simulated in the Strategy Tester.

This depends on the symbol and the type of account. Here is an example ...

 
Fernando Carreiro #:

That is incorrect. The market can be closed for retail trading but still have quotes due to trading at the institutional level, and this is correctly simulated in the Strategy Tester.

This depends on the symbol and the type of account. Here is an example ...

Thanks for heads up.
Reason: