Mark Session Boundaries
Session times are always quoted in GMT, but a chart's time axis is the broker's server time, and every broker sits at a different, often unlabelled, offset from GMT. Getting that offset wrong is the single most common bug in session-marking scripts. MQL has no function that simply reports "the broker's UTC offset". This script derives it the only honest way available: by comparing TimeGMT(), which is calculated from the local computer's time zone and daylight-saving data, against TimeCurrent(), the broker's own server time. The difference is printed to the Experts log every run, in minutes, so the number being used is never hidden. That derivation has two limits, and both are stated plainly rather than glossed over. First, it is only as accurate as the computer's own clock and time zone settings at the moment the script runs - a machine with the wrong system time zone will derive the wrong offset. Second, it is a single snapshot: London and New York each move their own UTC offset by an hour twice a year for daylight saving, and the derived broker offset does not know when that happened for either city. Across a lookback that straddles a DST change, a wall drawn from a fixed GMT hour input can drift by an hour against what actually happened on that historical day. The GMT hour inputs exist for exactly this reason - if a wall looks a session out after a change, correct the input by hand rather than expect the script to track daylight saving on your behalf. Two display modes are supported from the same inputs. Lines mark the open and close instants precisely. Rectangles shade the whole session as a background band, spanning the full visible price range so the candles read clearly on top of it - useful for seeing at a glance which session a move happened in. Each session can be switched off independently, and each has its own colour. Notes and limitations - The broker GMT offset is derived once, from the clock at the moment the script runs, and applied to every day in the lookback. It does not follow historical DST changes on either the broker's side or London/New York's side. - This script does not draw the objects live going forward - it draws a fixed set of boundaries for the days that have already happened (plus today, even if not yet complete) and does not update on new ticks. - Weekends are not skipped. A day count that spans a weekend will include boundaries for Saturday and Sunday, which simply land in the gap before Monday's bars. - Objects are prefixed "ses_" and are always cleared and redrawn from scratch on every run - nothing here is meant to be edited by hand.
Script · MT4 · v1.0 · Free
About Mark Session Boundaries
Mark Session Boundaries is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 15 settings, such as Days back, Display mode and Show tokyo. MQL source code included.
Files in the download: MarkSessions.ex4, MarkSessions.mq4, MarkSessions.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Days back | 5 | Days back to mark |
| Display mode | DISPLAY_LINES | How to draw each session |
| Show tokyo | true | Show Tokyo |
| Tokyo open gmt | 0 | Tokyo open, GMT hour (0-23) |
| Tokyo close gmt | 9 | Tokyo close, GMT hour (0-23) |
| Tokyo color | C'40,70,100' | Tokyo colour |
| Show london | true | Show London |
| London open gmt | 8 | London open, GMT hour (0-23) |
| London close gmt | 17 | London close, GMT hour (0-23) |
| London color | C'40,100,60' | London colour |
| Show new york | true | Show New York |
| New york open gmt | 13 | New York open, GMT hour (0-23) |
| New york close gmt | 22 | New York close, GMT hour (0-23) |
| New york color | C'100,70,40' | New York colour |
| Show labels | true | Draw a small session name label |
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 · Alerts · MT4 Script · MQL4 Source Code