Trading Sessions That Survive Daylight Saving: New York Time to Broker Server Time in MQL5
Twice a year, a lot of session indicators quietly break. The London box starts an hour early, the New York killzone lands on the wrong candles, and "Asia" suddenly overlaps London. Nothing crashes, so most traders never notice. They just trade the wrong window for a few weeks.
The cause is always the same: the indicator stores session times in broker server time, but sessions are really defined in New York time, and the two clocks change for daylight saving on different dates.
This post shows the approach I use in GOAT Killzones: define every session in New York time, then convert to server time bar by bar.
Why fixed server hours fail
Most brokers run their server at GMT+2 in winter and GMT+3 in summer, switching on the US schedule so that the New York 17:00 close is always midnight on the chart. Others switch on the EU schedule, and some never switch at all.
The US and EU switch on different dates:
- US: second Sunday of March to first Sunday of November, at 02:00 local time
- EU: last Sunday of March to last Sunday of October, at 01:00 UTC
That leaves about three weeks in spring and one week in autumn where New York and the broker are one hour further apart (or closer) than usual. A session hard-coded as "server 15:30" is right for most of the year and wrong for those weeks. Over a few years of history that is a lot of wrong boxes, and a backtest that uses them is testing the wrong hour.
The idea: one source of truth
- Write every session in New York wall-clock time (for example, New York AM killzone 08:30–11:00).
- Convert New York time to UTC using the US daylight saving rule.
- Convert UTC to broker server time using the broker's standard offset plus that broker's own daylight saving rule.
Both directions use the same three pieces, so a box drawn on a 2024 bar and a box drawn today follow the same logic.
Step 1: the US daylight saving rule
// true when the New York wall-clock time 'wall' is inside US daylight saving
bool IsUSDST(const datetime wall)
{
MqlDateTime dt;
TimeToStruct(wall, dt);
if(dt.mon < 3 || dt.mon > 11) return false;
if(dt.mon > 3 && dt.mon < 11) return true;
int firstSun = 1 + (7 - WeekdayOf(dt.year, dt.mon, 1)) % 7;
if(dt.mon == 3) // starts 2nd Sunday of March, 02:00
{
int secondSun = firstSun + 7;
if(dt.day != secondSun) return (dt.day > secondSun);
return (dt.hour >= 2);
}
if(dt.day != firstSun) return (dt.day < firstSun); // ends 1st Sunday of November, 02:00
return (dt.hour < 2);
} WeekdayOf() builds the date with StructToTime() and reads day_of_week . The EU rule is the same shape: last Sunday of March to last Sunday of October, checked in UTC at 01:00.
Step 2: New York offset from UTC
int NYOffsetFromUTC(const datetime utc)
{
return IsUSDST(utc - 5 * 3600) ? -4 * 3600 : -5 * 3600; // EDT or EST
} Step 3: the broker's offset
The broker offset is measured once at start-up. TimeTradeServer() - TimeGMT() gives the current offset. Round it to 15 minutes, then remove the daylight saving hour if the broker is currently in it. What is left is the broker's standard offset, which never changes.
int srvStdOffset = 0; // seconds, e.g. 7200 for GMT+2
void DetectBrokerOffset()
{
long diff = (long)TimeTradeServer() - (long)TimeGMT();
int rounded = (int)(MathRound(diff / 900.0) * 900.0);
srvStdOffset = rounded - (BrokerDST(TimeGMT()) ? 3600 : 0);
}
int BrokerOffset(const datetime utc)
{
return srvStdOffset + (BrokerDST(utc) ? 3600 : 0);
} BrokerDST() uses the US rule, the EU rule or none, chosen by an input. In the Strategy Tester TimeGMT() isn't reliable, so there the offset comes from a manual input instead.
Putting it together
datetime NYToServer(const datetime nyWall)
{
datetime utc = nyWall - NYOffsetFromWall(nyWall);
return utc + BrokerOffset(utc);
}
datetime ServerToNY(const datetime srv)
{
datetime utc = srv - BrokerOffset(srv - srvStdOffset);
return utc + NYOffsetFromUTC(utc);
} To draw a session for any day, take that day's New York midnight, add the session's start and end minutes, and convert both ends with NYToServer() . To ask "is this bar inside a killzone?", convert the bar time with ServerToNY() and compare the minute of the day. Sessions that cross midnight (such as Asia) are handled by checking start < end and testing either side.
Weekend and close handling
The New York day ends at 17:00. Anything from Friday 17:00 to Sunday 17:00 New York time is closed, which stops "phantom" Sunday sessions from being drawn:
bool MarketClosedNY(const datetime wall)
{
MqlDateTime dt;
TimeToStruct(wall, dt);
if(dt.day_of_week == 6) return true;
if(dt.day_of_week == 5 && dt.hour >= 17) return true;
if(dt.day_of_week == 0 && dt.hour < 17) return true;
return false;
} How to check yours
Open a chart on the week after the US clock change in March (around the 10th–17th) and the week after the EU change in late March. London and New York boxes should sit on the same candles as the week before and the week after. If they jump by an hour, the indicator is using fixed server hours.
Free to use
All of this is in GOAT Killzones, which is free in the MQL5 Code Base with full source code: https://www.mql5.com/en/code/79409. It draws Asia, London and New York sessions, the ICT killzones and the session highs and lows, and the boxes stay on the right candles through every daylight saving change.
The same session engine drives the killzone check in GOAT A+ Confluence and the session jump buttons in GOAT Replay.
GOATS DYNASTY · Engineered for Presence


