- MQL5 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| LICENSE | ||
| README.md | ||
| SessionBoxes.mq5 | ||
| SessionTime.mqh | ||
| SessionTimeCheck.mq5 | ||
SessionTime for MQL5
Convert session hours given in London, New York, Tokyo or Sydney time into broker server time, with US and EU daylight saving, including the weeks when the two rules are out of step.
The same code is published in the MQL5 CodeBase: https://www.mql5.com/en/code/79838
Why
Session hours are set in the exchange's local time, but the chart shows the broker's server time. The difference depends on the broker and changes twice a year, and the US and Europe do not change on the same day. In 2026 the US moved its clocks on 8 March and Europe on 29 March; in autumn Europe moved back on 25 October and the US on 1 November. Code that uses fixed server hours is one hour off for about four weeks a year.
Model
The broker server is modelled as UTC + a winter offset, plus one hour while the server is in its daylight-saving period (US rule, EU rule or none). With that model the library converts any zone time to server time and back.
Files
| File | Where it goes | What it is |
|---|---|---|
SessionTime.mqh |
MQL5\Include\ |
the library |
SessionTimeCheck.mq5 |
MQL5\Scripts\ |
15 hand-calculated test cases and a table of Monday session opens around each clock change |
SessionBoxes.mq5 |
MQL5\Indicators\ |
minimal indicator: one session drawn as a box, hours entered in the session's own time zone |
Main functions
ST_ZoneToServer(broker, zone, zoneTime): session time in London / New York / Tokyo / Sydney / GMT to server timeST_ServerToUtc(broker, serverTime),ST_UtcToServer(broker, utc)ST_ZoneToUtc(zone, zoneTime)ST_UsDst(utc),ST_EuDst(utc),ST_AuDst(utc): daylight saving in force at a UTC momentST_DetectWinterOffset(rule, winter): live charts only, readsTimeTradeServer() - TimeGMT()once the terminal is connected. In the Strategy TesterTimeGMT()equals the simulated server time, so pass the offset as an input there.ST_ParseHM("08:30"): "HH:MM" to minutes
Example
#include <SessionTime.mqh>
ST_Broker b;
b.winter = 2; // GMT+2 in winter
b.dst = ST_DST_US; // server moves with US daylight saving
datetime londonOpen = ST_ZoneToServer(b, ST_ZONE_LONDON, D'2026.03.16 08:00'); // 11:00 server time
Check which rule your broker follows before you set dst: many GMT+2/+3 servers use the US dates, others use the EU dates. SessionBoxes.mq5 defaults to the US rule; change InpDst if your server follows the EU dates.
Tests
SessionTimeCheck.mq5 covers London, New York, Tokyo and Sydney, brokers on US and EU daylight saving, and Friday 17:00 New York = 00:00 server time. All 15 cases pass on MetaTrader 5.
Limits
US rules as in force since 2007, EU rules as they are today. Half-hour broker offsets and broker-specific holiday hours are not modelled.
Author
Ciprian Ghebanoaei, https://www.mql5.com/en/users/ciprian252