Page 1 of 1

Automatically detecting the broker's server time offset so my session filter doesn't break

Posted: Thu Oct 08, 2026 2:00 am
by Fairman
Automatically detecting the broker's server time offset so my session filter doesn't break

my EA had inputs for the session start and end in server time, and every time the broker's clock shifted for daylight saving I had to remember to change them. I forgot more than once and it traded in the wrong hours for a week.

My fix was to calculate the offset in the code. The EA compares the server time with GMT, which the platform can give me, and works out the difference. Then I enter the session times in GMT, and the EA converts them to the current server time each tick or each bar. When the broker's clock changes, the offset changes with it automatically.

There are some caveats. In the strategy tester the GMT function may not behave the same way as live, so I tested separately. And around the daylight saving transitions there can be an hour of mismatch because the broker's switch and the reference one don't happen on the same day. I just disable trading for a few hours around those dates to be safe.

It's a small improvement but it removed one of my recurring mistakes.

Re: Automatically detecting the broker's server time offset so my session filter doesn't break

Posted: Thu Oct 08, 2026 2:35 am
by Fairman
On the tester point, what I found is that the GMT time function in the tester just returns the server time, so the offset comes out as zero. For backtests I added an input where I set the offset manually, along with dates for when it changes. Live, the EA calculates it, and in the tester it uses the input. It is a bit clunky, but it means the backtest uses the same session hours as live trading would have.

Re: Automatically detecting the broker's server time offset so my session filter doesn't break

Posted: Thu Oct 08, 2026 3:02 am
by Fairman
A tip for checking the offset is working. I make the EA print the calculated offset and the converted session start and end times to the log once a day. After a clock change I look at the log the following Monday and check the times match what I expect. It takes a minute and it has already caught one case where my broker changed its server time on a different weekend than I had assumed. Since then the check is part of my Monday routine.