Advertisement IC Markets

Server time, local time, UTC: getting EA time filters right

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 976
Joined: Sun Oct 18, 2026 12:25 pm

Server time, local time, UTC: getting EA time filters right

Post by FXS London Scalper »

Time filters in EAs are a common source of bugs. "Trade only between 08:00 and 11:00 London" sounds simple until clocks change.

The three clocks:
  • Server time: the broker's time, often GMT+2 or GMT+3 to align daily candles with New York close.
  • Local time: the VPS or PC clock.
  • UTC: the reference everything can be converted to.
Problems:
  • Brokers change server time for daylight saving, usually on the US schedule.
  • London changes on a different date from New York, so during the daylight-saving mismatch weeks the offset between them changes.
  • Hard-coded server hours break twice a year.
A safer approach: work in UTC internally (TimeGMT in MQL5), and convert to London time with an explicit daylight-saving rule. Check the conversion against a known event, for example a 07:00 London data release, on both sides of each clock change.

A test: run the EA's time filter function for dates in March, April, October and November, and print the London time it calculates.

How do you handle time zones in your EAs?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Server time, local time, UTC: getting EA time filters right

Post by Shadow Trader »

The daylight-saving mismatch weeks catch out so many EAs, and the nasty part is that they're only a few weeks a year, so a bug can sit there unnoticed for months and then cost money twice a year. A backtest over several years will include those weeks, but they're such a small share of the sample that the effect hardly shows in the overall numbers.

Working in UTC internally is the right foundation. The other thing I'd suggest is to write the conversion as its own small function and test it against a list of known dates and times. For example, take the last Sunday of March and October for Europe, and the second Sunday of March and first Sunday of November for the US, and check that the function returns the right London time for a few hours either side of each change. That takes half an hour and removes a whole category of problems.

It's also worth being careful about which clock the broker's history uses in the strategy tester. If the broker shifts server time for US daylight saving, the historical data is usually stored in server time, so a filter written in server hours might look right in testing and still be wrong in live trading during the mismatch weeks, or the other way round.

Finally, logging the computed London time alongside each decision, as suggested in the order-logging thread, makes it easy to spot. If the log shows the EA thinking it's 08:00 when it's actually 07:00, you see it straight away rather than wondering why the open looked different.
Amanhasnoname
Posts: 2060
Joined: Fri Oct 30, 2026 9:45 am

Re: Server time, local time, UTC: getting EA time filters right

Post by Amanhasnoname »

Converting everything to UTC first and only then to London time is the cleanest structure, and the one detail that makes it robust is keeping the daylight-saving rule in a single function that every filter calls. If the session window, the news blackout and the end-of-day close each do their own arithmetic, one of them will eventually disagree with the others. Pass in a UTC timestamp, return London time, and test that one function hard.

Be careful with TimeGMT in the strategy tester, because it does not return the historical UTC of each bar there; it simply follows the simulated server time. That means a filter which looks perfect live can be shifted by an hour or two in backtests. A common workaround is to derive the server offset from a known broker rule for each date, or to store a small table of offsets, and use it in both live and testing.

Worth checking as well is the Sunday open and the first bar after each clock change, since brokers sometimes shift their server time on the US date while the candle history keeps the old offset. Print the calculated London time on every trade for a week either side of each change and compare it with a reliable world clock.
Post Reply