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).
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.