Broker GMT offset in the Strategy Tester: TimeGMT() is server time there, so estimate it from the weekly close (code)
Not sure if your code is correct considering there are tons of nuances.
I do not mean to hijack your thread but user amrali has made a few related libraries:
- Determine Broker's Daylight (DST) schedule
- Local Timezones and Local Session Hours
- TimeGMT library for the strategy tester
It is worth while reading the respective threads. A true rabbit hole.
- 2024.03.14
- www.mql5.com
Thanks for the pointers, Enrique, and no hijack at all. amrali's libraries are the thorough route, and worth reading for anyone who needs the full DST picture.
The snippet above only tries to do one thing: estimate the broker's offset inside the Strategy Tester from the weekend gap, recalculated once a day so that a long backtest follows the summer and winter time of each period. Where that cannot work (no weekend gap, unusual server times, half-hour offsets) it falls back to the New York close convention, and a manual input always wins.
If anyone has a broker where the estimate comes out wrong, I would like to hear which one.
Forum on trading, automated trading systems and testing trading strategies
Daily loss limit from server midnight, including floating P/L: how do you measure it in an EA?
Alain Verleyen, 2026.11.18 16:53
Please add your code using the correct editor tool for source code. I have edited your message.
Any EA that works with fixed session times (Tokyo fixing, London open, New York close) needs the broker's GMT offset, the difference between server time and UTC. Live, TimeTradeServer() - TimeGMT() gives it. In the Strategy Tester it does not: the documentation says that during testing TimeGMT() is always equal to TimeTradeServer(), the simulated server time. So a backtest that uses TimeGMT() silently runs every session at the wrong hour, and summer and winter time make it worse.
What I use instead is the weekly close. FX (and gold and most CFDs) closes on Friday at 17:00 New York time, so the last bar before the weekend gap tells you where 17:00 New York sits in server time. For each weekend of the last 45 days the code finds the whole-hour offset that puts that close at 17:00 New York, with US daylight saving time applied, and takes the most frequent one. That makes it robust against a short Friday or a holiday weekend.
Notes:
If your broker's weekly close does not land at 17:00 New York, I would be interested to hear which one it is.