OPEN-SOURCE SCRIPT

RSI Predictive Divergence

648
RSI Predictive Divergence — Forming Divergence Detector

OVERVIEW
This indicator detects RSI divergences in two stages: a forming stage (early warning) and a confirmed stage (classic pivot-based). The forming stage is the unique component — it uses linear regression slope analysis to identify divergence conditions building up in real time, before a pivot is confirmed.

HOW IT WORKS

1. Slope Calculation
The indicator computes linear regression slopes for both RSI and price over a user-defined lookback period (default 5 bars). The price slope is ATR-normalized so that the comparison works consistently across different instruments and timeframes.

2. Slope Angles
Both slopes are converted to angles in degrees using the arctangent function. This gives a normalized way to compare RSI direction against price direction.

3. Opposition Counter
A counter tracks how many consecutive closed bars show opposing slopes (price down + RSI up = potential bullish divergence; price up + RSI down = potential bearish divergence). When the counter reaches the user-defined threshold (default 5 bars), a forming divergence is flagged.

4. Strength Score (0-100)
A composite score is calculated using three factors:
- Angle difference between RSI and price slopes (50% weight)
- Duration of slope opposition (30% weight)
- RSI zone context — oversold/overbought adds weight (20% weight)
Users can set a minimum strength threshold to filter low-quality signals.

5. Confirmed Divergence
Classic pivot-based divergence detection runs in parallel using RSI pivot highs and lows compared against price pivots. An anti-overlap gate prevents same-type labels from clustering too closely (default 8 bars minimum spacing).

NON-REPAINTING DESIGN
- All slope counters update only on confirmed bars (barstate.isconfirmed)
- Forming signals trigger only after bar close
- Confirmed divergence labels are drawn at the pivot bar, naturally
lagging by the pivot lookback period
- No lookahead_on, no future data access

INPUTS
- RSI Length, Source, Overbought/Oversold levels
- Slope lookback bars and minimum opposite-slope bars
- Minimum strength threshold for forming signals
- Pivot lookback for confirmed divergence
- Anti-overlap spacing between confirmed labels
- Label style: Compact, Icon Only, or Full
- Dashboard position, size, and compact/full mode
- Color customization for bullish, bearish, forming, and neutral states

DASHBOARD
A status table shows RSI value, RSI zone, slope angle difference, and live forming-divergence status with strength meters for both directions. Two display modes: Compact (7 rows) for minimal footprint or Full (10 rows) with detailed slope angles.

ALERTS
Four alert conditions available:
- Forming Bullish Divergence
- Forming Bearish Divergence
- Confirmed Bullish Divergence
- Confirmed Bearish Divergence

HOW TO USE
Forming divergences are early-warning signals — they indicate that divergence conditions are building. Wait for higher strength readings (60+) before acting, and combine with price-action context such as support/resistance, trend, and volume. Confirmed divergences provide
classical pivot-based signals after pivot formation. This indicator works across all timeframes.

NOTES
This is a technical analysis tool intended for educational and informational purposes. Past performance of any divergence signal does not guarantee future results. Always apply proper risk management and combine with your own trading methodology.

CREDITS
Original implementation. Uses standard RSI and pivot logic from TradingView's built-in functions combined with original slope-angle analysis methodology.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.