Build notes
The MQL5 Economic Calendar API Gives You a Time With No Time Zone
Batdorj Byambadorj · · 6 min read
MetaTrader 5 ships an economic calendar and MQL5 lets you read it: CalendarValueHistory hands back MqlCalendarValue records, each with a time.
A time in what zone? Not server time, not UTC, not local time — the field is a datetime and nothing in the API says what it is measured against.
For a tool that warns a trader before a release, that gap is the whole problem. An hour early is not a small bug: someone who trusted the alert is away from the screen when the number prints. So I measured it.
What the offset actually was
A probe read one weekly US release across six months of history and compared each record's raw time with the schedule that release actually keeps. The same log recorded the broker's server time, taken from hourly bar opens.
| Period | Server time | Calendar |
|---|---|---|
| 8 June – 26 October | UTC+3 | UTC+2 |
| 2 November – 9 November | UTC+2 | UTC+2 |
Forty-six records, six months, and the calendar's offset never moved once — not for the European clock change in late October, not for the American one at the start of November.
Two things fall out of that table. The calendar is not on server time: for most of the sample the two differed by an hour, and they agreed at the end only because the server moved. The calendar observes daylight saving nowhere: it sat two hours ahead of UTC through both changeovers.
That is enough to convert a time. It is not enough to hardcode one: this is measured behaviour, not a documented contract. If MetaQuotes changes it, every alert built on a fixed offset shifts by an hour, silently.
Calibrating instead
So the EA does not store an offset. It works one out while it runs, from a release whose schedule is known and fixed.
The anchor is a weekly US release published at 8:30 Eastern. The EA takes the last four occurrences, compares each record's time-of-day with 8:30 Eastern expressed in UTC, and derives that conversion from the US daylight-saving rule rather than a stored date table. Times of day rather than timestamps, because a US holiday moves the release to another weekday but leaves the hour alone.
Then it decides whether to believe the answer. All four offsets must agree within a few minutes, and the result must be a whole number of hours. If either test fails the EA marks the state bad and will not fire a news alert at all — a wrong time is worse than no alert, because the trader does not know it is wrong.
It calibrates again every hour and once more just before a news alert is due, so the offset in force at firing time comes from an anchor less than a week old. If the calendar ever does start following daylight saving, the error is bounded by a week instead of a season.
A second anchor, a monthly US release also at 8:30 Eastern, covers the weeks the first is missing. If both are present and disagree, that is not a reason to pick one. It is a reason to refuse.
The mistake that made this necessary
The first probe was handed a list of US releases with the instruction that they all publish at 8:30 Eastern. One of them, a monthly payroll estimate, publishes at 8:15, and the summary duly reported an offset of UTC+1.75 — nonsense, which is the only reason it was caught. A fifteen-minute error hidden inside a plausible whole-hour answer would have passed.
That failure became a test: the probe is now fed the 8:15 release on purpose and has to reject it. A calibration routine that cannot refuse a bad anchor is not one.
Checking the clock the calendar is converted against
Converting to UTC is pointless if the PC's own clock is wrong, and TimeGMT() comes from the PC.
The only independent source inside the terminal is tick time, but ticks stop at the weekend, so an absolute comparison would report a fault every Saturday. Instead the EA compares how much each clock advances over a sixty-second window; a constant bias cancels out in the difference. Then it rounds TimeCurrent() − TimeGMT() to the nearest whole hour and checks the remainder: within five minutes is fine, beyond it firing is blocked. Measured on a live terminal, the remainder was one second.
One hole stays open: a PC clock wrong by exactly a whole number of hours leaves a remainder of zero and passes. Nothing inside MT5 catches that — the interface does, because event times are shown with their zone spelled out.
Four more things the measuring turned up
Reading the calendar is cheap. Thirty days ahead, every currency: 1,161 records in 2.4 ms; one currency, 308 records in 1.05 ms. An earlier design limited reads on the assumption that the call was expensive. It was not.
The data is the same at every broker. Three terminals, three brokers, three builds returned identical event counts and change ids: MetaQuotes distributes one dataset. A demo account was enough, and nobody had to open the Calendar tab first.
Never store the event's name. Names can be localised. The stable key is the event id, byte-identical across all three terminals; the name is read fresh each time it is displayed.
Not every event has a usable time. Of 63 high-importance events in the next thirty days, four were not marked as having a date and time — including one central bank rate decision, which certainly has one. "Fifteen minutes before" is meaningless for those, so they are excluded rather than guessed at.
If you build on the MQL5 calendar
- Calibrate at runtime against a release whose schedule you know, comparing times of day rather than timestamps. Do not trust an offset you read somewhere, this article included.
- Demand a whole-hour answer from several samples. If you do not get one, refuse to fire and say why.
- Test with an anchor you know is wrong, and make sure your code rejects it.
- Check the PC clock by comparing rates of change, not absolute values.
- Key on the event id. Read the name for display only.
This runs inside the trader's own terminal, which is the same reason the alert engine does: the calendar is local data, and it stays local. The EA is free to download.
Measured in November 2026 across three brokers' MetaTrader 5 terminals. The offset is one platform's behaviour at one point in time, not a documented guarantee.
Batdorj Byambadorj
Batdorj Byambadorj has been trading forex for his own account since 2007, mostly gold. He is the sole developer of fx-alert and writes every article on this site himself.