Building a Time-of-Day Filter Into Your EA
Most strategies do not have an edge spread evenly across the day. The hours where the edge lives are usually a subset, and an EA without a time filter trades the rest with equal enthusiasm.
Building a time-of-day filter into your EA is straightforward to code and easy to get subtly wrong, mostly because of which clock you measure against.
Derive the Window From Your Results
Do not guess. Export your trade history, group results by hour of entry, and see where performance actually sits.
Most traders find something unexpected. Either profit concentrates in a window they were not prioritising, or losses concentrate in one they assumed was productive.
That takes minutes and beats any general advice about which session suits which strategy.
Choose What Your Window Is Anchored To
Here is the decision that breaks most implementations.
A window can be anchored to a market session or to a fixed clock, and those are different things.
Session anchored means the London open, which is eight in the morning London time whether or not summer time is in effect. In GMT terms that hour moves twice a year.
Clock anchored means a fixed hour that never moves, which drifts relative to the session for part of the year.
If your edge comes from session behaviour, and it usually does, the window must follow the session. A hardcoded hour measures the wrong period for several months.
Decide which you want and make sure the code implements it.
Know Which Clock You Are Reading
Platforms expose several and they return different values.
Server time is what your broker’s feed uses and your charts display. GMT is a fixed reference. Local time is whatever your machine thinks, which is irrelevant and differs on a VPS abroad.
Choose one and use it consistently. A filter comparing a server hour against a locally derived value is the quiet bug behind a strategy that tests well and trades at the wrong times live.
Decide What Happens at the Boundary
The filter blocking new entries is only half of it.
If the window closes at four and the EA enters at five to four, the position is open when the window ends. Either it runs outside your tested hours or something closes it.
Treat the entry window and the exit policy as separate settings. A buffer blocking new entries before the window closes removes the case entirely.
Day of Week Is Often Worth More
Hour filtering gets the attention and day filtering frequently does more.
Monday opens into accumulated weekend news. Friday afternoons carry thin liquidity and weekend gap exposure. Those are structural rather than statistical quirks.
Segment by weekday as well as hour before deciding what to exclude.
The Overfitting Problem
This is honest caution and it matters more here than with most filters.
With twenty four hours and five weekdays you have over a hundred cells. Some will look excellent by chance, and selecting the best is choosing the luckiest sample from a set you generated.
A time filter needs a reason beyond the backtest. A session boundary, a release schedule, a liquidity pattern. If you cannot explain why the excluded hours differ, you have probably fitted noise.
Check those hours have enough trades to support the conclusion before removing them.
Conclusion – Building a Time-of-Day Filter Into Your EA
Building a time-of-day filter into your EA means deriving the window from your own results, anchoring it to a session rather than a fixed clock when the edge is session driven, using one clock consistently, handling the boundary deliberately, and justifying the exclusion with a mechanism rather than with performance alone.
FAQ – Building a Time-of-Day Filter Into Your EA
1. Should my window follow daylight saving?
If the edge comes from session behaviour, yes. A fixed clock hour drifts relative to the session for several months a year.
2. What should happen to open trades at the window close?
Decide explicitly. A buffer blocking new entries before the window ends avoids the problem.
3. How do I know the filter is not overfitted?
It needs a structural reason, not just a good backtest. With over a hundred hour and weekday combinations, some will look profitable by chance.
We have helped thousands of traders reach funding at TTT Markets from account sizes of $5k upwards to $500k. Check out our programs.
Additional resources:
MQL5 Session Time Filter: Code EA Trade Hours Utility
support@tttmarkets.com
WhatsApp Support →