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.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.