Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

Session Time - session hours to broker server time with daylight saving - library for MetaTrader 5

Ciprian Ghebanoaei
Ciprian Ghebanoaei
Algorithmic trader and MQL5 developer from Romania, building Expert Advisors since 2018.
Views:
18
Published:
\MQL5\Include\
SessionTime.mqh (7.85 KB) view
st_gap_week.png (14.1 KB)
st_table.png (18.62 KB)
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Session hours are defined 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.

On a GMT+2 server that follows US time, the London open is at 10:00 server time for most of the year but at 11:00 in those weeks. Code that uses fixed server hours is one hour off for about four weeks a year.

SessionTime.mqh models the server as UTC + a winter offset + one hour while the server is in its daylight-saving period (US rule, EU rule or none). With that model it converts any zone time to server time and back. It is an include file: add it to an indicator or Expert Advisor that needs session times, range windows or time filters in local market time.

Main functions

  • ST_ZoneToServer(broker, zone, zoneTime) - session time in London, New York, Tokyo, Sydney or GMT to server time
  • ST_ServerToUtc(broker, serverTime) , ST_UtcToServer(broker, utc)
  • ST_ZoneToUtc(zone, zoneTime) - two passes, so the hours around a clock change come out right
  • ST_UsDst(utc) , ST_EuDst(utc) , ST_AuDst(utc) - daylight saving in force at a UTC moment
  • ST_DetectWinterOffset(rule, winter) - live charts only: reads TimeTradeServer() - TimeGMT() after the terminal is connected and removes the summer hour. In the Strategy Tester TimeGMT() equals the simulated server time, so use an input there.
  • ST_ParseHM("08:30") - "HH:MM" to minutes after midnight

Example

#include <SessionTime.mqh>
ST_Broker b;
b.winter = 2;            // GMT+2 in winter
b.dst    = ST_DST_US;    // moves with US daylight saving
datetime londonOpen = ST_ZoneToServer(b, ST_ZONE_LONDON, D'2026.03.16 08:00');   // 11:00 server time

Files

  • SessionTimeCheck.mq5 (script) - runs 15 hand-calculated cases (London, New York, Tokyo, Sydney; brokers on US and EU daylight saving; Friday 17:00 New York = 00:00 server) and prints the Monday session opens around each clock change. Inputs: broker winter offset, broker daylight-saving rule, year. All 15 cases pass on MetaTrader 5.

London session box: London time vs fixed server hours, EURUSD M15, 11-12 March 2026

The screenshot shows EURUSD M15 on 11-12 March 2026, with boxes drawn from ST_ZoneToServer(): the orange box is the London session (08:00-16:30 London time) converted day by day, the grey box uses fixed server hours 10:00-18:30. In normal weeks the two boxes are identical.

Limits: the US rules are those in force since 2007 and the EU rules as they are today; half-hour broker offsets and broker-specific holiday hours are not modelled.

Basket Guard - closes a basket of positions at loss or profit in percent of balance Basket Guard - closes a basket of positions at loss or profit in percent of balance

Free Expert Advisor that watches a basket of open positions (all, by Magic number or by symbols) and closes the whole basket when floating loss or profit reaches a set percent of balance. Works next to any EA or manual trading.

Trade-Request Matrix: Regression Testing Invalid Stops, Volume and Close Errors with OrderCheck() Trade-Request Matrix: Regression Testing Invalid Stops, Volume and Close Errors with OrderCheck()

Part 4 of the regression-testing series. An Expert Advisor that builds a fixed matrix of 20 valid and invalid trade requests (stops at and inside the stops level, wrong-side stops, volume outside the symbol rules, oversized and unknown closes, unchanged and wrong-side modifications), checks each one with OrderCheck() without sending anything, and reports PASS, FAIL or INCONCLUSIVE per row with a digest you can compare between runs.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.