RSI Divergence Pro — Momentum Drop
# RSI Divergence Pro — Momentum Drop
A clean Wilder's RSI with automatic regular bullish and bearish divergence detection. Pivots are scanned on price and confirmed against the RSI to flag exhaustion *before* the move actually reverses.
## What it does
- Plots RSI with overbought (70), oversold (30), and a 50 midline.
- Detects **regular bullish divergence**: price prints a lower low while RSI prints a higher low.
- Detects **regular bearish divergence**: price prints a higher high while RSI prints a lower high.
- Marks each divergence with a triangle on the oscillator at the actual pivot bar.
- Shades the OB/OS zones for quick visual context.
- Fires `alertcondition` events for both bullish and bearish divergences.
## Recommended settings
- RSI Length: **14** (Wilder's smoothing — `ta.rsi`)
- Overbought: **70**
- Oversold: **30**
- Pivot Lookback: **5** bars (confirmation window — higher = fewer, cleaner signals)
- Source: **close**
## Ideal timeframe
Works on any timeframe; sweet spot is the 1H and 4H for swing setups, and 5m/15m for intraday reversal scalps.
## How to use
Wait for a divergence triangle inside or near the OB/OS bands — those are the highest-quality signals. Treat the divergence as a *warning*, not an entry. Pair it with a structure break (trendline, prior swing, or VWAP reclaim) before pulling the trigger. The triangle is plotted with `offset = -pivotLookback` so it appears on the actual pivot bar; signal confirms `pivotLookback` bars later in real time.
## Pine Script v5 code
```
//@version=5
// ─────────────────────────────────────────────
// │ MarketFragments.com | DNA & Market │
// │ info@marketfragments.com │
// │ www.marketfragments.com │
// ─────────────────────────────────────────────
// Time →
// │
// █ █ █│ █
// █ █ █ │ █ █
// █ █ █ │ █ █ █ ╭─╮
// █ █ █ │ █ █ █ █ ╭─╯ ╰─╮
// █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮
// █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮
// █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮
// █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯
// █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯
// █ █ █ │ █ █ █ █ ╰─╮ ╭─╯
// █ █ █ │ █ █ ╰─╮ ╭─╯
// █ █ █ │ █ ╰─────╯
// ──────┴──────────────────────────────────────────────────────────────
// T1 T2 T3 T4 T5 T6
//
// RSI Divergence Pro
// Wilder's RSI with auto-detected regular bullish/bearish divergences.
// Free for non-commercial use. Tweaks and forks welcome.
indicator("MF RSI Divergence Pro", shorttitle="MF RSI Div", overlay=false)
price = input.source(close, "Source")
rsiLen = input.int(14, "RSI Length", minval=1)
ob = input.int(70, "Overbought")
os = input.int(30, "Oversold")
pivotLookback = input.int(5, "Pivot Lookback", minval=1)
rsiVal = ta.rsi(price, rsiLen)
// Oscillator and reference lines
plot(rsiVal, "RSI", color=color.new(#50A0E6, 0), linewidth=2)
hObTop = hline(100, "OB top", display=display.none)
hOb = hline(ob, "OB", color=color.new(color.red, 50), linestyle=hline.style_dashed)
hMid = hline(50, "Mid", color=color.new(color.gray, 30), linestyle=hline.style_dashed)
hOs = hline(os, "OS", color=color.new(color.green, 50), linestyle=hline.style_dashed)
hOsBot = hline(0, "OS bot", display=display.none)
fill(hObTop, hOb, color=color.new(color.red, 90), title="OB fill")
fill(hOs, hOsBot, color=color.new(color.green, 90), title="OS fill")
// Pivot detection
pl = ta.pivotlow(low, pivotLookback, pivotLookback)
ph = ta.pivothigh(high, pivotLookback, pivotLookback)
// Track current + previous pivot price and matching RSI value
var float lastPLPrice = na
var float lastPLRsi = na
var float prevPLPrice = na
var float prevPLRsi = na
var float lastPHPrice = na
var float lastPHRsi = na
var float prevPHPrice = na
var float prevPHRsi = na
if not na(pl)
prevPLPrice := lastPLPrice
prevPLRsi := lastPLRsi
lastPLPrice := pl
lastPLRsi := rsiVal[pivotLookback]
if not na(ph)
prevPHPrice := lastPHPrice
prevPHRsi := lastPHRsi
lastPHPrice := ph
lastPHRsi := rsiVal[pivotLookback]
bullDiv = not na(pl) and not na(prevPLPrice) and pl < prevPLPrice and rsiVal[pivotLookback] > prevPLRsi
bearDiv = not na(ph) and not na(prevPHPrice) and ph > prevPHPrice and rsiVal[pivotLookback] < prevPHRsi
plotshape(bullDiv, "Bull Div", shape.triangleup, location.bottom, color=color.new(color.green, 0), size=size.small, offset=-pivotLookback)
plotshape(bearDiv, "Bear Div", shape.triangledown, location.top, color=color.new(color.red, 0), size=size.small, offset=-pivotLookback)
alertcondition(bullDiv, title="RSI Bullish Divergence", message="MF RSI: Bullish divergence on {{ticker}} {{interval}}")
alertcondition(bearDiv, title="RSI Bearish Divergence", message="MF RSI: Bearish divergence on {{ticker}} {{interval}}")
```
Drop your tweaks, screenshots, and questions below — that's how the library gets better.

