MetaTrader 4 & 5 Integration
Embed live central-bank and macroeconomic data directly in your MetaTrader charts and Expert Advisors.
The FXMacroData.mqh include file works with both MQL4 and MQL5 —
no extra DLLs required.
Languages
MQL4 & MQL5
Authentication
?api_key=YOUR_API_KEY
HTTP method
WebRequest() built-in
Files
Download
Three files make up the integration. Download each one and place it in the correct MetaTrader folder shown below.
FXMacroData.mqh
Core include — MQL4 & MQL5
API helper library. Place in MQL4\Include\ and/or MQL5\Include\.
Download .mqhFXMacroData_MacroPanel.mq4
Macro panel indicator — MT4
Chart overlay showing Policy Rate, Inflation, Unemployment and GDP for the active pair. Place in MQL4\Indicators\.
Download .mq4FXMacroData_MacroPanel.mq5
Macro panel indicator — MT5
Same panel indicator compiled for MQL5. Place in MQL5\Indicators\.
Download .mq5Installation
Setup guide
Copy files to the Include and Indicators folders
In MT4 click File › Open Data Folder. Copy the files to:
Allow WebRequest for the API host
Go to Tools › Options › Expert Advisors, tick "Allow WebRequest for listed URL", and add:
Compile the indicator
Open the MetaEditor (F4), locate FXMacroData_MacroPanel.mq4
in the Navigator pane and press F7 (Compile). Fix any path errors if
FXMacroData.mqh is not found.
Attach to a chart and enter your API key
Drag FXMacroData_MacroPanel
from Navigator onto any currency chart.
In the Inputs tab enter your
API key
(or leave blank to test with USD free-tier data).
Copy files to the Include and Indicators folders
In MT5 click File › Open Data Folder. Copy the files to:
Allow WebRequest for the API host
Go to Tools › Options › Expert Advisors, tick "Allow WebRequest for listed URL", and add:
Compile the indicator
Open MetaEditor (F4), locate FXMacroData_MacroPanel.mq5
and press F7. Compilation should complete with 0 errors.
Attach to a chart and enter your API key
Drag the indicator 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 |
|---|---|---|
| currency | string | Lowercase, e.g. "eur", "jpy", "gbp" |
| indicator | string | Snake_case name — see table below |
| api_key | string | Optional. Omit for free USD tier. Required for all other currencies. |
// 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 — free, no key needed 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.
string cal = FMD_GetCalendar("aud", ApiKey); Print(cal); // inspect in Experts log
string FMD_GetForex(base, quote)
Returns FX spot rate history. Free — no API key needed.
string fx = FMD_GetForex("usd", "jpy"); 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 |
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.
Full list: fxmacrodata.com/documentation
Indicator
Macro Panel indicator
FXMacroData_MacroPanel.mq4 /
FXMacroData_MacroPanel.mq5 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.
Indicators displayed
- Policy Rate (%)
- CPI Inflation (%)
- Unemployment Rate (%)
- GDP Growth (%)
Configurable inputs
ApiKey— your FXMacroData keyBaseOverride/QuoteOverrideRefreshMinutes— polling intervalPanelX/PanelY— positionFontSize, color inputs
The panel refreshes on every new bar and whenever RefreshMinutes have elapsed since the last API call.
API calls are made in the main chart thread via WebRequest() — use a longer refresh interval on lower-spec machines.
Examples
Custom scripts & EAs
Include FXMacroData.mqh in any indicator, script, or Expert Advisor
to access the full API surface.
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 HTTP 0 or error 4060
The URL https://fxmacrodata.com is not in the allowed list.
Go to Tools › Options › Expert Advisors, tick "Allow WebRequest for listed URL", and add https://fxmacrodata.com exactly as shown.
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://fxmacrodata.com/api/v1/data-catalogue"));
Or browse the full catalogue at fxmacrodata.com/documentation.
Can I use this inside an Expert Advisor (EA)?
Yes. Include FXMacroData.mqh in your EA just as you would in an indicator.
Call FMD_GetIndicator() from OnInit()
or on a timer to cache the latest values and avoid blocking every tick.