Indicator · Pine Script v6 · Own pane

RSI Divergence [trugurpala]

by trugurpala

The RSI Divergence indicator plots the Relative Strength Index in a separate pane with horizontal lines for overbought at 70, mid at 50, and oversold at 30.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code45
Settings5inputs
LicenceMIT
Last update2 months ago3 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

45 lines of Pine Script v6 from examples/indicators/14_rsi_divergence.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

14_rsi_divergence.pine
//@version=6
// RSI Divergence Detector — github.com/trugurpala/pinescriptv6
// Author: Ugur Pala · mail@ugurpala.com
indicator("RSI Divergence [trugurpala]", overlay=false)

// ── Inputs ───────────────────────────────────────────────────────────────────
int   rsiLen   = input.int(14,  "RSI Length",   minval=1)
int   lbR      = input.int(5,   "Pivot Right",  minval=1)
int   lbL      = input.int(5,   "Pivot Left",   minval=1)
int   rangeUpper = input.int(60, "Max Lookback", minval=5)
int   rangeLower = input.int(5,  "Min Lookback", minval=1)

// ── Calculations ─────────────────────────────────────────────────────────────
float rsi = ta.rsi(close, rsiLen)

// RSI pivot noktaları
float rsiPivHigh = ta.pivothigh(rsi,   lbL, lbR)
float rsiPivLow  = ta.pivotlow(rsi,    lbL, lbR)
float pricePivHigh = ta.pivothigh(high, lbL, lbR)
float pricePivLow  = ta.pivotlow(low,   lbL, lbR)

// Bearish Divergence: Fiyat YY ama RSI DD
bool bearDiv = not na(rsiPivHigh) and not na(pricePivHigh) and
    high[lbR] > ta.valuewhen(not na(ta.pivothigh(high, lbL, lbR)), high[lbR], 1) and
    rsi[lbR]  < ta.valuewhen(not na(ta.pivothigh(rsi,  lbL, lbR)), rsi[lbR],  1)

// Bullish Divergence: Fiyat DD ama RSI YY
bool bullDiv = not na(rsiPivLow) and not na(pricePivLow) and
    low[lbR] < ta.valuewhen(not na(ta.pivotlow(low, lbL, lbR)), low[lbR], 1) and
    rsi[lbR] > ta.valuewhen(not na(ta.pivotlow(rsi, lbL, lbR)), rsi[lbR], 1)

// ── Visuals ──────────────────────────────────────────────────────────────────
hline(70, "OB", color.new(color.red,   40), hline.style_dashed)
hline(50, "Mid",color.new(color.gray,  60), hline.style_dotted)
hline(30, "OS", color.new(color.green, 40), hline.style_dashed)

plot(rsi, "RSI", color.new(color.blue, 20), linewidth=2)

plotshape(bearDiv, "Bear Div",
    shape.triangledown, location.abovebar, color.red,   size=size.small)
plotshape(bullDiv, "Bull Div",
    shape.triangleup,   location.belowbar, color.green, size=size.small)

alertcondition(bearDiv, "Bearish Divergence", "RSI Bearish Div — {{ticker}}")
alertcondition(bullDiv, "Bullish Divergence", "RSI Bullish Div — {{ticker}}")

Overview

RSI Divergence [trugurpala] detects bullish divergence when price forms a lower low but RSI forms a higher low, marked by a green upward triangle. Bearish divergence appears when price makes a higher high but RSI a lower high, shown with a red downward triangle. The script uses inputs to set RSI length, pivot left and right bars, and lookback ranges for searches. It sends alerts for both divergence types but provides no exit rules or stop loss as it is a non-strategy indicator.

Details

Published by

trugurpala on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Divergence

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

aialgorithmic-tradingclaude-codecodexcoding-agentsgithub-copilotopen-sourcepine-scriptpine-script-v6technical-analysis

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Lengthint14rsiLen
Pivot Rightint5lbR
Pivot Leftint5lbL
Max Lookbackint60rangeUpper
Min Lookbackint5rangeLower
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator
330 stars

This indicator calculates the MACD oscillator from a configurable source with fast and slow lengths, then plots the histogram, MACD line, and signal line in a separate pane. It detects regular bullish divergences (price lower lows with oscillator higher lows),

Indicator v5 Oscillators & momentumDivergence
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]
218 stars

This indicator calculates the Relative Strength Index (RSI) across four user-selected timeframes and plots the results in a separate pane. It identifies regular bullish and bearish divergences between price pivot points and the primary timeframe RSI value. Add

Indicator v6 Oscillators & momentumDivergence
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe RSI with Divergence

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

RSI [SystemAlpha]

by iamc1oud
56 stars

This indicator plots a standard Relative Strength Index (RSI) in a separate pane alongside customizable overbought and oversold threshold levels with shaded fills. It identifies pivot highs and lows on the oscillator to detect regular and hidden bullish and be

Indicator v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of RSI [SystemAlpha]
55 stars

This indicator calculates a 14-period RSI from close and plots it in a separate pane with dotted overbought and dashed oversold lines at 70 and 30. It marks bullish divergence when a five-bar pivot low in price is lower than the price twenty bars earlier while

Indicator v6 Oscillators & momentumDivergence
Updated 6 months ago · Apache-2.0 GitHub repository of RSI Divergence Detector

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers