FXMacroData Pine Script
Bring central bank rates, inflation differentials, and macro strength scores into TradingView. Copy-paste Pine Script v5 templates that accept FXMacroData values as inputs and render them directly on your charts.
Pine Script cannot make HTTP API calls
TradingView's Pine Script v5 is a sandboxed language — it cannot fetch data from external REST APIs at runtime. The templates below use input.float() and input.int() to accept values you fetch from FXMacroData and type in once. Your macro context is then rendered as a persistent overlay on any chart.
How it works
Three steps to add macro context to any TradingView chart.
Fetch your indicator values from FXMacroData
Use the REST API, Python SDK, or the dashboard to pull the latest reading for the indicator you want — policy rate, inflation, unemployment, etc.
Copy a template below into TradingView Pine Editor
Open Pine Editor in TradingView (bottom panel → Pine Editor tab), paste the script, and click Add to chart.
Enter values via the indicator settings panel
The script exposes input fields for each macro value. Enter the numbers you fetched in step 1. The chart updates instantly and persists until you change them.
Pine Script templates
All templates are Pine Script v5. Click a tab to switch between examples.
Policy Rate Differential
Draws a horizontal line for the base/quote central bank rate spread. Works on any FX pair. Data source: /v1/announcements/{currency}/policy_rate
API endpoints: /v1/announcements/usd/policy_rate · /v1/announcements/eur/policy_rate · and 16 more currencies
Inflation Differential
Shades the chart background based on whether base or quote currency has higher inflation. Data source: /v1/announcements/{currency}/inflation
API endpoints: /v1/announcements/usd/inflation · and 17 more currencies
Macro Strength Score
Computes a composite macro score for a currency pair from four indicators. Displayed as a separate pane. Pull all four from /v1/announcements/{currency}/{indicator}
Combine policy_rate, inflation, unemployment, and gdp across any currency pair.
Economic Release Labels
Adds a labelled annotation on the chart for a scheduled economic release. Use /v1/calendar/{currency} to get upcoming announcement dates.
Get upcoming release dates from the Release Calendar endpoint or the Release Calendar dashboard.
Yield Spread
Plots a 10-year government bond yield spread between two countries as a separate pane. Data source: /v1/announcements/{currency}/gov_bond_10y
API: /v1/announcements/usd/gov_bond_10y · /v1/announcements/eur/gov_bond_10y · and more
Fetching values from FXMacroData
Get the latest indicator reading before opening your TradingView chart. USD endpoints are free — no key required.
Supported indicators
Commonly used with Pine Script templates. All available via /v1/announcements/{currency}/{indicator}
Monetary policy
policy_rate— Central bank policy raterisk_free_rate— Overnight risk-free rategov_bond_2y— 2-year government yieldgov_bond_10y— 10-year government yieldinflation_linked_bond— Real yield proxy
Macro fundamentals
inflation— CPI year-on-yearcore_inflation— Core CPI (ex food/energy)unemployment— Unemployment rategdp— GDP growth (annual)trade_balance— Trade balance
Full indicator list: API documentation · Full endpoint reference per currency: Indicator index
Tips & limitations
Values update only when you change the input
Pine Script inputs are static — the indicator shows the same values until you open settings and update them. Refresh your values from FXMacroData after each central bank meeting or major release.
Use the Release Calendar to know when to refresh
The Release Calendar dashboard and /v1/calendar/{currency} endpoint tell you exactly when each indicator is next published, so you know when your Pine Script values become stale.
Save templates to your TradingView account
After pasting a script into Pine Editor, click Save before adding it to your chart. This preserves your entered values across sessions and lets you apply the same indicator to multiple pairs.
Get started
Ready to add macro context to your charts?
USD endpoints are free — no API key required. Subscribe for multi-currency access covering 18 currencies and 60+ indicators.