OPEN-SOURCE SCRIPT
Sector Relative Strength

This indicator measures a stock's Real Relative Strength against its sector benchmark, helping you identify stocks that are outperforming or underperforming their sector peers.
The concept is based on the Real Relative Strength methodology popularized by the r/realdaytrading community.
Unlike traditional relative strength calculations that simply compare price ratios, this indicator uses a more sophisticated approach that accounts for volatility through ATR (Average True Range), providing a normalized view of true relative performance.
Key Features
Automatic Sector Detection
Automatically detects your stock's sector using TradingView's built-in sector classification
Maps to the appropriate SPDR Sector ETF (XLK, XLF, XLV, XLY, XLP, XLI, XLE, XLU, XLB, XLC)
Supports all 20 TradingView sectors
Sector ETF Mappings
The indicator automatically compares your stock against:
Technology: XLK (Technology Services, Electronic Technology)
Financials: XLF (Finance sector)
Healthcare: XLV (Health Technology, Health Services)
Consumer Discretionary: XLY (Retail Trade, Consumer Services, Consumer Durables)
Consumer Staples: XLP (Consumer Non-Durables)
Industrials: XLI (Producer Manufacturing, Industrial Services, Transportation, Commercial Services)
Energy: XLE (Energy Minerals)
Utilities: XLU
Materials: XLB (Non-Energy Minerals, Process Industries)
Communications: XLC
Default: SPY (for Miscellaneous or unclassified sectors)
Customizable Settings
Comparison Mode: Choose between automatic sector comparison or custom symbol
Length: Adjustable lookback period (default: 12)
Smoothing: Apply moving average to reduce noise (default: 3)
Visual Clarity
Green line: Stock is outperforming its sector
Red line: Stock is underperforming its sector
Zero baseline: Clear reference point for performance
Clean info box: Shows which ETF you're comparing against
How It Works
The indicator calculates relative strength using the following methodology:
Rolling Price Change: Measures the price movement over the specified length for both the stock and its sector ETF
ATR Normalization: Uses Average True Range to normalize for volatility differences
Power Index: Calculates the sector's strength relative to its volatility
Real Relative Strength: Compares the stock's performance against the sector's power index
Smoothing: Applies a moving average to reduce single-candle spikes
Formula:
Power Index = (Sector Price Change) / (Sector ATR)
RRS = (Stock Price Change - Power Index × Stock ATR) / Stock ATR
Smoothed RRS = SMA(RRS, Smoothing Length)
The concept is based on the Real Relative Strength methodology popularized by the r/realdaytrading community.
Unlike traditional relative strength calculations that simply compare price ratios, this indicator uses a more sophisticated approach that accounts for volatility through ATR (Average True Range), providing a normalized view of true relative performance.
Key Features
Automatic Sector Detection
Automatically detects your stock's sector using TradingView's built-in sector classification
Maps to the appropriate SPDR Sector ETF (XLK, XLF, XLV, XLY, XLP, XLI, XLE, XLU, XLB, XLC)
Supports all 20 TradingView sectors
Sector ETF Mappings
The indicator automatically compares your stock against:
Technology: XLK (Technology Services, Electronic Technology)
Financials: XLF (Finance sector)
Healthcare: XLV (Health Technology, Health Services)
Consumer Discretionary: XLY (Retail Trade, Consumer Services, Consumer Durables)
Consumer Staples: XLP (Consumer Non-Durables)
Industrials: XLI (Producer Manufacturing, Industrial Services, Transportation, Commercial Services)
Energy: XLE (Energy Minerals)
Utilities: XLU
Materials: XLB (Non-Energy Minerals, Process Industries)
Communications: XLC
Default: SPY (for Miscellaneous or unclassified sectors)
Customizable Settings
Comparison Mode: Choose between automatic sector comparison or custom symbol
Length: Adjustable lookback period (default: 12)
Smoothing: Apply moving average to reduce noise (default: 3)
Visual Clarity
Green line: Stock is outperforming its sector
Red line: Stock is underperforming its sector
Zero baseline: Clear reference point for performance
Clean info box: Shows which ETF you're comparing against
How It Works
The indicator calculates relative strength using the following methodology:
Rolling Price Change: Measures the price movement over the specified length for both the stock and its sector ETF
ATR Normalization: Uses Average True Range to normalize for volatility differences
Power Index: Calculates the sector's strength relative to its volatility
Real Relative Strength: Compares the stock's performance against the sector's power index
Smoothing: Applies a moving average to reduce single-candle spikes
Formula:
Power Index = (Sector Price Change) / (Sector ATR)
RRS = (Stock Price Change - Power Index × Stock ATR) / Stock ATR
Smoothed RRS = SMA(RRS, Smoothing Length)
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.