1. Why News Filtering Is Required in Algorithmic Trading
High-impact macroeconomic releases (NFP, CPI, FOMC, ECB, GDP, etc.) introduce:
-
liquidity gaps
-
spread explosions
-
stop-hunting spikes
-
non-stationary volatility
Any strategy based on technical market structure becomes unreliable during those periods.
A professional Expert Advisor must therefore disable new trade entries during macroeconomic shock windows.
2. Why MT5 Economic Calendar Should Be Used
Many legacy EAs use:
-
ForexFactory scraping
-
Investing.com APIs
-
external XML feeds
These approaches fail in production because:
-
WebRequest is blocked on VPS
-
websites change layouts
-
Strategy Tester cannot reproduce them
-
Market validation rejects them
MetaTrader 5 provides a native Economic Calendar API maintained by MetaQuotes.
It is synchronized with the broker’s trade server and works in live trading, VPS and validation.
This article uses that API.
3. What the News Filter Does
The filter blocks only new entries during a configurable time window:
It is configurable by:
-
currency list (e.g. USD,EUR )
-
news importance (High / Medium+High / All)
-
minutes before and after the event
Trailing stops, break-even logic and exits are never blocked.
4. Architecture Overview
The filter works in two stages:
Stage 1 – Cache refresh (infrequent)
The EA periodically queries the MT5 calendar and stores the nearest upcoming news window.
Stage 2 – Runtime check (every entry)
When a trade signal appears, the EA only checks:
Is current server time inside the cached window?
This makes the filter extremely fast and suitable for scalpers and high-frequency EAs.
5. Supplied Module: NewsFilter.mqh
The full implementation is provided in the attached file:
It contains:
-
all input parameters
-
calendar queries
-
cache logic
-
debug display
-
init / deinit handlers
You do not need to write or maintain calendar code yourself.
6. How to Attach the News Filter to an Expert Advisor
Copy NewsFilter.mqh into:
Then include it in your EA:
7. Initialization
In OnInit():
int OnInit()
{
NewsFilter_Init();
return(INIT_SUCCEEDED);
}
In OnDeinit():
void OnDeinit(const int reason)
{
NewsFilter_Deinit();
}
This ensures that:
-
the news cache is prepared
-
chart debug text is cleaned when the EA is removed
8. Blocking New Trade Entries
Insert this block immediately before opening any new position:
string why = "";
if(UseNewsFilter)
{
NewsFilter_DebugUpdate(); // optional, only if NewsDebug = true
if(NewsFilter_Blocked(why))
return; // cancel entry
}
This will block BUY and SELL entries during the news window, but will not interfere with:
-
trailing stops
-
exits
-
trade management
9. Debug Mode
When NewsDebug = true, the filter shows its state directly on the chart and logs state changes.
Example:
NEWS FILTER: BLOCKED USD | Nonfarm Payrolls |
2026.01.09 15:30 Window: 14:30 – 16:30
This allows easy validation in live trading and forward testing.
10. Properties of the Implementation
This implementation:
-
uses the MT5 Economic Calendar
-
does not rely on WebRequest or external data sources
-
queries the calendar only at fixed intervals
-
performs O(1) checks during normal operation
-
supports filtering by currency
-
supports filtering by event importance
The filter can be integrated into any Expert Advisor that controls its own entry logic.
11. Conclusion
News filtering is a form of market regime control.
By combining:
-
the MT5 Economic Calendar
-
time-window based blocking
-
currency filtering
-
importance filtering
-
a cache-based update model
it is possible to implement a deterministic and low-overhead news filter that can be used as part of an automated trading system.


