DuoFX News Filter Library MT4
- librerie
-
Dragos Mihai Ofrim
DuoFX Labs: trading tools for MetaTrader 5 and MetaTrader 4
We build the tools we use ourselves: fast, clean and honest about what they do. Every product ships for both MT5 and MT4 from the same code, is tested on live charts before release, and gets updates when traders ask for something. - Versione: 1.0
- Attivazioni: 10
Backtest with a news filter. Keep your Expert Advisor out of FOMC, CPI and Nonfarm Payrolls (NFP), live, in the Strategy Tester and in the optimizer.
User guide and articles
Needs coding: a library for MQL5 and MQL4 developers. It has no panel, does not trade and does nothing on its own: your EA calls it.
MT5's built-in economic calendar isn't available in the Strategy Tester, and MT4 has no built-in calendar. A news filter built on them only works live, so backtests and optimizations run without it. DuoFX News Filter Library compiles the high-impact US calendar into the library: the same calendar live and in the tester. Set your broker's time mode once and the news windows land on the same bars in both. No web requests, no files, no DLLs.
Who uses it
- EA developers: add a high impact news filter to any Expert Advisor in a few lines of MQL5 or MQL4.
- Prop firm traders: each prop firm has its own news rule (how many minutes, which currencies, whether open trades count). Set the window to match yours and test it in the Strategy Tester. The library covers the US releases listed below; it cannot guarantee that a trade complies with any firm's rules.
- Scalpers and gold (XAUUSD) traders: avoid trading during news, when spreads widen and stops slip.
- Optimization: compare your EA with and without the filter on the same history.
High impact US news: FOMC, CPI, NFP, plus PPI, retail sales, GDP and PCE
- FOMC rate decision (statement time), CPI and Nonfarm Payrolls (NFP): on by default.
- PPI, retail sales, GDP advance estimate and PCE (personal income and outlays): switch on any of them.
- 574 releases from January 2020 to December 2027, from the official Federal Reserve, BLS, Census and BEA schedules, including dates moved by government shutdowns and the emergency Fed actions of March 2020.
- Times to the minute (08:30, 10:00, 14:00 New York and the rest), as scheduled by the agency. A release can be delayed on the day.
Built for the Strategy Tester and the optimizer
- The calendar lives inside the library, so backtests, visual mode and every optimizer pass see the same releases as live trading.
- Fast, even across thousands of optimizer passes.
Your broker's server time, both sides of every clock change
- Each release is stored in New York time and converted to your broker's server time, with the US and EU daylight saving rules for every year.
- Time modes: NY+7 (GMT+2/+3 with US DST, the most common forex and gold server clock), EU DST (an offset that changes with Europe, e.g. GMT+2/+3 or GMT+0/+1), US DST with any offset, and a fixed GMT offset.
- The gap weeks are handled: in March and around the start of November the US and Europe change clocks on different dates, and a release lands an hour apart on the two kinds of server.
- Auto mode, live only: it reads the server's GMT offset and matches the weekly market opens in the chart's H1 history against the US DST, EU DST and no-DST rules. It recognises those three families with any whole or half hour offset. With too little history, or a symbol that trades all weekend, it cannot tell the rules apart outside the gap weeks: it then says "ambiguous" in its log line and assumes NY+7. Until the terminal is connected it also assumes NY+7.
- In the Strategy Tester Auto always uses NY+7, because the tester has no real GMT clock, and prints a warning. Set your broker's mode yourself for backtests.
Windows that match how bars work
- Minutes before and after, your choice. Suggested: 2 before and 5 after (tight), or 15 before and 30 after (wide).
- Whole minutes, both ends included: 2 before and 5 after NFP at 15:30 server time blocks 15:28:00 to 15:35:59, and 15:36:00 is free again. One rule for ticks and M1 bars.
- Releases in the same minute come back as one event, e.g. "CPI + Retail Sales".
The API
- DuoNewsInit(types, minutes_before, minutes_after, time_mode, gmt_offset_minutes) : once in OnInit.
- DuoNewsIsBlocked(server_time) : true inside a window. The one call most EAs need.
- DuoNewsNextEvent and DuoNewsLastEvent : the next or last release and its name.
- DuoNewsMinutesToNext : minutes to the next release, to avoid opening a trade that would still be open at it.
- DuoNewsEventsBetween : every release in a range, for drawing them on a chart.
- DuoNewsCoverageEnd : the server time up to which the calendar is complete.
- DuoNewsTimeModeText and DuoNewsCalendarInfo : for your logs.
- Everything is prefixed DuoNews / DUONEWS_, so it does not clash with your own code.
Add it to your EA
- Install the library from the Market, then copy the installed file to MQL4\Libraries\DuoFX\NewsFilter.ex4. The user guide shows where the terminal saves it.
- Save the DuoFX header from the user guide as MQL5\Include\DuoFX\NewsFilter.mqh (MT4: MQL4\Include\DuoFX\NewsFilter.mqh ).
- #include <DuoFX\NewsFilter.mqh> , then in OnInit: DuoNewsInit(DUONEWS_TIER1, 2, 5, DUONEWS_TIME_NY_PLUS_7, 0);
- Before any entry: if(DuoNewsIsBlocked(TimeCurrent())) return;
A free sample EA that draws the news windows on the chart and stays flat around them is in the user guide.
What it covers, and what it does not
- US releases only: FOMC, CPI, NFP, PPI, retail sales, GDP advance and PCE. No other countries, no speeches, no FOMC press conference (usually 30 minutes after the statement: widen "after" to cover it).
- Release times only. Forecasts, actual figures and surprises are not included.
- Complete to 31 December 2027. After that DuoNewsIsBlocked returns false, so check DuoNewsCoverageEnd() in your EA. We plan to extend the calendar in later versions.
- Dates up to 8 November 2026 are confirmed against the official schedules; later dates are as scheduled.
- The library answers questions about time. Your EA decides what to do: skip entries, close trades or move stops.
News filter FAQ
- Does it work in the Strategy Tester and the optimizer? Yes. The calendar is compiled in, so backtests, visual mode and optimizer passes use the same releases as live. Set your broker's time mode for backtests.
- Does it work on MT4? Yes, the MT4 version has the same functions and calendar.
- Which time mode do I pick? If your server shows GMT+2 in winter and GMT+3 in summer and the daily candle starts at 17:00 New York, use NY+7. Not sure? Run your EA live with Auto: its log line names the rule it found, or says ambiguous. Then use that mode in the tester.
- Can it trade or close my positions? No. Your EA does that.
- Does it need WebRequest, DLLs or files? No.
- Is the forecast or actual number included? No, release times only.
- What happens after 2027? DuoNewsCoverageEnd() tells your EA where the calendar ends. We plan to extend it in later versions.
- Can I use it in an EA I build for clients or sell? Each terminal that runs the EA needs the library installed, so your clients need their own copy. For an EA sold on the MQL5 Market, a Market product generally cannot depend on another Market product: check MQL5's seller rules first.
- Other currencies? US events only. They move gold, the US dollar pairs and US indices most.
Available for MetaTrader 5 and MetaTrader 4.
Settings (DuoNewsInit arguments)
- Event types: DUONEWS_FOMC , DUONEWS_CPI , DUONEWS_NFP , DUONEWS_PPI , DUONEWS_RETAIL , DUONEWS_GDP , DUONEWS_PCE , combined with | ; DUONEWS_TIER1 (FOMC, CPI, NFP, the default) and DUONEWS_ALL . At least one.
- Minutes before and after: 0 to 1440 each (default 2 and 5)
- Time mode: Auto (default), NY+7, EU DST, US DST, fixed offset
- GMT offset for EU DST, US DST and fixed: winter offset in minutes, -720 to +840 in steps of 15 (120 = GMT+2)
- Bad arguments are refused with a log line, and the previous settings stay in force
Trading is risky, and news releases are among the most volatile minutes of the month. A news filter reduces exposure to scheduled releases; it does not remove risk, and markets can move sharply at any time. Not financial advice, no promise of profit. Test any EA on a demo account first.
