How to Add a News Filter to an MT4 Expert Advisor

To stop an MT4 Expert Advisor trading around high-impact news, give it a schedule of upcoming economic releases and check that schedule before every new entry. MetaTrader 4 has no economic calendar that an Expert Advisor can read, so the schedule has to come from outside the terminal. This guide adds one with a single include file. It loads official release times for 15 currencies and gold, matches both currencies of the chart symbol, and tells your code whether the symbol is inside a quiet window right now.

Contents

You need MetaTrader 4, the source of your Expert Advisor and a Finance Calendar API key. The same include file compiles for MetaTrader 5, so the steps carry over unchanged. The filter only reads the schedule. Your Expert Advisor stays in charge of every order.

What a news filter has to do

  • Know the release times. US jobs, CPI, rate decisions and the other market-moving releases, with exact times in UTC so broker server time and daylight saving do not shift them.
  • Match the symbol. EURUSD should react to euro area, German and United States releases. USDJPY should not react to a UK release.
  • Answer quickly. One call before each entry: is this symbol inside the window around a release?

Step 1: get the files

Download the include and the example Expert Advisor for your terminal:

Copy FinanceCalendarNews.mqh into the MQL4/Experts folder beside your Expert Advisor. In MetaTrader, File → Open Data Folder takes you there.

Step 2: allow the terminal to load the schedule

MetaTrader blocks web requests until you list the address. Open Tools → Options → Expert Advisors, tick Allow WebRequest for listed URL and add:

https://www.financecalendar.com

Step 3: add the filter to your Expert Advisor

Start the filter once, refresh it from a timer and ask before you open a trade. A refresh only makes a request when one is due.

#include "FinanceCalendarNews.mqh"

input string InpApiKey = "";

int OnInit()
{
   FcNewsInit(InpApiKey);
   EventSetTimer(30);
   return INIT_SUCCEEDED;
}

void OnTimer() { FcNewsRefresh(); }

void OnTick()
{
   string reason;
   if(FcNewsBlocked(_Symbol, 30, 30, reason))
      return;   // 30 minutes either side of a release

   // your entry logic
}

Compile in MetaEditor, attach the Expert Advisor to a chart and paste your key into InpApiKey. Keep the key out of shared presets and screenshots. Run it on a demo account first and watch it through one release.

Step 4: choose the window

The two numbers in FcNewsBlocked are the minutes before and after each release. Thirty either side is a common starting point. Widen the window after the release if your strategy is sensitive to spreads, which can stay wide for some minutes.

Setting Default What it controls
InpImpact high Which releases count. Use high,medium for a wider filter.
InpMinutesBefore / InpMinutesAfter 30 / 30 The size of the quiet window around each release.
InpRefreshMinutes 180 How often the schedule is refreshed.

Stand aside when no schedule is loaded

A filter that fails open is worse than no filter. FcNewsReady() tells you whether a schedule from the last 26 hours is loaded, so your code can hold new entries when the terminal has been offline:

if(!FcNewsReady())
   return;   // no recent schedule, so do not open new trades

FcNewsNext(_Symbol, when, name) gives the next release time in UTC and its name, which is useful for a chart label or a log line.

Use it without changing your code

If you cannot edit an Expert Advisor, run the example on any chart of the symbol. It publishes the state as a terminal global variable that another Expert Advisor can read: 1 inside a quiet window, 0 clear, -1 when no usable schedule is loaded.

string state = "FC_NEWS_BLOCK_" + _Symbol;
bool quiet = GlobalVariableCheck(state)
          && GlobalVariableGet(state) == 1.0;

Which releases count for each symbol

Each symbol is matched through its base and quote currencies. EURUSD watches euro area, German and United States releases. XAUUSD watches the United States. Covered currencies are USD, EUR, GBP, JPY, CAD, AUD, NZD, CHF, CNY, INR, KRW, MYR, HKD, NOK and SEK. Cancelled releases, and releases without a published time, never open a window.

Release times come from the publishers’ own schedules, such as the Bureau of Labor Statistics, Eurostat and the central banks, and each record links to its source.

How many requests it uses

With the default settings the filter refreshes every three hours, which is 8 requests a day, and every chart in one terminal shares the same schedule. That leaves most of a Starter allowance free for a dashboard, a Python script or an AI assistant on the same key.

More than a schedule on the same key

The key that runs the filter also returns consensus forecasts for 60 measures across 10 economies, with the actual and previous figures after each release. That lets an Expert Advisor or a companion script act on the size of a surprise, not only on the clock. The same account connects ChatGPT and Claude to the calendar through the hosted MCP server.

Free and Starter at a glance

Starter is US$4.99/month or US$53.89/year with 250 requests per UTC day and 5,000 per UTC calendar month for consensus across 10 economies, results and history, wider dates and integration tools. Ongoing Free Developer provides 100 successful schedule JSON responses per UTC calendar month, up to 10 per UTC day, with 1 active key issued after approval of your request. Its allowance renews monthly; no card or automatic paid conversion.

Free-to-Starter integration details

Starter adds recorded figures, history, wider dates and paid integration tools. Keep your existing active API key linked to the same verified account when paid access is confirmed. Free Developer and paid access use different JSON response schemas: Free returns compact schedules and omits numerical fields; paid access adds richer event fields and endpoint-specific responses. Use the documented paid response model when adding these features, including the different /today envelope. Compare Free and paid response models.

Compare current plans · Current machine-readable prices and allowances.

If the calendar does not load

  • WebRequest returns -1 (error 4014 or 4060). The terminal has not been allowed to call the site. Repeat step 2.
  • HTTP 401. The key is missing or not recognised. Check for extra spaces. Keys start with fc_live_.
  • HTTP 429. The allowance for the day has been used. Refreshing every few hours is enough for a news filter.
  • Strategy Tester. WebRequest does not run in the Strategy Tester or in indicators, so test the filter on a live demo chart.

About Finance Calendar

Economic release schedules, market calendars and practical guides to using the data.

About the site
Back to Resources

Keep reading

All articles

From Resources

From Resources

From Resources