Code Library / RSI Strategies

Pine Script RSI Divergence

Detect bullish and bearish RSI divergences on TradingView.

Language: Pine Script · Category: RSI Strategies · Tags: RSI, divergence, Pine Script, TradingView, signal

Source code

//@version=5
indicator("RSI Divergence",overlay=false)
rsi=ta.rsi(close,14)
pL=ta.pivotlow(rsi,5,5); pH=ta.pivothigh(rsi,5,5)
plot(rsi,"RSI",color.purple); hline(70); hline(30)
plotshape(not na(pL),"PivLow",shape.triangleup,location.bottom,color.green,offset=-5)

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.

Related snippets