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).
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.