OPEN-SOURCE SCRIPT
Yield Spread Macro

Yield Spread Macro — Indicator Guide
What it does
This indicator compares the interest rate differential between two countries against the actual FX price of their currency pair, both plotted on the same normalised scale so they can be directly compared. The core idea is that exchange rates are fundamentally driven by the difference in yields between two economies — when one country's rates are significantly higher than another's, capital tends to flow toward the higher-yielding currency, pushing its price up. This indicator tracks whether the FX price is keeping up with that yield story or diverging from it.
What you're looking at on the chart
Blue line — Yield Spread (z-score)
The interest rate differential between the US and the local country, normalised to show where it sits relative to its own history. Above zero means the spread is above average. Below zero means it has compressed.
Aqua line — FX Price (z-score)
The FX pair price, normalised on the same scale as the spread so the two can be directly compared.
Shaded fill between the lines
The gap between the spread and price. When this gap is wide, the two series have diverged — price is not reflecting what the rate differential is saying.
Coloured line (lime/yellow/orange/red) — Rolling Correlation
This is the most important line on the chart. It measures how closely the yield spread and FX price are actually tracking each other over the selected window. Think of it as a trust meter for the spread signal:
🟢 Above 0.80 — strong alignment, spread is a reliable guide right now
🟡 0.40–0.80 — moderate, use alongside other inputs
🟠 0.20–0.40 — weak, something else is driving the pair
🔴 Below 0.20 — regime shift, the spread relationship has broken down entirely
Green background / ▲ DIV label
The yield spread is rising but price has not caught up yet. If correlation is strong this suggests price may follow higher. If correlation is weak, treat it as a tension signal rather than a directional call.
Red background / ▼ DIV label
The yield spread is falling but price has not caught down yet. Price is elevated relative to where the rate differential says it should be. Same caveat — only a strong correlation makes this actionable.
Horizontal dotted lines
The ±1σ and ±2σ bands show historically stretched levels. When either the spread or price z-score pushes beyond ±2, it is statistically extended relative to the lookback window.
Settings explained
Pair Settings
FX Pair
The currency pair you want to analyse. Options are USDJPY, USDCAD, EURUSD, GBPUSD, AUDUSD. Changing this automatically updates all yield series, breakeven data, and FX price feeds — you don't need to change anything else.
Yield Timeframe
The timeframe used to fetch yield data. Default is Daily. Leaving this at D is recommended regardless of what chart timeframe you are on — yield data is most meaningful and cleanest on a daily basis.
General Settings
Normalization Length
The lookback window for the z-score calculation — how many bars of history the indicator uses to compute the average and standard deviation that everything is measured against.
Lower (20–50) — reactive, reflects recent history only, z-score moves frequently
Default (100) — roughly five months on a daily chart, good medium-term context
Higher (200–300) — structural, slow-moving, only flags genuinely historical extremes
If you are a shorter-term trader bring this down. If you want to see where things sit in a multi-year context bring it up.
Spread EMA Smoothing
Applied to the raw yield spread before it gets z-scored. Yield data can print erratic single-day spikes due to auction flows or data feed quirks. This smooths those out.
Lower (3–5) — close to raw spread, more reactive, more noise
Default (10) — removes day-to-day jitter while still tracking real moves
Higher (20–30) — only responds to sustained shifts in the differential, very smooth
Divergence Settings
Divergence Lookback (bars)
How far back the indicator looks when deciding whether the spread and price are moving in opposite directions. A divergence is flagged when the spread has moved one way and price has moved the other way over this window.
Lower (3–5) — very sensitive, signals fire frequently, more noise
Default (10) — roughly two trading weeks on a daily chart
Higher (20–30) — only flags sustained, structural divergences
Min Z-Score Gap to Flag Div
The minimum difference between the spread z-score and price z-score required before a divergence label appears. This prevents the labels from firing when the two lines are close together and the divergence is trivial.
Lower (0.1–0.2) — more signals, lower quality
Default (0.3) — reasonable filter for meaningful gaps
Higher (0.5+) — only the most extreme divergences get flagged
Correlation Settings
Correlation Length (bars)
The rolling window used to measure how tightly the yield spread and FX price are tracking each other. This is the most important setting to understand.
Lower (20–30) — very reactive, correlation shifts quickly, good for seeing regime changes as they happen but noisy
Default (60) — roughly three months on a daily chart, captures a meaningful regime without being too slow
Higher (120–200) — slow-moving, tells you about the long-run structural relationship rather than the current regime
Plot Correlation Line
Toggle the correlation line on or off. If you find the chart visually busy you can turn this off and rely on the table value instead.
Display Settings
Show Zero Line — the dashed horizontal line at zero. Useful reference for whether z-scores are above or below their historical average.
Show ±1σ / ±2σ — the dotted band lines. Turn off if you want a cleaner chart.
Show Data Table — the data panel in the top right corner showing all live values including FX price, yields, real yield, implied breakeven, spread in basis points, z-scores, divergence status, and correlation reading. Turn off if you don't need it or are using the indicator on a small screen.
How to read it in practice
The right workflow is to check the correlation first, then the divergence, in that order.
Check correlation. If it is below 0.40 the spread is not currently driving the pair and the divergence signals should be treated with scepticism. Something else — geopolitics, intervention risk, risk sentiment — is dominant.
Check the spread z-score. Is the differential historically stretched or compressed? Above +2 or below −2 is a significant reading.
Check the divergence. Is price keeping up with the spread or lagging it? A green divergence with strong correlation means price may have room to catch up higher. A red divergence with strong correlation means price may have room to correct lower.
Use the real yield toggle. Switching between nominal and real yields shows you how much of the spread is being driven by inflation expectations versus actual rate differentials. If the two modes show very different spreads, inflation expectations are a significant part of the story.
The indicator works best on a daily chart with the yield timeframe set to D. It is a macro context tool, not a precise entry signal — it tells you whether the fundamental backdrop supports a directional bias, and how much to trust that signal right now.
What it does
This indicator compares the interest rate differential between two countries against the actual FX price of their currency pair, both plotted on the same normalised scale so they can be directly compared. The core idea is that exchange rates are fundamentally driven by the difference in yields between two economies — when one country's rates are significantly higher than another's, capital tends to flow toward the higher-yielding currency, pushing its price up. This indicator tracks whether the FX price is keeping up with that yield story or diverging from it.
What you're looking at on the chart
Blue line — Yield Spread (z-score)
The interest rate differential between the US and the local country, normalised to show where it sits relative to its own history. Above zero means the spread is above average. Below zero means it has compressed.
Aqua line — FX Price (z-score)
The FX pair price, normalised on the same scale as the spread so the two can be directly compared.
Shaded fill between the lines
The gap between the spread and price. When this gap is wide, the two series have diverged — price is not reflecting what the rate differential is saying.
Coloured line (lime/yellow/orange/red) — Rolling Correlation
This is the most important line on the chart. It measures how closely the yield spread and FX price are actually tracking each other over the selected window. Think of it as a trust meter for the spread signal:
🟢 Above 0.80 — strong alignment, spread is a reliable guide right now
🟡 0.40–0.80 — moderate, use alongside other inputs
🟠 0.20–0.40 — weak, something else is driving the pair
🔴 Below 0.20 — regime shift, the spread relationship has broken down entirely
Green background / ▲ DIV label
The yield spread is rising but price has not caught up yet. If correlation is strong this suggests price may follow higher. If correlation is weak, treat it as a tension signal rather than a directional call.
Red background / ▼ DIV label
The yield spread is falling but price has not caught down yet. Price is elevated relative to where the rate differential says it should be. Same caveat — only a strong correlation makes this actionable.
Horizontal dotted lines
The ±1σ and ±2σ bands show historically stretched levels. When either the spread or price z-score pushes beyond ±2, it is statistically extended relative to the lookback window.
Settings explained
Pair Settings
FX Pair
The currency pair you want to analyse. Options are USDJPY, USDCAD, EURUSD, GBPUSD, AUDUSD. Changing this automatically updates all yield series, breakeven data, and FX price feeds — you don't need to change anything else.
Yield Timeframe
The timeframe used to fetch yield data. Default is Daily. Leaving this at D is recommended regardless of what chart timeframe you are on — yield data is most meaningful and cleanest on a daily basis.
General Settings
Normalization Length
The lookback window for the z-score calculation — how many bars of history the indicator uses to compute the average and standard deviation that everything is measured against.
Lower (20–50) — reactive, reflects recent history only, z-score moves frequently
Default (100) — roughly five months on a daily chart, good medium-term context
Higher (200–300) — structural, slow-moving, only flags genuinely historical extremes
If you are a shorter-term trader bring this down. If you want to see where things sit in a multi-year context bring it up.
Spread EMA Smoothing
Applied to the raw yield spread before it gets z-scored. Yield data can print erratic single-day spikes due to auction flows or data feed quirks. This smooths those out.
Lower (3–5) — close to raw spread, more reactive, more noise
Default (10) — removes day-to-day jitter while still tracking real moves
Higher (20–30) — only responds to sustained shifts in the differential, very smooth
Divergence Settings
Divergence Lookback (bars)
How far back the indicator looks when deciding whether the spread and price are moving in opposite directions. A divergence is flagged when the spread has moved one way and price has moved the other way over this window.
Lower (3–5) — very sensitive, signals fire frequently, more noise
Default (10) — roughly two trading weeks on a daily chart
Higher (20–30) — only flags sustained, structural divergences
Min Z-Score Gap to Flag Div
The minimum difference between the spread z-score and price z-score required before a divergence label appears. This prevents the labels from firing when the two lines are close together and the divergence is trivial.
Lower (0.1–0.2) — more signals, lower quality
Default (0.3) — reasonable filter for meaningful gaps
Higher (0.5+) — only the most extreme divergences get flagged
Correlation Settings
Correlation Length (bars)
The rolling window used to measure how tightly the yield spread and FX price are tracking each other. This is the most important setting to understand.
Lower (20–30) — very reactive, correlation shifts quickly, good for seeing regime changes as they happen but noisy
Default (60) — roughly three months on a daily chart, captures a meaningful regime without being too slow
Higher (120–200) — slow-moving, tells you about the long-run structural relationship rather than the current regime
Plot Correlation Line
Toggle the correlation line on or off. If you find the chart visually busy you can turn this off and rely on the table value instead.
Display Settings
Show Zero Line — the dashed horizontal line at zero. Useful reference for whether z-scores are above or below their historical average.
Show ±1σ / ±2σ — the dotted band lines. Turn off if you want a cleaner chart.
Show Data Table — the data panel in the top right corner showing all live values including FX price, yields, real yield, implied breakeven, spread in basis points, z-scores, divergence status, and correlation reading. Turn off if you don't need it or are using the indicator on a small screen.
How to read it in practice
The right workflow is to check the correlation first, then the divergence, in that order.
Check correlation. If it is below 0.40 the spread is not currently driving the pair and the divergence signals should be treated with scepticism. Something else — geopolitics, intervention risk, risk sentiment — is dominant.
Check the spread z-score. Is the differential historically stretched or compressed? Above +2 or below −2 is a significant reading.
Check the divergence. Is price keeping up with the spread or lagging it? A green divergence with strong correlation means price may have room to catch up higher. A red divergence with strong correlation means price may have room to correct lower.
Use the real yield toggle. Switching between nominal and real yields shows you how much of the spread is being driven by inflation expectations versus actual rate differentials. If the two modes show very different spreads, inflation expectations are a significant part of the story.
The indicator works best on a daily chart with the yield timeframe set to D. It is a macro context tool, not a precise entry signal — it tells you whether the fundamental backdrop supports a directional bias, and how much to trust that signal right now.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.