indicator · own pane · open source
RSI Divergence Spotter
Running…
Loading chart…
About
RSI with regular divergences marked on the oscillator: price makes a lower low while RSI makes a higher low (bullish), or the opposite (bearish).
Pivots are confirmed right bars later, so signals never repaint — they just arrive a few bars after the turn.
Source code
//@version=5
indicator("RSI Divergence Spotter", overlay=false)
len = input.int(14, "RSI length", minval=2)
left = input.int(5, "Pivot left", minval=1)
right = input.int(5, "Pivot right", minval=1)
r = ta.rsi(close, len)
pl = ta.pivotlow(r, left, right)
ph = ta.pivothigh(r, left, right)
plR = ta.valuewhen(not na(pl), r[right], 1)
plP = ta.valuewhen(not na(pl), low[right], 1)
phR = ta.valuewhen(not na(ph), r[right], 1)
phP = ta.valuewhen(not na(ph), high[right], 1)
bull = not na(pl) and r[right] > plR and low[right] < plP
bear = not na(ph) and r[right] < phR and high[right] > phP
plot(r, "RSI", color=color.purple, linewidth=2)
hline(70, "Overbought", color=color.gray)
hline(30, "Oversold", color=color.gray)
plotshape(bull, "Bullish divergence", style=shape.labelup, location=location.bottom, color=color.green, text="Bull")
plotshape(bear, "Bearish divergence", style=shape.labeldown, location=location.top, color=color.red, text="Bear")
alertcondition(bull, "Bullish divergence", "RSI bullish divergence confirmed")
alertcondition(bear, "Bearish divergence", "RSI bearish divergence confirmed")
No comments yet.
Sign in to comment.