OPEN-SOURCE SCRIPT

Yield Curve Regime Shading with Legend

201
Takes two symbols (e.g. two futures contracts, two FX pairs, etc.) as inputs.

Calculates the “regime” as the sign of the change in their difference over an n‑period lookback.

Lets you choose whether you want to color the bars themselves or shade the background.

How it works
Inputs

symbolA, symbolB: the two tickers you’re comparing.

n: lookback in bars to measure the change in the spread.

mode: pick between “Shading” or “Candle Color”.

Data fetching

We use request.security() to pull each series at the chart’s timeframe.

Regime calculation

spread = priceA – priceB

spreadPrev = ta.valuewhen(not na(spread), spread[n], 0) (i.e. the spread n bars ago)

If spread > spreadPrev → bullish regime

If spread < spreadPrev → bearish regime

Plotting

Shading: apply bgcolor() in green/red.

Candle Color: use barcolor() to override the bar color.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.