Time Filters: Restricting Your EA's Trading Hours
The Logic of the Clock: Why Time Filters Matter?
In the 24/5 Forex market, not all hours are equal. A trend-following strategy that works beautifully during the high-volatility London and New York sessions will often get 'Chopped up' during the quiet Asian session. A Time Filter is a simple logic block that ensures your EA only trades when the probability of a successful move is highest.
By restricting your EA to specific hours (e.g., 08:00 to 18:00 GMT), you are filtering for Liquidity and Momentum. This is the key to reducing drawdown and increasing the 'Profit Factor' of any automated system. Trading less often—but with higher conviction—is a hallmark of professional algorithmic development.
The Danger Zones: Friday Close and Sunday Open
The most dangerous times for a trading bot are the Friday Close and the Sunday Open. On Friday evening, liquidity dries up, and spreads can widen to 50+ pips. On Sunday night, the market often 'Gaps' due to over-the-weekend news events.
A robust time filter should also include a Day-of-Week (DOW) check. Most institutional-grade EAs are configured to 'Close all trades' by 20:00 GMT on Friday. This prevents the account from being exposed to the high-slippage weekend gap risk. If your EA doesn't have a weekend filter, you are effectively gambling on the news.
Time Filter Execution Rules
- ✓
Primary: Restrict trading to 'High Liquidity' sessions (LDN/NY)
- ✓
Constraint: Use a Day-of-Week filter to avoid Friday close
- ✓
Market State: Broker Time (GMT+2/3) offset check mandatory
- ✓
Verified: Check the 'Experts' tab for 'No trade session' logs
- ✓
Survival: Stop trading 15 minutes before the weekend close
- ✓
Optimization: Test different session starts on M15 charts
Coding the Filter: MQL Time Functions
Implementing a time filter in MQL4/MQL5 involves the TimeHour() and TimeDayOfWeek() functions. You create two input variables: StartHour and EndHour. Inside the OnTick() loop, the EA checks: if (TimeHour(TimeCurrent()) < StartHour || TimeHour(TimeCurrent()) > EndHour) return;.
This simple logic tells the EA to stay flat during the hours you've specified as 'No-Trade' zones. This ensures that the code's signal-processing engine is only active during the periods of the day when its technical indicators (like RSI or Stochastic) are historically most accurate.
Context: The Broker Time (GMT) Offset
When setting your time filter, remember that the EA uses Broker Time, not your local time. Most brokers use GMT+2 or GMT+3 (Eastern European Time). You must adjust your settings to match your specific broker's clock. This is why many EAs have an 'Auto GMT' feature that detects the offset automatically via a server ping.