Timezone Rules Lite
MQL4 has no timezone API beyond the broker's own server time, which floats depending on that broker's own DST policy - many brokers do not observe DST at all, or shift on their own schedule unrelated to any real-world zone. Any script that needs to know whether it is currently session hours in New York, London or Frankfurt has to compute that from first principles. The US and EU rules are genuinely different and both are easy to get wrong. The US rule changed in 2007 (the Energy Policy Act of 2005 moved the start from the first Sunday in April to the second Sunday in March, and the end from the last Sunday in October to the first Sunday in November) - a script written against the old dates silently misreports the three weeks either side of the actual switch every year. The EU rule runs on the last Sunday in March and the last Sunday in October, both switching at 01:00 UTC regardless of country, which is a different rule entirely from the US one, not just a different date. This library hand-codes both rules as date computations - the Nth weekday of a month, or the last weekday of a month - rather than pulling from any external timezone file or server lookup, so it has nothing to download and nothing that goes stale. Four zones are covered: US Eastern (EST/EDT), UK London (GMT/BST), EU Central (CET/CEST), and two fixed-offset references, Tokyo (JST, never observes DST) and UTC itself. TzOffsetHours is the function most callers need: given a zone and a UTC instant, it returns the current offset in whole hours, DST already resolved. TzToLocal converts a UTC instant to that zone's local wall-clock time for display. TzNextTransition reports the next DST boundary for a zone, useful for scheduling a session-open check that fires on the correct day even during the week rates change. Notes and limitations - The US rule modelled here is the post-2007 rule only. A backtest running before 2007 will compute the wrong US transition dates for those years; this library targets live and recent use, not multi-decade backtests. - All inputs and outputs are UTC instants (datetime values representing UTC), except TzToLocal's return value, which is a display-only local wall-clock reading - never feed that value back into another UTC-based comparison in this library or anywhere else. - Only four zones are covered. Extending to another zone means adding its own DST rule (or fixed offset) as a new case in TzOffsetHours/TzIsDaylight/ TzAbbreviation/TzNextTransition - the pattern is copy-paste from the existing EU or fixed-offset case. - This library has no dependency on broker server time, symbols, or trade context - every function takes a UTC datetime and returns a plain value, so it is safe to call from any program type.
Script · MT4 · v1.0 · Free
About Timezone Rules Lite
Timezone Rules Lite is a script for MetaTrader 4. It has 1 setting, such as Reference year. MQL source code included.
Files in the download: TimezoneRulesLite.mqh, TimezoneRulesLite.txt, TimezoneRulesLiteDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Reference year | 2026 | Year used to build the DST transition walkthrough |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Trading Sessions · MT4 Script · MQL4 Source Code