OPEN-SOURCE SCRIPT
Aggiornato Sector Relative Strength

Description
This script compares sector performance relative to the S&P 500. Sector price levels or charts alone can mislead, because they tend to move with the broader market. An increase in a sector’s price does not necessarily indicate strength, as it may simply be following the index.
For more a more reliable picture, the script calculates a ratio between each sector ETF and SPY. If the ratio has increased, the sector has outperformed the index. In case it has declined, the sector has underperformed. If the value is near zero, the sector has moved in line with the index. The sectors are presented in a table and sorted on relative performance.
Calculation Method
The performance is expressed as a percentage change in the ratio over a user-defined lookback period. The default lookback is set to 21 bars, which corresponds to one month on a daily chart. This value can be adopted in the settings to match preferred time period.
Z-Score
In addition to the percentage change, the script calculates a Z-score of the ratio, which measures how far the current value deviates from its recent mean. A high positive Z-score indicates that the ratio is significantly above its average, while a negative value indicates it is below. This normalization allows for comparison between sectors with different price levels or volatility profiles.
Table Columns
- Relative %: The sector's performance relative to SPY over the selected lookback period
- Z-Score: Standardized measure of current performance ratio is relative to its average
- Trend Arrow: Indicates the direction of relative performance up down or flat
Example Interpretation
For example, if XLK shows a 3.7% change, it has outperformed SPY over the selected period. Another sector might show a -2.1% change, which indicates underperformance. While both values shows relative strength or weakness, the Z-score is optional and can provide additional context based on how unusual that performance is compared to the sector's own recent behavior.
Use Case
This approach helps evaluate overall market conditions and supports a top-down method. By starting with sector performance, it becomes easier to identify where the market is showing leadership or weakness. This allows the stock selection process to be more deliberate and can help refine or customize screeners based on certain sectors.
This script compares sector performance relative to the S&P 500. Sector price levels or charts alone can mislead, because they tend to move with the broader market. An increase in a sector’s price does not necessarily indicate strength, as it may simply be following the index.
For more a more reliable picture, the script calculates a ratio between each sector ETF and SPY. If the ratio has increased, the sector has outperformed the index. In case it has declined, the sector has underperformed. If the value is near zero, the sector has moved in line with the index. The sectors are presented in a table and sorted on relative performance.
Calculation Method
The performance is expressed as a percentage change in the ratio over a user-defined lookback period. The default lookback is set to 21 bars, which corresponds to one month on a daily chart. This value can be adopted in the settings to match preferred time period.
Z-Score
In addition to the percentage change, the script calculates a Z-score of the ratio, which measures how far the current value deviates from its recent mean. A high positive Z-score indicates that the ratio is significantly above its average, while a negative value indicates it is below. This normalization allows for comparison between sectors with different price levels or volatility profiles.
Table Columns
- Relative %: The sector's performance relative to SPY over the selected lookback period
- Z-Score: Standardized measure of current performance ratio is relative to its average
- Trend Arrow: Indicates the direction of relative performance up down or flat
Example Interpretation
For example, if XLK shows a 3.7% change, it has outperformed SPY over the selected period. Another sector might show a -2.1% change, which indicates underperformance. While both values shows relative strength or weakness, the Z-score is optional and can provide additional context based on how unusual that performance is compared to the sector's own recent behavior.
Use Case
This approach helps evaluate overall market conditions and supports a top-down method. By starting with sector performance, it becomes easier to identify where the market is showing leadership or weakness. This allows the stock selection process to be more deliberate and can help refine or customize screeners based on certain sectors.
Note di rilascio
* Fixed a script error where values were affected by the chart's timeframe and symbol selection, all calculations now use consistent daily data.* Script is now slightly heavier due to per-symbol daily requests, but is more stable.
* Removed Z-score column to improve clarity and significantly boost performance.
* Added dropdown menu for selecting lookback period (1D to 1Y) instead of manual bar input.
Note di rilascio
LabelsScript open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Technical Trading: Research and Application
stockleave.com/
stockleave.com/
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Technical Trading: Research and Application
stockleave.com/
stockleave.com/
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.