Automatically detecting the broker's server time offset so my session filter doesn't break
Posted: Thu Oct 08, 2026 2:00 am
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.
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.