OPEN-SOURCE SCRIPT
Yield Curve Regime Shading with Legend

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.
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.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。