OPEN-SOURCE SCRIPT
Structural Divergence [Proozac]

Structural Divergence [Proozac] — Pine Script v6 — Overlay Indicator
What It Does
Structural Divergence merges two of the most reliable concepts in technical analysis into a single confluence-based signal: Market Structure (HH/HL/LH/LL, BOS/CHoCH) and RSI/MACD divergence detected precisely at structural swing points — not anywhere on the chart, but exactly where it matters.
Most divergence indicators flag every RSI/price disagreement, drowning traders in low-quality signals. Structural Divergence only calculates divergence at confirmed swing highs and lows, then cross-references it against real structural breaks. A signal only fires when both align.
## How It Works
Swing Detection: identifies significant highs and lows using a configurable pivot length, then labels each one HH, HL, LH, or LL relative to the prior swing of the same type.
BOS / CHoCH: automatically draws Break of Structure and Change of Character lines whenever price closes beyond the last confirmed swing level, tracking trend direction in real time.
Divergence Engine: at every swing high/low, RSI (and optionally MACD histogram, for stricter confirmation) is compared against the prior swing of the same type to detect classic bearish/bullish divergence.
Confluence Signal: when a divergence and a BOS/CHoCH occur within a configurable bar window in the same direction, a triangle signal fires with a built-in alert — filtering out the noise of standalone divergence or structure signals used alone.
Why It's Different
Instead of stacking indicators and hoping for visual confluence, this script computes it algorithmically. The result is fewer, higher-conviction signals: you're not just seeing "RSI diverged" or "structure broke" — you're seeing both happen together, which historically marks higher-probability reversal and continuation zones.
## Settings
Swing Detection Length (pivot sensitivity)
RSI Length
Optional MACD confirmation (stricter mode)
Confluence window (max bars between divergence and structural break)
Full color customization for bullish/bearish elements
Alerts
Two ready-to-use alert conditions: Confluence Buy Signal and Confluence Sell Signal — plug straight into TradingView's alert system or your own webhook automation.
What It Does
Structural Divergence merges two of the most reliable concepts in technical analysis into a single confluence-based signal: Market Structure (HH/HL/LH/LL, BOS/CHoCH) and RSI/MACD divergence detected precisely at structural swing points — not anywhere on the chart, but exactly where it matters.
Most divergence indicators flag every RSI/price disagreement, drowning traders in low-quality signals. Structural Divergence only calculates divergence at confirmed swing highs and lows, then cross-references it against real structural breaks. A signal only fires when both align.
## How It Works
Swing Detection: identifies significant highs and lows using a configurable pivot length, then labels each one HH, HL, LH, or LL relative to the prior swing of the same type.
BOS / CHoCH: automatically draws Break of Structure and Change of Character lines whenever price closes beyond the last confirmed swing level, tracking trend direction in real time.
Divergence Engine: at every swing high/low, RSI (and optionally MACD histogram, for stricter confirmation) is compared against the prior swing of the same type to detect classic bearish/bullish divergence.
Confluence Signal: when a divergence and a BOS/CHoCH occur within a configurable bar window in the same direction, a triangle signal fires with a built-in alert — filtering out the noise of standalone divergence or structure signals used alone.
Why It's Different
Instead of stacking indicators and hoping for visual confluence, this script computes it algorithmically. The result is fewer, higher-conviction signals: you're not just seeing "RSI diverged" or "structure broke" — you're seeing both happen together, which historically marks higher-probability reversal and continuation zones.
## Settings
Swing Detection Length (pivot sensitivity)
RSI Length
Optional MACD confirmation (stricter mode)
Confluence window (max bars between divergence and structural break)
Full color customization for bullish/bearish elements
Alerts
Two ready-to-use alert conditions: Confluence Buy Signal and Confluence Sell Signal — plug straight into TradingView's alert system or your own webhook automation.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.