XAU Macro Risk Filter
- Indicators
-
Aleksei Lebedev
I am engaged in the development of algorithmic trading systems and tools for MetaTrader 5, with a focus on XAUUSD. - Version: 2.0
- Activations: 5
This indicator reads the built-in MT5 economic calendar and displays US macro events on the XAUUSD chart. It draws vertical lines at event times, colored risk zone rectangles around each event, and an on-chart information panel with current risk status and countdown to upcoming events.
The indicator is designed for traders who want to see macro event timing directly on the chart without switching to the calendar tab. It is also useful for EA developers who need their robots to account for scheduled news risk.
How it works
The indicator uses the native MQL5 Calendar* API. It does not require WebRequest calls, external websites, API keys, or subscriptions. It works on any broker that provides MT5 calendar data.
Events are classified into three risk tiers, each with its own color and independently configurable time window.
Risk classification
BLOCK tier (red line, firebrick zone): NFP, Unemployment Rate, Average Hourly Earnings, CPI, Core CPI, PCE, Core PCE, FOMC Rate Decision, FOMC Statement, FOMC Press Conference, Dot Plot, SEP, Jackson Hole.
BLOCK-SHORT tier (orange line, dark orange zone): PPI, Core PPI, Initial Jobless Claims, ADP Employment, Retail Sales, Core Retail Sales, Fed Chair Powell Speeches.
WARNING tier (gold line, gray zone): ISM Manufacturing PMI, ISM Services PMI, S&P Global PMI, JOLTS, University of Michigan Sentiment, FOMC Member Speeches.
Low-impact data such as Cleveland Fed Trimmed Mean and Dallas Fed PCE is filtered out automatically.
Per-event time windows
Each event type has its own configurable "minutes before" and "minutes after" window. Default values are based on typical gold market behavior:
NFP: 45 minutes before, 150 minutes after. FOMC Rate Decision: 30 minutes before, 240 minutes after. CPI and PCE: 30 minutes before, 120 minutes after. PPI, Claims, ADP, Retail: 15 minutes before, 60 minutes after. WARNING events: 5 minutes before, 30 minutes after.
All values can be adjusted in the indicator settings.
On-chart information panel
A compact panel in the top-right corner of the chart displays:
Current risk status. When no risk window is active it shows CLEAR. When a risk window is active it shows the event name and risk tier with the block end time.
Upcoming events listed chronologically and grouped by date. Each event has a live countdown timer showing days, hours, and minutes remaining. Events scheduled for today are highlighted.
Chart labels
Event names are drawn directly on the chart near the corresponding bars. Labels are staggered to avoid overlap and can be toggled independently for past, current, and future events. Labels near the right edge of the chart automatically extend to the left to stay visible.
Historical risk zones
Past risk zones can be displayed on the chart for backtesting and analysis. This allows visual comparison of price action with news windows. Historical zones are drawn only within the visible chart area and are limited to a configurable maximum count to maintain performance.
EA integration via GlobalVariables
The indicator writes four MT5 GlobalVariables that any Expert Advisor can read:
XAU_NEWS_BLOCK — equals 1.0 when a risk window is active, 0.0 when clear. XAU_NEWS_LEVEL — current risk level from 0 (clear) to 3 (block). XAU_NEWS_BLOCK_UNTIL — timestamp when the current block expires. XAU_NEWS_EVENT_TIME — timestamp of the current event.
An EA can check the block status before opening a trade with a single GlobalVariableGet call. No DLL, no file I/O, no external services are needed.
FOMC event clustering
Related FOMC releases such as the rate decision, statement, and press conference that occur within a configurable time interval are automatically merged into a single combined risk zone with the widest time window.
Technical details
The calendar is loaded in 90-day chunks to prevent API timeouts on large date ranges. It refreshes automatically every 15 minutes. The panel updates every 60 seconds. A manual time shift parameter allows correction for broker calendar timezone differences. The indicator only activates on symbols containing XAU or GOLD in the name and has zero overhead on other charts.
Parameters
Over 50 configurable inputs are available. Event visibility can be toggled per risk tier. Time windows are individually adjustable for each event type. Zone colors, transparency, and display limits are configurable. Panel dimensions, font sizes, margins, and column widths can be adjusted. Label positioning, stagger levels, and spacing are customizable.
Requirements
MetaTrader 5 build 2715 or higher. Broker with economic calendar data enabled. Symbol must contain XAU or GOLD in its name.
