Skip to content
Live Data MetaTrader 4 MetaTrader 5 USD Free Tier

MetaTrader 4 & 5 Integration

Embed live central-bank and macroeconomic data directly in your MetaTrader charts and Expert Advisors, and pause trading around scheduled releases with the News Filter EA. The FXMacroData.mqh include file works with both MQL4 and MQL5, no extra DLLs required.

Languages

MQL4 & MQL5

Authentication

X-API-Key: YOUR_API_KEY

HTTP method

WebRequest() built-in

USD endpoints support no-key evaluation up to 100 requests/day, delivered 15 minutes after each release. You can test the integration with no-key USD evaluation using any USD indicator. An Individual or Business key removes the delay, which is what a live trading setup needs. An API key is required for higher limits and all other currency pairs. Get an API key

Files

Download

Five files make up the integration: the include, the Macro Panel and the News Filter, each for MT4 and MT5. Download the ones you need and place them in the MetaTrader folders shown below. MetaTrader allows web requests only from Expert Advisors and scripts, so both programs install as EAs.

FXMacroData.mqh

Core include — MQL4 & MQL5

API helper library. Place in MQL4\Include\ and/or MQL5\Include\.

Download .mqh

FXMacroData_MacroPanel.mq4

Macro panel EA, MT4

Non-trading EA that overlays Policy Rate, Inflation, Unemployment and GDP for the active pair. Place in MQL4\Experts\.

Download .mq4

FXMacroData_MacroPanel.mq5

Macro panel EA, MT5

The same panel for MQL5. Place in MQL5\Experts\.

Download .mq5

FXMacroData_NewsFilter.mq4

News filter EA, MT4

Flags a blocking window around scheduled releases for your other EAs and can close positions ahead of a release. Place in MQL4\Experts\.

Download .mq4

FXMacroData_NewsFilter.mq5

News filter EA, MT5

The same news filter for MQL5. Place in MQL5\Experts\.

Download .mq5

Installation

Setup guide

1

Copy files to the Include and Experts folders

In MT4 click File › Open Data Folder. Copy the files to:

FXMacroData.mqh → MQL4\Include\ FXMacroData_MacroPanel.mq4 → MQL4\Experts\ FXMacroData_NewsFilter.mq4 → MQL4\Experts\
2

Allow WebRequest for the API host

Go to Tools › Options › Expert Advisors, tick "Allow WebRequest for listed URL", and add:

https://api.fxmacrodata.com
3

Compile the Expert Advisors

Open the MetaEditor (F4), locate FXMacroData_MacroPanel.mq4 and FXMacroData_NewsFilter.mq4 under Experts in the Navigator pane and press F7 (Compile) on each. Fix any path errors if FXMacroData.mqh is not found.

4

Attach to a chart and enter your API key

Drag FXMacroData_MacroPanel or FXMacroData_NewsFilter from the Expert Advisors list in Navigator onto any currency chart. In the Inputs tab enter your API key (or leave blank to test with USD free-tier data).

1

Copy files to the Include and Experts folders

In MT5 click File › Open Data Folder. Copy the files to:

FXMacroData.mqh → MQL5\Include\ FXMacroData_MacroPanel.mq5 → MQL5\Experts\ FXMacroData_NewsFilter.mq5 → MQL5\Experts\
2

Allow WebRequest for the API host

Go to Tools › Options › Expert Advisors, tick "Allow WebRequest for listed URL", and add:

https://api.fxmacrodata.com
3

Compile the Expert Advisors

Open MetaEditor (F4), locate FXMacroData_MacroPanel.mq5 and FXMacroData_NewsFilter.mq5 under Experts and press F7 on each. Compilation should complete with 0 errors.

4

Attach to a chart and enter your API key

Drag either EA from the Expert Advisors list onto any currency chart. Set your API key in the Inputs tab.

FXMacroData.mqh

MQL function reference

All public functions are defined in FXMacroData.mqh and work identically in MQL4 and MQL5. Each function is a thin wrapper around a single REST endpoint.

string FMD_GetIndicator(currency, indicator [, api_key])

Fetches a macroeconomic time series. Returns a JSON string.

Parameter Type Notes
currencystringLowercase, e.g. "eur", "jpy", "gbp"
indicatorstringSnake_case name — see table below
api_keystringOptional. Omit for free USD tier. Required for all other currencies. Sent as an X-API-Key request header.
// Policy rate — EUR requires an API key
string json = FMD_GetIndicator("eur", "policy_rate", ApiKey);
double rate = FMD_LastValue(json);
Print("EUR policy rate: ", rate);

// USD inflation — no-key evaluation, up to 100 requests/day
string inf = FMD_GetIndicator("usd", "inflation");
string FMD_GetCalendar(currency [, api_key])

Returns upcoming release dates and announcement times for all tracked indicators in a currency. Each row in data carries announcement_datetime as Unix seconds in UTC. Walk the rows with FMD_CalendarCount() and FMD_CalendarRow(), and compare times with TimeGMT(), not server time.

string cal = FMD_GetCalendar("usd");   // USD needs no key
int rows = FMD_CalendarCount(cal);
for(int i = 0; i < rows; i++)
  {
   long   epoch;  string release, name;
   int    tier;   bool   topTier, timed, assumed;
   if(!FMD_CalendarRow(cal, i, epoch, release, name, tier, topTier, timed, assumed)) continue;
   if(!timed || assumed) continue;        // keep exact official times only
   Print(name, " at ", TimeToString((datetime)epoch), " UTC, tier ", tier);
  }
string FMD_GetForex(base, quote)

Returns FX spot rate history. FX rates require an API key, and FMD_GetForex does not take one, so pass your key through FMD_WebGet as shown.

string fx = FMD_WebGet(FMD_BuildUrl("forex/usd/jpy"), ApiKey);
double spot = FMD_LastValue(fx);
Print("USD/JPY spot: ", spot);
string FMD_GetCOT(currency [, api_key])

Returns CFTC Commitment of Traders positioning data. Currency code should be uppercase.

string cot = FMD_GetCOT("EUR", ApiKey);
double net = FMD_JsonDouble(cot, "net_non_commercial");
Utility functions

Helper functions for parsing the JSON responses returned by the API.

Function Description
FMD_LastValue(json)Most recent non-null val from an announcements response
FMD_JsonDouble(json, key)Extract a numeric value by key name
FMD_JsonString(json, key)Extract a string value by key name
FMD_JsonBool(json, key, fallback)Extract a boolean by key name; fallback when absent
FMD_CalendarCount(json)Number of rows in a calendar response
FMD_CalendarRow(json, i, ...)Read row i: epoch, release, name, tier, top tier, time announced, time assumed
FMD_IsNewsBlocked()True while the News Filter EA reports a blocking window
FMD_NextRelease()UTC time of the release the News Filter EA is inside or waiting for; 0 when none
string json = FMD_GetIndicator("usd", "inflation");

// Get the most recent value
double val  = FMD_LastValue(json);

// Extract a named field from the last record manually
double num  = FMD_JsonDouble(json, "val");
string date = FMD_JsonString(json, "date");

Available indicators

Pass any of these snake_case names as the indicator argument to FMD_GetIndicator(). Not every indicator is available for every currency — see the full endpoint documentation for coverage.

policy_rate inflation inflation_mom core_inflation ppi ppi_mom gdp gdp_quarterly unemployment employment participation_rate retail_sales trade_balance current_account_balance consumer_confidence business_confidence industrial_production m1 m2 m3 gov_bond_2y gov_bond_5y gov_bond_10y gov_bond_30y

Full list: fxmacrodata.com/documentation/reference

Expert Advisor

Macro Panel EA

FXMacroData_MacroPanel.mq4 / FXMacroData_MacroPanel.mq5 is a non-trading Expert Advisor that draws a live data panel in the top-left corner of the chart showing four key macro indicators for both currencies in the active pair. It places no orders and touches no positions. It runs as an EA because MetaTrader allows WebRequest() only from Expert Advisors and scripts.

Indicators displayed

  • Policy Rate (%)
  • CPI Inflation (%)
  • Unemployment Rate (%)
  • GDP Growth (%)

Configurable inputs

  • ApiKey — your FXMacroData key
  • BaseOverride / QuoteOverride
  • RefreshMinutes — polling interval
  • PanelX / PanelY — position
  • FontSize, color inputs

The panel reloads its values whenever RefreshMinutes have elapsed since the last API call, eight requests per refresh. Without an API key the USD evaluation allowance is 100 requests a day, so keep the interval at 15 minutes or more. The Strategy Tester cannot make web requests, so the panel shows "No live data in the Strategy Tester" there.

Expert Advisor

News Filter EA

FXMacroData_NewsFilter.mq4 / FXMacroData_NewsFilter.mq5 loads the FXMacroData release calendar for the currencies you choose, keeps the releases that carry an exact official time, and raises a terminal-wide flag while the clock is inside a window around each one. Your own EAs read that flag with one call and skip new entries until the window closes. The News Filter never opens trades itself.

What it publishes

  • FXMD_NEWS_BLOCKED: terminal global variable, 1 inside a window, 0 outside
  • FXMD_NEXT_RELEASE: Unix time (UTC) of the active or next release
  • Optional chart panel: status, next release, local and UTC time, countdown, calendar age
  • Optional macro rows: policy rate, inflation, unemployment and GDP for the chart pair

Which releases count

  • Only rows with time_announced true: date-only entries are skipped
  • Rows with release_time_assumed true are skipped
  • High: tier 1 or top tier for the currency
  • Medium: tiers 1 and 2, plus top tier
  • All: every timed release

Install

Copy FXMacroData.mqh to the Include folder and the EA to MQL5\Experts\ or MQL4\Experts\, compile it, then allow the API host under Tools › Options › Expert Advisors: tick "Allow WebRequest for listed URL" and add https://api.fxmacrodata.com. Attach the EA to one chart per terminal; the flag is shared with every other chart. If ClosePositionsBeforeRelease is on, Algo Trading (MT5) or AutoTrading (MT4) must be enabled for the closes to go through.

Guard your own EA

#include <FXMacroData.mqh>

void OnTick()
  {
   if(FMD_IsNewsBlocked()) return;   // inside a release window: no new entries
   // ... your entry logic here ...
  }

Inputs

Input Default Meaning
CurrenciesUSDCalendars to watch, comma-separated, e.g. USD,EUR,GBP. USD works without a key; other currencies need one.
ApiKeyblankYour FXMacroData key, sent as an X-API-Key header. Blank limits the filter to USD.
BlockMinutesBefore10Minutes before each release that the block starts.
BlockMinutesAfter10Minutes after each release that the block ends.
ImportanceHighHigh, Medium or All, as described above.
ClosePositionsBeforeReleasefalseClose every open position on the chart symbol ahead of a release, whichever EA or person opened it. Pending orders are left in place.
CloseMinutesBefore2Minutes before the release at which positions are closed, when the option above is on.
RefreshMinutes60How often the calendar is reloaded, one request per watched currency. Minimum 5.
ShowPaneltrueDraw the status panel in the top-right corner of the chart. Colours follow the chart background, so it reads on light and dark themes.
OnlyChartSymbolCurrenciestrueWatch only the entries in Currencies that match the chart symbol's base or profit currency. Set to false to watch the full list on any chart.
ShowMacroPanelfalseAdd policy rate, inflation, unemployment and GDP rows for the chart pair under the status panel, refreshed with the calendar (eight extra requests per refresh).

Limits

  • It blocks only EAs that call FMD_IsNewsBlocked() or read FXMD_NEWS_BLOCKED. Other EAs and manual trades are not stopped.
  • It closes positions only when ClosePositionsBeforeRelease is on, and then closes every position on the chart symbol.
  • Times are compared in UTC with TimeGMT(); the panel shows both your computer's local time and UTC.
  • A failed calendar request keeps the releases from the last good load, and the panel shows how old the calendar is.
  • The Strategy Tester cannot make web requests, so the calendar is empty there and the flag stays at 0.
  • When the EA is removed from the chart the flag is reset to 0.

Examples

Custom scripts & EAs

Include FXMacroData.mqh in any Expert Advisor or script to access the full API surface. Indicators cannot call WebRequest(), so fetch in an EA and share values through global variables if an indicator needs them.

Alert when rate divergence exceeds a threshold

// Place in an EA or script — fires an alert when EUR-USD
// policy-rate spread crosses a threshold.
#include <FXMacroData.mqh>

input string ApiKey    = "";
input double MinSpread = 1.5;  // percentage points

void OnTick()
  {
   double eur_rate = FMD_LastValue(FMD_GetIndicator("eur", "policy_rate", ApiKey));
   double usd_rate = FMD_LastValue(FMD_GetIndicator("usd", "policy_rate"));

   if(eur_rate == EMPTY_VALUE || usd_rate == EMPTY_VALUE) return;

   double spread = MathAbs(eur_rate - usd_rate);
   if(spread >= MinSpread)
      Alert("EUR/USD rate spread: ", spread, "pp");
  }

Print upcoming releases to the Experts log

#include <FXMacroData.mqh>

input string ApiKey   = "";
input string Currency = "usd";

void OnInit()
  {
   string cal = FMD_GetCalendar(Currency, ApiKey);
   Print("[FXMacroData] Calendar for ", Currency, ": ", cal);
  }

Gate EA entries on macro context

#include <FXMacroData.mqh>

input string ApiKey     = "";
input double MaxUnempRate = 6.0;

bool MacroConditionMet(const string currency)
  {
   string json   = FMD_GetIndicator(currency, "unemployment", ApiKey);
   double uemp   = FMD_LastValue(json);
   if(uemp == EMPTY_VALUE) return false;  // fail-safe: skip trade
   return uemp < MaxUnempRate;
  }

void OnTick()
  {
   if(!MacroConditionMet("usd")) return;
   // ... your entry logic here ...
  }

Help

Troubleshooting

WebRequest returns -1 with error 4014 (MT5) or 4060 (MT4)

Two causes produce this error. Either the URL https://api.fxmacrodata.com is not in the allowed list, or the request was made from an indicator. MetaTrader allows WebRequest() only from Expert Advisors and scripts.

Go to Tools › Options › Expert Advisors, tick "Allow WebRequest for listed URL", and add https://api.fxmacrodata.com exactly as shown. Make sure the Macro Panel and News Filter are installed under Experts and attached from the Expert Advisors list, not from Indicators.

Compile error: "FXMacroData.mqh" not found

The include file is not in the correct folder. For MQL4, it must be at MQL4\Include\FXMacroData.mqh. For MQL5, at MQL5\Include\FXMacroData.mqh.

Open the MetaTrader data folder via File › Open Data Folder to confirm the path.

All values show "n/a" on the panel

Check the Experts log (Ctrl+T) for [FXMacroData] HTTP messages. Common causes:

  • API key is missing or invalid for a non-USD pair
  • The indicator you're requesting is not available for that currency
  • WebRequest URL not whitelisted (see above)
How do I check which currencies and indicators are available?

Use the Data Catalogue endpoint from within MQL:

Print(FMD_WebGet("https://api.fxmacrodata.com/v1/data_catalogue/usd"));

Or browse the full catalogue at fxmacrodata.com/documentation/reference.

Can I use this inside an indicator?

Not directly. MetaTrader allows WebRequest() only from Expert Advisors and scripts, so an indicator that calls it fails with error 4014 (MT5) or 4060 (MT4). Fetch the data in an EA, call FMD_GetIndicator() from OnInit() or OnTimer() so you do not block every tick, and pass values to an indicator through GlobalVariableSet() if you need them there.

Still stuck? Open a ticket at fxmacrodata.com/support or email info@fxmacrodata.com.

AI Answer-Ready

Key Facts

Page
Metatrader
Section
Documentation
Canonical URL
https://fxmacrodata.com/documentation/metatrader
Source
FXMacroData editorial and official publisher references
Last Updated
See page metadata

Provenance And Trust

Cite the canonical URL and source field above. Where available, this page maps to official publisher releases and timestamped updates.

Quick Q&A

What is this page about? This page explains Metatrader with directly usable context for trading, research, and API workflows.

What source should be cited? Use the canonical URL and the listed source field; cite official publisher references when available.

How fresh is this content? The last updated value above reflects the page metadata or latest available data timestamp.

Can this be used in AI assistants? Yes. This section is intentionally structured for retrieval and citation in chat assistants.

Prompt Packs

Use these in ChatGPT, Claude, Gemini, Mistral, Perplexity, or Grok for consistent source-aware outputs.

Share page X LinkedIn Email