OPEN-SOURCE SCRIPT
RSI Divergence Strategy v6

What this does
Detects regular and hidden divergences between price and RSI using confirmed RSI pivots. Adds RSIpivot entry gates, a normalized strength + volume filter, optional volume gate, delayed entries, and transparent risk management with rigid SL and activatable trailing. Visuals are throttled for clarity and include a gap-free horizontal RSI gradient.
How it works (simple)
🧮 RSI is calculated on your selected source/period.
📌 RSI pivots are confirmed with left/right lookbacks (lbL/lbR). A pivot becomes final only after lbR bars; before that, it can move (expected).
🔎 The latest confirmed pivot is compared against the previous confirmed pivot within your bar window:
• Regular Bullish = price lower low + RSI higher low
• Hidden Bullish = price higher low + RSI lower low
• Regular Bearish = price higher high + RSI lower high
• Hidden Bearish = price lower high + RSI higher high
💪 Each divergence gets a strength score that multiplies price % change, RSI change, and a volume ratio (Volume SMA / Baseline Volume SMA).
• Set Min divergence strength to filter tiny/noisy signals.
• Turn on the volume gate to require volume ratio ≥ your threshold (e.g., 1.0).
🎯 RSIpivot gating:
• Longs only if RSI at the bullish pivot ≤ 30 (default).
• Shorts only if RSI at the bearish pivot ≥ 70 (default).
⏱ Entry timing:
• Immediate: on divergence confirm (delay = 0).
• Delayed: after N bars if RSI is still valid.
• RSI-only mode: ignore divergences; use RSI thresholds only.
🛡 Risk:
• Rigid SL is placed from average entry.
• Trailing activates only after unrealized gain ≥ threshold; it re-anchors on new highs (long) or new lows (short).
What’s NEW here (vs. the reference) — and why you may care
• Improved pivots + bar window → fewer early/misaligned signals; cleaner drawings.
• RSIpivot gates → entries aligned with true oversold/overbought at the exact decision bar.
• Normalized strength + volume gate → ignore weak or low-volume divergences.
• Delayed entries → require the signal to persist N bars if you want more confirmation.
• Rigid SL + activatable trailing → trailing engages only after a cushion, so it’s less noisy.
• Clutter control + gradient → readable chart with a smooth RSI band look.
Suggested starting values (clear ranges)
• RSIpivot thresholds: LONG ≤ 30 (oversold), SHORT ≥ 70 (overbought).
• Min divergence strength:
0.0 = off
3–6 = moderate filter
7–12 = strict filter for noisy LTFs
• Volume gate (ratio):
1.0 = at least baseline volume
1.2–1.5 = strong-volume only (fewer but cleaner signals)
• Pivot lookbacks:
lbL 1–2, lbR 3–4 (raise lbR to confirm later and reduce noise)
• Bar window (between pivots):
Min 5–10, Max 30–60 (increase Min if you see micro-pivots; increase Max for wider structures)
• Risk:
Rigid SL 2–5% on liquid majors; 5–10% on higher-volatility symbols
Trailing activation 1–3%, trailing 0.5–1.5% are common intraday starts
Plain-text examples
• BTCUSDT 1h → RSI 9, lbL 1, lbR 3, Min strength 5.0, Volume gate 1.0, SL 4.5%, Trail on 2.0%, Trail 1.0%.
• SPY 15m → RSI 8, lbL 1, lbR 3, Min strength 7.0, Volume gate 1.2, SL 3.0%, Trail on 1.5%, Trail 0.8%.
• EURUSD 4h → RSI 14, lbL 2, lbR 4, Min strength 4.0, Volume gate 1.0, SL 2.5%, Trail on 1.0%, Trail 0.5%.
Notes & limitations
• Pivot confirmation means the newest candidate pivot can move until lbR confirms it (expected).
• Results vary by timeframe/symbol/settings; always forward-test.
• Educational tool — no performance or profit claims.
Credits
• RSI by J. Welles Wilder Jr. (1978).
• Reference divergence script by eemani123:
• This version by tagstrading 2025 adds: improved pivot engine, RSIpivot gating, normalized strength + optional volume gate, delayed entries, rigid SL and activatable trailing, and a gap-free RSI gradient.
Detects regular and hidden divergences between price and RSI using confirmed RSI pivots. Adds RSIpivot entry gates, a normalized strength + volume filter, optional volume gate, delayed entries, and transparent risk management with rigid SL and activatable trailing. Visuals are throttled for clarity and include a gap-free horizontal RSI gradient.
How it works (simple)
🧮 RSI is calculated on your selected source/period.
📌 RSI pivots are confirmed with left/right lookbacks (lbL/lbR). A pivot becomes final only after lbR bars; before that, it can move (expected).
🔎 The latest confirmed pivot is compared against the previous confirmed pivot within your bar window:
• Regular Bullish = price lower low + RSI higher low
• Hidden Bullish = price higher low + RSI lower low
• Regular Bearish = price higher high + RSI lower high
• Hidden Bearish = price lower high + RSI higher high
💪 Each divergence gets a strength score that multiplies price % change, RSI change, and a volume ratio (Volume SMA / Baseline Volume SMA).
• Set Min divergence strength to filter tiny/noisy signals.
• Turn on the volume gate to require volume ratio ≥ your threshold (e.g., 1.0).
🎯 RSIpivot gating:
• Longs only if RSI at the bullish pivot ≤ 30 (default).
• Shorts only if RSI at the bearish pivot ≥ 70 (default).
⏱ Entry timing:
• Immediate: on divergence confirm (delay = 0).
• Delayed: after N bars if RSI is still valid.
• RSI-only mode: ignore divergences; use RSI thresholds only.
🛡 Risk:
• Rigid SL is placed from average entry.
• Trailing activates only after unrealized gain ≥ threshold; it re-anchors on new highs (long) or new lows (short).
What’s NEW here (vs. the reference) — and why you may care
• Improved pivots + bar window → fewer early/misaligned signals; cleaner drawings.
• RSIpivot gates → entries aligned with true oversold/overbought at the exact decision bar.
• Normalized strength + volume gate → ignore weak or low-volume divergences.
• Delayed entries → require the signal to persist N bars if you want more confirmation.
• Rigid SL + activatable trailing → trailing engages only after a cushion, so it’s less noisy.
• Clutter control + gradient → readable chart with a smooth RSI band look.
Suggested starting values (clear ranges)
• RSIpivot thresholds: LONG ≤ 30 (oversold), SHORT ≥ 70 (overbought).
• Min divergence strength:
0.0 = off
3–6 = moderate filter
7–12 = strict filter for noisy LTFs
• Volume gate (ratio):
1.0 = at least baseline volume
1.2–1.5 = strong-volume only (fewer but cleaner signals)
• Pivot lookbacks:
lbL 1–2, lbR 3–4 (raise lbR to confirm later and reduce noise)
• Bar window (between pivots):
Min 5–10, Max 30–60 (increase Min if you see micro-pivots; increase Max for wider structures)
• Risk:
Rigid SL 2–5% on liquid majors; 5–10% on higher-volatility symbols
Trailing activation 1–3%, trailing 0.5–1.5% are common intraday starts
Plain-text examples
• BTCUSDT 1h → RSI 9, lbL 1, lbR 3, Min strength 5.0, Volume gate 1.0, SL 4.5%, Trail on 2.0%, Trail 1.0%.
• SPY 15m → RSI 8, lbL 1, lbR 3, Min strength 7.0, Volume gate 1.2, SL 3.0%, Trail on 1.5%, Trail 0.8%.
• EURUSD 4h → RSI 14, lbL 2, lbR 4, Min strength 4.0, Volume gate 1.0, SL 2.5%, Trail on 1.0%, Trail 0.5%.
Notes & limitations
• Pivot confirmation means the newest candidate pivot can move until lbR confirms it (expected).
• Results vary by timeframe/symbol/settings; always forward-test.
• Educational tool — no performance or profit claims.
Credits
• RSI by J. Welles Wilder Jr. (1978).
• Reference divergence script by eemani123:

• This version by tagstrading 2025 adds: improved pivot engine, RSIpivot gating, normalized strength + optional volume gate, delayed entries, rigid SL and activatable trailing, and a gap-free RSI gradient.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.