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
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。