OPEN-SOURCE SCRIPT
S&P 500 Weighted Advance/ Decline

This indicator reads the internal health of the S&P 500 by tracking all 11 State Street sector ETFs (XLK, XLF, XLV, etc.) in real time. Instead of just watching price, it tells you who is driving the market and how broad the move really is.
The Two Lines
Histogram (teal/red bars) = "Big Companies that drive the market"
This is a cap-weighted view of all 11 sectors. Each sector is weighted by how big it is in the S&P 500 — so Tech (XLK) at ~31% carries far more influence than Materials (XLB) at ~2%. When the bars are teal, the cap-weighted market is positive from today's open. When red, it's negative. This tells you what the index itself is doing.
White Line = "All sectors get equal vote" This is a simple average of all 11 sectors with equal weight — every sector gets one vote. This tells you what the average sector is doing, regardless of size. This is your breadth reading.
Divergence Line (aqua/orange thin line) = The Gap
This plots the difference between weighted and Unweighted. When it's positive, the weighted are outpacing the unweighted — the index is being carried by a few large sectors. When it's near zero, everything is moving together.
How To Read It
✅ Healthy rally — Histogram is teal AND white line is also above zero, both close together. Broad participation. Safe to be long and trade in the direction of the move.
⚠️ Narrow rally (warning sign) — Histogram is teal but the white line is lagging below it. Only the big sectors (usually Tech or Financials) are carrying the index. The rally lacks breadth and is fragile. Avoid chasing breakouts.
🔄 Rotation signal — Divergence line flips from positive to negative. Money is likely rotating from growth/tech into smaller or defensive sectors. Watch for a trend change.
🔴 Healthy selloff — Histogram is red AND white line is also below zero, both close together. Everything is selling off uniformly. High conviction bearish environment. Avoid longs.
Important Notes
This is an intraday tool. All readings are based on % change from today's open, so the slate resets every session. Apply it to any chart (SPY, SPX, ES). The indicator ignores the chart symbol — it always pulls data from the 11 sector ETFs.
Use it as confirmation, not a trigger. A long setup from your own strategy is stronger when both generals and soldiers are positive. A setup where only generals are positive deserves caution.
On big gap days, the histogram will open far from zero. Focus on whether it's expanding or contracting as the day progresses, not the absolute level.
The single most important thing to watch is the relationship between the histogram and the white line. When they agree, trust the move. When they diverge, be skeptical.
Teal Above zero, close Strong broad rally — trust it
Teal Below zero or lagging Narrow, fragile rally — be careful
Red Below zero, close Broad selloff — stay defensive
Red Above zero Only large caps selling — possible rotation
Either Divergence line widening Breadth breaking down — watch for reversal
The Two Lines
Histogram (teal/red bars) = "Big Companies that drive the market"
This is a cap-weighted view of all 11 sectors. Each sector is weighted by how big it is in the S&P 500 — so Tech (XLK) at ~31% carries far more influence than Materials (XLB) at ~2%. When the bars are teal, the cap-weighted market is positive from today's open. When red, it's negative. This tells you what the index itself is doing.
White Line = "All sectors get equal vote" This is a simple average of all 11 sectors with equal weight — every sector gets one vote. This tells you what the average sector is doing, regardless of size. This is your breadth reading.
Divergence Line (aqua/orange thin line) = The Gap
This plots the difference between weighted and Unweighted. When it's positive, the weighted are outpacing the unweighted — the index is being carried by a few large sectors. When it's near zero, everything is moving together.
How To Read It
✅ Healthy rally — Histogram is teal AND white line is also above zero, both close together. Broad participation. Safe to be long and trade in the direction of the move.
⚠️ Narrow rally (warning sign) — Histogram is teal but the white line is lagging below it. Only the big sectors (usually Tech or Financials) are carrying the index. The rally lacks breadth and is fragile. Avoid chasing breakouts.
🔄 Rotation signal — Divergence line flips from positive to negative. Money is likely rotating from growth/tech into smaller or defensive sectors. Watch for a trend change.
🔴 Healthy selloff — Histogram is red AND white line is also below zero, both close together. Everything is selling off uniformly. High conviction bearish environment. Avoid longs.
Important Notes
This is an intraday tool. All readings are based on % change from today's open, so the slate resets every session. Apply it to any chart (SPY, SPX, ES). The indicator ignores the chart symbol — it always pulls data from the 11 sector ETFs.
Use it as confirmation, not a trigger. A long setup from your own strategy is stronger when both generals and soldiers are positive. A setup where only generals are positive deserves caution.
On big gap days, the histogram will open far from zero. Focus on whether it's expanding or contracting as the day progresses, not the absolute level.
The single most important thing to watch is the relationship between the histogram and the white line. When they agree, trust the move. When they diverge, be skeptical.
Teal Above zero, close Strong broad rally — trust it
Teal Below zero or lagging Narrow, fragile rally — be careful
Red Below zero, close Broad selloff — stay defensive
Red Above zero Only large caps selling — possible rotation
Either Divergence line widening Breadth breaking down — watch for reversal
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.