OPEN-SOURCE SCRIPT

Divergences v2.4 [LTB][SPTG]

131
Open-source credit & license
Original author: LonesomeTheBlue.
This fork by: sirpipthegreat — with attribution to the original work.
License: Open-source, published under the MPL-2.0 (same license header in the code).
I am publishing this open-source in accordance with TradingView’s Open-source reuse rules.

What’s new:
- Fixes & stability (addresses “historical offset beyond buffer” errors)
- Capped and validated all historical indexing with guarded lookbacks (e.g., min(…, 200) style limits) to prevent referencing data beyond the buffer on shorter histories/thin symbols.
- Refactored highest/lowest bars scans to obey the cap and avoid cumulative overflows on long sessions.
- Added per-bar counters with safety clamps to ensure it never exceeds available history.
- Ensured HTF switching doesn’t create invalid offsets when the higher timeframe compresses history.

Modernization & user control:
- Pine v6 upgrade and re-organization of logic for clarity/performance.
- More predictable tops/bottoms detection.

What it does:
- Detects regular (trend-reversal) and optional hidden (trend-continuation) divergences between price swing tops/bottoms and the selected oscillator(s).
- Computes candidate pivots with a light HTF alignment to reduce micro-noise; validates divergence when oscillator and price move in opposite directions across those pivots.
- Plots colored lines/labels on price to highlight bearish (regular & hidden) and bullish (regular & hidden) patterns.

How to use:
- Choose the oscillator set you trust (start with RSI + MACD).
- Consider confluence (S/R, volume, trend filters). This tool only identifies conditions

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.