Indicator · Pine Script v6 · Own pane

Divergence Engine

by jayadevrana

This indicator plots an RSI oscillator in a separate pane with fixed overbought and oversold lines.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code102
Settings6inputs
LicenceMPL-2.0
Last update2 days ago26 Oct 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

102 lines of Pine Script v6 from scripts/divergence-engine.pine.txt, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

divergence-engine.pine.txt
//@version=6
indicator("Divergence Engine", overlay = false, max_bars_back = 500)

rsiLen = input.int(14, "RSI length", minval = 2)
lb = input.int(5, "Pivot bars left", minval = 1)
rb = input.int(5, "Pivot bars right", minval = 1)
minGap = input.int(5, "Min bars between pivots", minval = 1)
maxGap = input.int(60, "Max bars between pivots", minval = 2)
showHidden = input.bool(true, "Show hidden divergences")

rsi = ta.rsi(close, rsiLen)
plot(rsi, "RSI", color.new(color.purple, 0), 2)
hline(70, "Overbought", color.new(color.gray, 40))
hline(30, "Oversold", color.new(color.gray, 40))

type Pivot
    int bar
    float osc
    float price

var array<Pivot> lows = array.new<Pivot>()
var array<Pivot> highs = array.new<Pivot>()

pl = ta.pivotlow(rsi, lb, rb)
ph = ta.pivothigh(rsi, lb, rb)
bool bull = false
bool hBull = false
bool bear = false
bool hBear = false

if not na(pl)
    Pivot c = Pivot.new(bar_index - rb, pl, low[rb])
    n = array.size(lows)
    if n > 0
        for i = n - 1 to 0
            Pivot p = array.get(lows, i)
            gap = c.bar - p.bar
            if gap > maxGap
                break
            if gap >= minGap
                bull := c.price < p.price and c.osc > p.osc
                hBull := showHidden and c.price > p.price and c.osc < p.osc
                break
    array.push(lows, c)
    if array.size(lows) > 20
        array.shift(lows)

if not na(ph)
    Pivot c = Pivot.new(bar_index - rb, ph, high[rb])
    n = array.size(highs)
    if n > 0
        for i = n - 1 to 0
            Pivot p = array.get(highs, i)
            gap = c.bar - p.bar
            if gap > maxGap
                break
            if gap >= minGap
                bear := c.price > p.price and c.osc < p.osc
                hBear := showHidden and c.price < p.price and c.osc > p.osc
                break
    array.push(highs, c)
    if array.size(highs) > 20
        array.shift(highs)

plotshape(bull, "Bull", shape.labelup, location.bottom,
  color.new(color.teal, 0), text = "Bull", textcolor = color.white)
plotshape(bear, "Bear", shape.labeldown, location.top,
  color.new(color.red, 0), text = "Bear", textcolor = color.white)
plotshape(hBull, "H Bull", shape.triangleup, location.bottom,
  color.new(color.teal, 40), text = "H Bull", textcolor = color.teal)
plotshape(hBear, "H Bear", shape.triangledown, location.top,
  color.new(color.red, 40), text = "H Bear", textcolor = color.red)

var int nBull = 0
var int nBear = 0
var int nHBull = 0
var int nHBear = 0
var string lastType = "none"
var int lastBar = na
nBull += bull ? 1 : 0
nBear += bear ? 1 : 0
nHBull += hBull ? 1 : 0
nHBear += hBear ? 1 : 0
if bull or bear or hBull or hBear
    lastBar := bar_index
    lastType := bull ? "Bull" : bear ? "Bear" : hBull ? "H Bull" : "H Bear"

var table t = table.new(position.top_right, 2, 7,
  bgcolor = color.new(color.black, 15), border_width = 1)
row(r, name, val, col) =>
    table.cell(t, 0, r, name, text_color = col)
    table.cell(t, 1, r, val, text_color = color.white)

if barstate.islast
    age = na(lastBar) ? "-" : str.tostring(bar_index - lastBar)
    row(0, "Divergence", "Count", color.white)
    row(1, "Bull", str.tostring(nBull), color.teal)
    row(2, "Bear", str.tostring(nBear), color.red)
    row(3, "H Bull", str.tostring(nHBull), color.teal)
    row(4, "H Bear", str.tostring(nHBear), color.red)
    row(5, "Most recent", lastType, color.yellow)
    row(6, "Age in bars", age, color.yellow)

Overview

Divergence Engine stores confirmed RSI pivot highs and lows, then compares each new pivot with the previous one inside a bar-gap window. A lower price low with a higher RSI low is marked Bull, and a higher price high with a lower RSI high is marked Bear. Hidden divergences can be shown with separate labels. A table counts each type and shows the latest signal and its age in bars. There are no trade entries, exits, or stops.

Details

Published by

jayadevrana on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Divergence, Screeners & dashboards

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

algorithmic-tradingbacktestingema-crossoverpine-scriptpine-script-v6pinescriptrsitechnical-analysistrading-automationtrading-indicators

Settings

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

SettingTypeDefaultVariable
RSI lengthint14rsiLen
Pivot bars leftint5lb
Pivot bars rightint5rb
Min bars between pivotsint5minGap
Max bars between pivotsint60maxGap
Show hidden divergencesbooltrueshowHidden
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 scans a pasted list of symbols for RSI directional momentum and shows matching long and short signals in a table in a separate pane. The user chooses continuous break, continuous retracement, flip break, flip retracement, divergence, or hidden d

Indicator v6 Oscillators & momentumDivergence
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Scanner
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

Oscillator Suite

by TamaraKGreen
46 stars

Oscillator Suite plots a normalised price oscillator in a separate pane and overlays a signal line that can use SMA, EMA, WMA, HMA, RMA, VWMA, T3, ZEMA, KAMA, or GKEMA. It marks bullish and bearish divergences, a smoothed money-flow series, confluence areas an

Indicator v5 Oscillators & momentumDivergence
Updated 7 weeks ago · None stated GitHub repository of Oscillator Suite
11 stars

This indicator plots a smoothed Z-score of cumulative volume delta in a separate pane, showing whether buying or selling pressure is dominant and when the reading enters extreme zones. It marks spot accumulation, climax or exhaustion, and pivot-based price-vol

Indicator v6 Oscillators & momentumVolume Repaints
Updated 7 weeks ago · MIT GitHub repository of CVD Z-Score [NeuNue]
9 stars

This indicator plots a heuristic volume-balance oscillator in a separate pane. It estimates signed volume from the close location inside each bar, multiplies that by volume, and sums the proxy over a rolling window. The sum is scaled between minus one and plus

Indicator v6 VolumeOscillators & momentum
Updated yesterday · MIT GitHub repository of CVD Bias [WavesUnchained]

KARPUZLU-RSI

by Kalumur
4 stars

Calculates a custom-period Relative Strength Index alongside an Exponential Moving Average of the RSI in a separate pane. It identifies pivot highs and lows directly on the RSI plot to highlight trendlines and potential divergence patterns. The area between th

Indicator v5 Oscillators & momentumMoving averages
Updated 2 years ago · None stated GitHub repository of KARPUZLU-RSI

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