OPEN-SOURCE SCRIPT
Sector RSI (Auto-Select)

This indicator measures the relative strength momentum of any stock against its most closely correlated sector ETF, using the Relative Strength Index (RSI).
Auto sector selection: The script computes correlations between your symbol’s short-term returns and all major SPDR sector ETFs (XLB, XLE, XLF, XLI, XLK, XLP, XLU, XLV, XLY, XTN). The sector with the highest correlation is automatically chosen as the benchmark.
Sector vs Symbol RSI: It calculates RSI (default 14-period) for both the chosen sector and the current chart’s symbol.
Display modes:
Line mode: Plots both RSIs with colored fill (red if the sector RSI is stronger, green if the symbol RSI is stronger).
Histogram mode: Shows the difference between Sector RSI and Symbol RSI as a column chart.
RSI bands: Standard 70/50/30 reference lines are available in line mode.
Status line: The selected sector’s ticker is shown on the TradingView status line so you always know which sector is being used.
Use Cases:
Identify whether a stock’s momentum is driven by its sector or if it’s showing independent relative strength.
Detect sector rotations: when the stock begins to outperform or underperform its sector on momentum basis.
Combine with absolute RSI levels (overbought/oversold) to filter signals.
Notes:
This tool infers sector membership via rolling correlation, not from static classification metadata. This means in some cases (e.g. diversified companies or news shocks) the “best” sector may not be the official one, but the one most correlated in the current market regime.
Use min positive correlation input to filter out weak matches and enforce a fallback (defaults to Technology XLK).
Auto sector selection: The script computes correlations between your symbol’s short-term returns and all major SPDR sector ETFs (XLB, XLE, XLF, XLI, XLK, XLP, XLU, XLV, XLY, XTN). The sector with the highest correlation is automatically chosen as the benchmark.
Sector vs Symbol RSI: It calculates RSI (default 14-period) for both the chosen sector and the current chart’s symbol.
Display modes:
Line mode: Plots both RSIs with colored fill (red if the sector RSI is stronger, green if the symbol RSI is stronger).
Histogram mode: Shows the difference between Sector RSI and Symbol RSI as a column chart.
RSI bands: Standard 70/50/30 reference lines are available in line mode.
Status line: The selected sector’s ticker is shown on the TradingView status line so you always know which sector is being used.
Use Cases:
Identify whether a stock’s momentum is driven by its sector or if it’s showing independent relative strength.
Detect sector rotations: when the stock begins to outperform or underperform its sector on momentum basis.
Combine with absolute RSI levels (overbought/oversold) to filter signals.
Notes:
This tool infers sector membership via rolling correlation, not from static classification metadata. This means in some cases (e.g. diversified companies or news shocks) the “best” sector may not be the official one, but the one most correlated in the current market regime.
Use min positive correlation input to filter out weak matches and enforce a fallback (defaults to Technology XLK).
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。