How are people handling this?
TimeGMT library for the strategy tester
amrali, 2024.02.22 01:54
Static class to fix the TimeGMT() function during testing in the strategy tester.First a correction, because it decides which way the window has to move. On a +2/+3 server that follows New York, 08:00 London is 10:00 server time in summer and in winter. In the gap week the server is still on +3 while London is already back on GMT, so the open lands at 11:00, one hour later. March gives the same direction, not the reverse, and that gap is longer than a week, from the second Sunday of March to the last Sunday of March, so two or three weeks depending on the year.
For reproducibility I stopped asking the terminal for the offset. On such a server the offset is a function of the date, +3 while US daylight saving is active and +2 otherwise, and the switch dates follow fixed rules (US second Sunday of March and first Sunday of November, EU last Sunday of March and October). I compute them from the date itself, so the same bar gets the same session window in a backtest and live, and TimeGMT never enters the calculation. What I would check once per broker is that the server really switches with New York.
Example codes for MT5 and MT4:
Vinicius Pereira De Oliveira, 2026.06.18 22:36
Asian Range Breakout day-trading EA. Multi-symbol, M15/M30/H1. Places pending stop orders during the London session outside the pre-London Asian range, using PSAR + MACD + Stochastic signals, with automatic London/NY DST handling, structural stops, trailing and break-even.Vinicius Pereira De Oliveira, 2017.01.25 09:12
Asian Range Breakout day-trading EA. Multi-symbol, M15/M30/H1. Places pending stop orders during the London session outside the pre-London Asian range, using PSAR + MACD + Stochastic signals, with automatic London/NY DST handling, structural stops, trailing and break-even.Yeah, that tester behaviour is documented, TimeGMT() just returns the simulated server time in a backtest, so option 2 can't rely on it there. What I'd do is compute the server offset yourself from the date: these brokers follow US DST (second Sunday of March to first Sunday of November), so it's +3 inside that window and +2 outside. UK DST is last Sunday of March to last Sunday of October, so London 08:00 in server time is 8 - ukOffset + serverOffset. Same function live and in the tester, so results stay reproducible.
Most brokers on GMT+2/+3 server time follow the US DST schedule so the daily close stays at 17:00 New York. Europe ends DST on 25 October and the US on 1 November, so for that week London opens one hour earlier in server time than usual. The same thing happens in March in reverse.
For EAs that build an Asian range from fixed server hours and trade the London breakout, the range window and the London open are misaligned for about a week, twice a year.
How are people handling this?
1. Keep fixed server hours and accept that week
2. Work out session times from GMT (TimeTradeServer() minus TimeGMT()) plus an internal DST table
3. Skip trading during the mismatch weeks
The catch with option 2: in the Strategy Tester, TimeGMT() returns the simulated server time, so the offset logic behaves differently in backtests than live unless the offset is hard-coded by date. Has anyone found a clean way to keep this reproducible in the tester?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Most brokers on GMT+2/+3 server time follow the US DST schedule so the daily close stays at 17:00 New York. Europe ends DST on 25 October and the US on 1 November, so for that week London opens one hour earlier in server time than usual. The same thing happens in March in reverse.
For EAs that build an Asian range from fixed server hours and trade the London breakout, the range window and the London open are misaligned for about a week, twice a year.
How are people handling this?
1. Keep fixed server hours and accept that week
2. Work out session times from GMT (TimeTradeServer() minus TimeGMT()) plus an internal DST table
3. Skip trading during the mismatch weeks
The catch with option 2: in the Strategy Tester, TimeGMT() returns the simulated server time, so the offset logic behaves differently in backtests than live unless the offset is hard-coded by date. Has anyone found a clean way to keep this reproducible in the tester?