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
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.