Securely Redirecting...

Connecting to Stripe

Pine Script v5 TradingView Macro Indicators

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.

5 ready-to-use templates
https://fxmacrodata.com/api/v1/
Updated on each release

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.

# Example: fetch USD and EUR policy rates with cURL curl "https://fxmacrodata.com/api/v1/announcements/usd/policy_rate?api_key=YOUR_API_KEY" curl "https://fxmacrodata.com/api/v1/announcements/eur/policy_rate?api_key=YOUR_API_KEY"

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

// FXMacroData — Policy Rate Differential // Source: https://fxmacrodata.com/api/v1/announcements/{currency}/policy_rate // Pine Script v5 //@version=5 indicator("FXMacroData: Policy Rate Differential", overlay=true, max_lines_count=10) // ── Inputs (enter values from FXMacroData API) ────────────────────────────── base_rate = input.float(5.25, title="Base Currency Rate (%)", step=0.25) quote_rate = input.float(4.50, title="Quote Currency Rate (%)", step=0.25) show_label = input.bool(true, title="Show differential label") // ── Calculation ────────────────────────────────────────────────────────────── diff = base_rate - quote_rate col = diff > 0 ? color.new(color.teal, 0) : color.new(color.red, 0) // ── Draw reference line at current price adjusted by spread ───────────────── var ref_line = line.new(bar_index, close, bar_index, close, xloc=xloc.bar_index, extend=extend.right, color=col, width=2, style=line.style_dotted) if barstate.islast line.delete(ref_line) ref_line := line.new(bar_index - 1, close, bar_index, close, extend=extend.right, color=col, width=2, style=line.style_dotted) if show_label label.new(bar_index, close, text = "Rate diff: " + str.tostring(diff, "#.##") + "%", style = label.style_label_left, color = col, textcolor = color.white, size = size.small) // ── Table overlay ──────────────────────────────────────────────────────────── var tbl = table.new(position.top_right, 2, 3, bgcolor=color.new(color.white, 10), border_width=1) if barstate.islast table.cell(tbl, 0, 0, "Base Rate", text_color=color.gray, text_size=size.small) table.cell(tbl, 1, 0, str.tostring(base_rate) + "%", text_color=color.black, text_size=size.small) table.cell(tbl, 0, 1, "Quote Rate", text_color=color.gray, text_size=size.small) table.cell(tbl, 1, 1, str.tostring(quote_rate) + "%", text_color=color.black, text_size=size.small) table.cell(tbl, 0, 2, "Differential", text_color=color.gray, text_size=size.small) table.cell(tbl, 1, 2, str.tostring(diff, "#.##") + "%", text_color=diff >= 0 ? color.teal : color.red, text_size=size.small)

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

// FXMacroData — Inflation Differential Background // Source: https://fxmacrodata.com/api/v1/announcements/{currency}/inflation // Pine Script v5 //@version=5 indicator("FXMacroData: Inflation Differential", overlay=true) // ── Inputs ─────────────────────────────────────────────────────────────────── base_cpi = input.float(3.5, title="Base CPI YoY (%)", step=0.1) quote_cpi = input.float(2.9, title="Quote CPI YoY (%)", step=0.1) target = input.float(2.0, title="Central Bank Target (%)", step=0.1) opacity = input.int (88, title="Background opacity (0–100)", minval=0, maxval=100) // ── Derived values ─────────────────────────────────────────────────────────── diff = base_cpi - quote_cpi base_hot = base_cpi > target quote_hot = quote_cpi > target both_hot = base_hot and quote_hot // ── Background shading ─────────────────────────────────────────────────────── bg_col = both_hot ? color.new(color.orange, opacity) : base_hot ? color.new(color.red, opacity) : quote_hot ? color.new(color.blue, opacity) : color.new(color.green, opacity) bgcolor(bg_col) // ── Label ──────────────────────────────────────────────────────────────────── if barstate.islast label.new(bar_index, high, text = "CPI diff: " + str.tostring(diff, "#.#") + "%\nBase: " + str.tostring(base_cpi) + "% | Quote: " + str.tostring(quote_cpi) + "%", style = label.style_label_down, color = bg_col, textcolor = color.white, size = size.normal)

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}

// FXMacroData — Macro Strength Score (4-factor composite) // Indicators: policy_rate · inflation · unemployment · gdp // Source: https://fxmacrodata.com/api/v1/announcements/{currency}/{indicator} // Pine Script v5 //@version=5 indicator("FXMacroData: Macro Strength Score", overlay=false) // ── Group: Base currency inputs ─────────────────────────────────────────────── b_rate = input.float(5.25, "Base: Policy Rate (%)", group="Base Currency", step=0.25) b_cpi = input.float(3.5, "Base: CPI YoY (%)", group="Base Currency", step=0.1) b_unemp= input.float(3.9, "Base: Unemployment (%)", group="Base Currency", step=0.1) b_gdp = input.float(2.8, "Base: GDP YoY (%)", group="Base Currency", step=0.1) // ── Group: Quote currency inputs ────────────────────────────────────────────── q_rate = input.float(4.50, "Quote: Policy Rate (%)", group="Quote Currency", step=0.25) q_cpi = input.float(2.9, "Quote: CPI YoY (%)", group="Quote Currency", step=0.1) q_unemp= input.float(4.3, "Quote: Unemployment (%)", group="Quote Currency", step=0.1) q_gdp = input.float(1.4, "Quote: GDP YoY (%)", group="Quote Currency", step=0.1) // ── Scoring (higher rate, lower unemployment, higher gdp → bullish base) ───── rate_score = b_rate - q_rate cpi_score = b_cpi - q_cpi // higher CPI → pressure to hike → bullish unemp_score = q_unemp - b_unemp // lower base unemployment → bullish base gdp_score = b_gdp - q_gdp composite = rate_score * 1.5 + cpi_score + unemp_score + gdp_score // ── Plot ───────────────────────────────────────────────────────────────────── hline(0, "Neutral", color=color.gray, linestyle=hline.style_dotted) plot(composite, title="Macro Score", color=composite > 0 ? color.teal : color.red, style=plot.style_columns, linewidth=2)

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.

// FXMacroData — Economic Release Annotation // Source: https://fxmacrodata.com/api/v1/calendar/{currency} // Pine Script v5 //@version=5 indicator("FXMacroData: Economic Release Labels", overlay=true, max_labels_count=20) // ── Inputs ─────────────────────────────────────────────────────────────────── release_date = input.time(timestamp("2025-01-01 14:30"), title="Release date/time (UTC)") release_label = input.string("USD CPI", title="Release label") actual = input.float(3.1, title="Actual (%)", step=0.1) forecast = input.float(3.0, title="Forecast (%)", step=0.1) previous = input.float(3.2, title="Previous (%)", step=0.1) // ── Beat / miss colour ──────────────────────────────────────────────────────── beat = actual > forecast col = beat ? color.new(color.teal, 0) : color.new(color.red, 0) // ── Draw label at the release bar ──────────────────────────────────────────── if time == release_date label.new(bar_index, low, text = release_label + "\n✓ " + str.tostring(actual) + "%" + " (f: " + str.tostring(forecast) + "% / p: " + str.tostring(previous) + "%)", style = beat ? label.style_label_up : label.style_label_down, color = col, textcolor = color.white, size = size.small)

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

// FXMacroData — 10Y Government Bond Yield Spread // Source: https://fxmacrodata.com/api/v1/announcements/{currency}/gov_bond_10y // Pine Script v5 //@version=5 indicator("FXMacroData: 10Y Yield Spread", overlay=false) // ── Inputs ─────────────────────────────────────────────────────────────────── base_yield = input.float(4.60, "Base: 10Y Yield (%)", step=0.01) quote_yield = input.float(3.20, "Quote: 10Y Yield (%)", step=0.01) ma_len = input.int (20, "Signal MA length", minval=2) // ── Spread is a constant from manual inputs; MA is computed over chart bars ── spread = base_yield - quote_yield sig_ma = ta.sma(close, ma_len) // reference moving average on price (not yield) // ── Plot ───────────────────────────────────────────────────────────────────── hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted) spread_plot = plot(spread, title="10Y Spread", color=spread > 0 ? color.teal : color.red, linewidth=2) plot(ta.sma(series_from_end(array.from(spread), 0), ma_len), title="Signal", color=color.orange, linewidth=1, display=display.none) // ── Table ──────────────────────────────────────────────────────────────────── var tbl = table.new(position.bottom_right, 2, 2, bgcolor=color.new(color.white, 15), border_width=1) if barstate.islast table.cell(tbl, 0, 0, "Base 10Y", text_color=color.gray) table.cell(tbl, 1, 0, str.tostring(base_yield, "#.##") + "%") table.cell(tbl, 0, 1, "Quote 10Y", text_color=color.gray) table.cell(tbl, 1, 1, str.tostring(quote_yield, "#.##") + "%")

Fetching values from FXMacroData

Get the latest indicator reading before opening your TradingView chart. USD endpoints are free — no key required.

# Get latest USD policy rate (free — no key required) curl "https://fxmacrodata.com/api/v1/announcements/usd/policy_rate" # Get latest EUR inflation (requires api_key) curl "https://fxmacrodata.com/api/v1/announcements/eur/inflation?api_key=YOUR_API_KEY" # Example response snippet # { "data": [{ "date": "2025-01-29", "val": 4.5, "announcement_datetime": "..." }] }

Supported indicators

Commonly used with Pine Script templates. All available via /v1/announcements/{currency}/{indicator}

Monetary policy

  • policy_rate — Central bank policy rate
  • risk_free_rate — Overnight risk-free rate
  • gov_bond_2y — 2-year government yield
  • gov_bond_10y — 10-year government yield
  • inflation_linked_bond — Real yield proxy

Macro fundamentals

  • inflation — CPI year-on-year
  • core_inflation — Core CPI (ex food/energy)
  • unemployment — Unemployment rate
  • gdp — 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.