Please help - "Market closed" in Strategy Tester

Dr Matthias Hammelsbeck
765
Dr Matthias Hammelsbeck  

Hi everybody,

like always and done without any problems in previous versions of MT5 I want to test my (unmodified) EA by the strategy tester. But since I've installed MT5 build 2926 I cannot open any pending orders. I get the error messages


CP      0       16:18:13.970    Tester  DE30,H1: testing of Experts\Vibra\Vibra.ex5 from 2020.12.01 00:00 to 2021.04.20 00:00 started with inputs:
IO      0       16:18:13.970    Tester    i_Breite_Dn=500
DL      0       16:18:13.970    Tester    i_max_tp=5
JG      0       16:18:14.008    Symbols EURUSD: symbol to be synchronized
CS      0       16:18:14.008    Symbols EURUSD: symbol synchronized, 3720 bytes of symbol info received
CE      0       16:18:14.009    History EURUSD: history synchronization started
PR      0       16:18:14.136    History EURUSD: load 27 bytes of history data to synchronize in 0:00:00.000
LR      0       16:18:14.136    History EURUSD: history synchronized from 2016.01.04 to 2021.04.20
ID      2       16:18:14.949    Trades  2020.12.01 00:00:00   failed buy stop limit 0.1 DE30 at 13375.00 (13350.00) tp: 13400.00 [Market closed]
OH      0       16:18:14.949    Vibra (DE30,H1) 2020.12.01 00:00:00   CTrade::OrderSend: buy stop limit 0.10 DE30 at 13375.00 (13350.00) tp: 13400.00 [market closed]
IS      2       16:18:14.950    Trades  2020.12.01 00:00:00   failed buy limit 0.1 DE30 at 13300.00 tp: 13350.00 [Market closed]
RI      0       16:18:14.950    Vibra (DE30,H1) 2020.12.01 00:00:00   CTrade::OrderSend: buy limit 0.10 DE30 at 13300.00 tp: 13350.00 [market closed]
CP      2       16:18:14.950    Trades  2020.12.01 00:00:00   failed buy limit 0.1 DE30 at 13250.00 tp: 13300.00 [Market closed]
IH      0       16:18:14.950    Vibra (DE30,H1) 2020.12.01 00:00:00   CTrade::OrderSend: buy limit 0.10 DE30 at 13250.00 tp: 13300.00 [market closed]


I have no idea what is going on here :-(

May be a configuration issue?

I tried different brokers inclusive MetaQuotes server: no success.


Thank you very much for your answer

Sincerely

Matthias


Btw: where I can find an explanation of the meaning of the two uppercase letters at the beginning of each line?


Alain Verleyen
42187
Alain Verleyen  
The trading sessions are now checked in the Strategy Tester. You need to check it before doing trading operations.
Dr Matthias Hammelsbeck
765
Dr Matthias Hammelsbeck  
Alain Verleyen:
The trading sessions are now checked in the Strategy Tester. You need to check it before doing trading operations.

@Alain: I like to say 'Thank You' for this helpful answer.

Matthias

Joerg Hartgen
1317
Joerg Hartgen  

Concerning backtesting the Dow Jones with tick data: There is no trading session between 00:00 AM and 01:00 AM:

Trading Sessions Dow Jones


But there are ticks between 00:00 and 01:00 AM. Example:

Ticks Example Dow Jones


So there is an error "[Market Closed}" if the EA tries to open a position between 00:00 and 01:00 AM.


I think the timestamp of the tick data has different time offset than the symbol, correct?


Can you please help me to solve this? Is it possible to "shift" the time stamp of the tick data for one hour?

Fernando Carreiro
7036
Fernando Carreiro  

Joerg Hartgen: Concerning backtesting the Dow Jones with tick data: There is no trading session between 00:00 AM and 01:00 AM:

But there are ticks between 00:00 and 01:00 AM. Example:

So there is an error "[Market Closed}" if the EA tries to open a position in this period.

I think the timestamp of the tick data is in an other timezone than the symbol, correct?

Can you please help me to solve this? Is it possible to "shift" the time stamp of the tick data for one hour?

Just because there are ticks during a certain period that does not mean that a broker allows trading during that period.

Many brokers close off trading during the beginning of the day, to take care of swaps and don’t allow trading, and sometimes trading is only allowed for institutions and that is why there are still ticks during that time. Sometimes, it is a CFD or Index based on another original symbol that is still trading even though the broker has paused for swap calculations, and so there also ticks.

That is how it works on live trading, and the Strategy Tester is simply now also simulating that behaviour in the market. That is a good thing, because it makes your testing more realistic and forces you to code better handling of those situations.

Joerg Hartgen
1317
Joerg Hartgen  

@Fernando Carreiro: In my case the fact that a broker not always allows trading is a minor reason. Please have a look:

There is an interruption of the trading session of this symbol, between 23:15 (=1.) and 23:30 (=2.):

Gap in Trading Session

If you have a look at the tick data, you will see this interruption one hour before, between 22:15 (=1.) and 22:30 (=2.):

Interruption Ticks

If I want to use the strategy tester to make an accurate and realistic testing, I need to setup an offset of one hour.

But how can I do that?

Or is there an other way?

Fernando Carreiro
7036
Fernando Carreiro  

Joerg Hartgen: @Fernando Carreiro: In my case the fact that a broker not always allows trading is a minor reason. Please have a look: There is an interruption of the trading session of this symbol, between 23:15 (=1.) and 23:30 (=2.): If you have a look at the tick data, you will see this interruption one hour before, between 22:15 (=1.) and 22:30 (=2.): If I want to use the strategy tester to make an accurate and realistic testing, I need to setup an offset of one hour. But how can I do that? Or is there an other way?

You don't need to offset anything. You are over-complicating things. Just read the session trading times with "SymbolInfoSessionTrade" and don't place or manage trades during those out-of-session times.

EDIT: The session times are based on broker's server time, so you don't need to adjust anything. Just read the session times, and check against "TimeCurrent" or "TimeTradeServer" and prevent EA from trading outside of the session times.

EDIT2: Just because there was no activity an hour before is probably a coincidence and does not have to do with the session times.

Documentation on MQL5: Market Info / SymbolInfoSessionTrade
Documentation on MQL5: Market Info / SymbolInfoSessionTrade
  • www.mql5.com
SymbolInfoSessionTrade - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Joerg Hartgen
1317
Joerg Hartgen  

In my case the specified session times are not congruent with the availability of tick data. There is a one hour time differ on several days. The reason is probably daylight saving times.

If I would stop trading during the "out of session times" specified in the symbol specifications, then I would miss a lot of tick data which would lead to an inaccurate testing.

So I need to find a solution to deal with the time differ between tick data and session times specified in the symbol.

Fernando Carreiro
7036
Fernando Carreiro  
Joerg Hartgen: In my case the specified session times are not congruent with the availability of tick data. There is a one hour time differ on several days. The reason is probably daylight saving times.

If I would stop trading during the "out of session times" specified in the symbol specifications, then I would miss a lot of tick data which would lead to an inaccurate testing. So I need to find a solution to deal with the time differ between tick data and session times specified in the symbol.

You are absolutely sure of that fact?

Did you check the tick activity over many days and weeks and did it all show a gap during 22:15 and 22:30 in every case?

Did you monitor session times during the week to see if in fact the broker is preventing trades during either at 22:15-22:30 or at 23:15-23:30?

If it is the case then speak to your broker about them fixing the session times in the contract specifications. It should not be up to you to fix that and it is their responsibility to report the correct information!

Joerg Hartgen
1317
Joerg Hartgen  

To check if in my case specified session times are not congruent with the availability of tick data:

Specified Symbol Trading hours are always the same:


But the timestamps differ because of daylight saving time:



As a consequence this will lead to invalid results in strategy tester.

If there would be an option in MQL5 to programmatically set an offset in periods of daylight saving time, this would be a great solution.

Fernando Carreiro
7036
Fernando Carreiro  
Joerg Hartgen: As a consequence this will lead to invalid results in strategy tester. If there would be an option in MQL5 to programmatically set an offset in periods of daylight saving time, this would be a great solution.

Just, create a Custom Symbol based on the underlying original symbol and remove the session time gaps and run the strategy tester against the custom symbol. Then you will not have any problem with the "Market Closed" situation!