Indicator · Pine Script v4 · On the chart

Multiple Divergences Rework NON-REPAINT by PeterO

by theonetrade· code credited to Peter_O

This indicator evaluates regular and hidden divergences across up to ten technical oscillators, including RSI, MACD, Stochastic, CCI, Momentum, OBV, DIOSC, VW-MACD, and Chaikin Money Flow.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code214
Settings20inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

214 lines of Pine Script v4 from assets/indicator/bit-exact/multiple_divergences_non_repaint_by_petero_LXz2NC1b.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

multiple_divergences_non_repaint_by_petero_LXz2NC1b.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Peter_O
// + huge parts of code by Lonesometheblue and Everget's built-in divergence indicator

//@version=4
study("Multiple divergences rework NON-REPAINT by PeterO", overlay=true)

offset=input(false, "Repaint or not?")
mindivcount=input(2, minval=1, maxval=10, title="Minimum Div Count to Display")

lbR = input(title="Pivot Lookback Right", defval=1)
lbL = input(title="Pivot Lookback Left", defval=3)
off = offset ? lbR : 0
rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=1)
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=true)

// Indicators
calcmacd = input(true, title="MACD")
calcmacda = input(true, title="MACD Histogram")
calcrsi = input(true, title="RSI")
calcstoc = input(true, title="Stochastic")
calccci = input(true, title="CCI")
calcmom = input(true, title="Momentum")
calcobv = input(true, title="OBV")
calcdi = input(true, title="Diosc")
calcvwmacd = input(true, title="VWmacd")
calccmf = input(true, title="Chaikin Money Flow")

// RSI
rsi = rsi(close, 14)
// MACD
[macd, signal, deltamacd] = macd(close, 12, 26, 9)
// Momentum
moment = mom(close, 10)
// CCI
cci = cci(close, 10)
// OBV
obv = cum(change(close) > 0 ? volume : change(close) < 0 ? -volume : 0 * volume)
// Stoch
stk = sma(stoch(close, high, low, 14), 3)
// DIOSC
DI = change(high) - (-change(low))
trur = rma(tr, 14)
diosc = fixnan(100 * rma(DI, 14) / trur)
// volume weighted macd
maFast = vwma(close, 12)
maSlow = vwma(close, 26)
vwmacd = maFast - maSlow
// Chaikin money flow
Cmfm = ((close-low) - (high-close)) / (high - low)
Cmfv = Cmfm * volume
cmf = sma(Cmfv, 21) / sma(volume,21)

plFound(_osc) => not na(pivotlow(_osc, lbL, lbR))
phFound(_osc) => not na(pivothigh(_osc, lbL, lbR))

_inRange(cond) =>
    bars = barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper

// Regular Bullish
oscHL(_osc) => _osc[lbR] > valuewhen(plFound(_osc), _osc[lbR], 1) and _inRange(plFound(_osc)[1]) // Higher Low on indicator
priceLL(_osc) => low[lbR] < valuewhen(plFound(_osc), low[lbR], 1) // Lower Low on Price
bullCond(_osc) => plotBull and priceLL(_osc) and oscHL(_osc) and plFound(_osc)

// Regular Bearish
oscLH(_osc) => _osc[lbR] < valuewhen(phFound(_osc), _osc[lbR], 1) and _inRange(phFound(_osc)[1]) // Lower High on indicator
priceHH(_osc) => high[lbR] > valuewhen(phFound(_osc), high[lbR], 1) // Higher High on Price
bearCond(_osc) => plotBear and priceHH(_osc) and oscLH(_osc) and phFound(_osc)

// Hidden Bullish
oscLL(_osc) => _osc[lbR] < valuewhen(plFound(_osc), _osc[lbR], 1) and _inRange(plFound(_osc)[1]) // Lower Low on indicator
priceHL(_osc) => low[lbR] > valuewhen(plFound(_osc), low[lbR], 1) // Higher Low on Price
hiddenBullCond(_osc) => plotHiddenBull and priceHL(_osc) and oscLL(_osc) and plFound(_osc)

// Hidden Bearish
oscHH(_osc) => _osc[lbR] > valuewhen(phFound(_osc), _osc[lbR], 1) and _inRange(phFound(_osc)[1]) // Higher High on indicator
priceLH(_osc) => high[lbR] < valuewhen(phFound(_osc), high[lbR], 1) // Lower High on Price
hiddenBearCond(_osc) => plotHiddenBear and priceLH(_osc) and oscHH(_osc) and phFound(_osc)


negdivergence = 0
if calcrsi and bearCond(rsi)
    negdivergence := 1
if calcmacd and bearCond(macd)
    negdivergence := negdivergence + 1
if calcmacda and bearCond(deltamacd)
    negdivergence := negdivergence + 1
if calcmom and bearCond(moment)
    negdivergence := negdivergence + 1
if calccci and bearCond(cci)
    negdivergence := negdivergence + 1
if calcobv and bearCond(obv)
    negdivergence := negdivergence + 1
if calcstoc and bearCond(stk)
    negdivergence := negdivergence + 1
if calcdi and bearCond(diosc)
    negdivergence := negdivergence + 1
if calcvwmacd and bearCond(vwmacd)
    negdivergence := negdivergence + 1
if calccmf and bearCond(cmf)
    negdivergence := negdivergence + 1

posdivergence = 0
if calcrsi and bullCond(rsi)
    posdivergence := 1
if calcmacd and bullCond(macd)
    posdivergence := posdivergence + 1
if calcmacda and bullCond(deltamacd)
    posdivergence := posdivergence + 1
if calcmom and bullCond(moment)
    posdivergence := posdivergence + 1
if calccci and bullCond(cci)
    posdivergence := posdivergence + 1
if calcobv and bullCond(obv)
    posdivergence := posdivergence + 1
if calcstoc and bullCond(stk)
    posdivergence := posdivergence + 1
if calcdi and bullCond(diosc)
    posdivergence := posdivergence + 1
if calcvwmacd and bullCond(vwmacd)
    posdivergence := posdivergence + 1
if calccmf and bullCond(cmf)
    posdivergence := posdivergence + 1
    
negdivergencehidden = 0
if calcrsi and hiddenBearCond(rsi)
    negdivergencehidden := 1
if calcmacd and hiddenBearCond(macd)
    negdivergencehidden := negdivergencehidden + 1
if calcmacda and hiddenBearCond(deltamacd)
    negdivergencehidden := negdivergencehidden + 1
if calcmom and hiddenBearCond(moment)
    negdivergencehidden := negdivergencehidden + 1
if calccci and hiddenBearCond(cci)
    negdivergencehidden := negdivergencehidden + 1
if calcobv and hiddenBearCond(obv)
    negdivergencehidden := negdivergencehidden + 1
if calcstoc and hiddenBearCond(stk)
    negdivergencehidden := negdivergencehidden + 1
if calcdi and hiddenBearCond(diosc)
    negdivergencehidden := negdivergencehidden + 1
if calcvwmacd and hiddenBearCond(vwmacd)
    negdivergencehidden := negdivergencehidden + 1
if calccmf and hiddenBearCond(cmf)
    negdivergencehidden := negdivergencehidden + 1
    
posdivergencehidden = 0
if calcrsi and hiddenBullCond(rsi)
    posdivergencehidden := 1
if calcmacd and hiddenBullCond(macd)
    posdivergencehidden := posdivergencehidden + 1
if calcmacda and hiddenBullCond(deltamacd)
    posdivergencehidden := posdivergencehidden + 1
if calcmom and hiddenBullCond(moment)
    posdivergencehidden := posdivergencehidden + 1
if calccci and hiddenBullCond(cci)
    posdivergencehidden := posdivergencehidden + 1
if calcobv and hiddenBullCond(obv)
    posdivergencehidden := posdivergencehidden + 1
if calcstoc and hiddenBullCond(stk)
    posdivergencehidden := posdivergencehidden + 1
if calcdi and hiddenBullCond(diosc)
    posdivergencehidden := posdivergencehidden + 1
if calcvwmacd and hiddenBullCond(vwmacd)
    posdivergencehidden := posdivergencehidden + 1
if calccmf and hiddenBullCond(cmf)
    posdivergencehidden := posdivergencehidden + 1

voffset=5*syminfo.mintick

plotshape(posdivergence==1 and mindivcount<2 ? low[lbR] - voffset : na, offset=-off, title="1 Regular Bullish Div found", text="1", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence==2 and mindivcount<3 ? low[lbR] - voffset : na, offset=-off, title="2 Regular Bullish Divs found", text="2", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence==3 and mindivcount<4 ? low[lbR] - voffset : na, offset=-off, title="3 Regular Bullish Divs found", text="3", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence==4 and mindivcount<5 ? low[lbR] - voffset : na, offset=-off, title="4 Regular Bullish Divs found", text="4", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence==5 and mindivcount<6 ? low[lbR] - voffset : na, offset=-off, title="5 Regular Bullish Divs found", text="5", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence==6 and mindivcount<7 ? low[lbR] - voffset : na, offset=-off, title="6 Regular Bullish Divs found", text="6", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence==7 and mindivcount<8 ? low[lbR] - voffset : na, offset=-off, title="7 Regular Bullish Divs found", text="7", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence==8 and mindivcount<9 ? low[lbR] - voffset : na, offset=-off, title="8 Regular Bullish Divs found", text="8", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)
plotshape(posdivergence>8 and mindivcount<11 ? low[lbR] - voffset : na, offset=-off, title="8+ Regular Bullish Divs found", text="8+", style=shape.labelup, location=location.absolute, color=color.teal, textcolor=color.white, transp=0)

plotshape(negdivergence==1 and mindivcount<2 ? high[lbR] + voffset : na, offset=-off, title="1 Regular Bearish Div found", text="1", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence==2 and mindivcount<3 ? high[lbR] + voffset : na, offset=-off, title="2 Regular Bearish Divs found", text="2", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence==3 and mindivcount<4 ? high[lbR] + voffset : na, offset=-off, title="3 Regular Bearish Divs found", text="3", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence==4 and mindivcount<5 ? high[lbR] + voffset : na, offset=-off, title="4 Regular Bearish Divs found", text="4", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence==5 and mindivcount<6 ? high[lbR] + voffset : na, offset=-off, title="5 Regular Bearish Divs found", text="5", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence==6 and mindivcount<7 ? high[lbR] + voffset : na, offset=-off, title="6 Regular Bearish Divs found", text="6", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence==7 and mindivcount<8 ? high[lbR] + voffset : na, offset=-off, title="7 Regular Bearish Divs found", text="7", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence==8 and mindivcount<9 ? high[lbR] + voffset : na, offset=-off, title="8 Regular Bearish Divs found", text="8", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)
plotshape(negdivergence>8 and mindivcount<11 ? high[lbR] + voffset : na, offset=-off, title="8+ Regular Bearish Divs found", text="8+", style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, transp=0)

plotshape(posdivergencehidden==1 and mindivcount<2 ? low[lbR] - voffset : na, offset=-off, title="1 Hidden Bullish Div found", text="1", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden==2 and mindivcount<3 ? low[lbR] - voffset : na, offset=-off, title="2 Hidden Bullish Divs found", text="2", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden==3 and mindivcount<4 ? low[lbR] - voffset : na, offset=-off, title="3 Hidden Bullish Divs found", text="3", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden==4 and mindivcount<5 ? low[lbR] - voffset : na, offset=-off, title="4 Hidden Bullish Divs found", text="4", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden==5 and mindivcount<6 ? low[lbR] - voffset : na, offset=-off, title="5 Hidden Bullish Divs found", text="5", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden==6 and mindivcount<7 ? low[lbR] - voffset : na, offset=-off, title="6 Hidden Bullish Divs found", text="6", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden==7 and mindivcount<8 ? low[lbR] - voffset : na, offset=-off, title="7 Hidden Bullish Divs found", text="7", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden==8 and mindivcount<9 ? low[lbR] - voffset : na, offset=-off, title="8 Hidden Bullish Divs found", text="8", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)
plotshape(posdivergencehidden>8 and mindivcount<11 ? low[lbR] - voffset : na, offset=-off, title="8+ Hidden Bullish Divs found", text="8+", style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, transp=0)

plotshape(negdivergencehidden==1 and mindivcount<2 ? high[lbR] + voffset : na, offset=-off, title="1 Hidden Bearish Div found", text="1", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden==2 and mindivcount<3 ? high[lbR] + voffset : na, offset=-off, title="2 Hidden Bearish Divs found", text="2", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden==3 and mindivcount<4 ? high[lbR] + voffset : na, offset=-off, title="3 Hidden Bearish Divs found", text="3", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden==4 and mindivcount<5 ? high[lbR] + voffset : na, offset=-off, title="4 Hidden Bearish Divs found", text="4", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden==5 and mindivcount<6 ? high[lbR] + voffset : na, offset=-off, title="5 Hidden Bearish Divs found", text="5", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden==6 and mindivcount<7 ? high[lbR] + voffset : na, offset=-off, title="6 Hidden Bearish Divs found", text="6", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden==7 and mindivcount<8 ? high[lbR] + voffset : na, offset=-off, title="7 Hidden Bearish Divs found", text="7", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden==8 and mindivcount<9 ? high[lbR] + voffset : na, offset=-off, title="8 Hidden Bearish Divs found", text="8", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)
plotshape(negdivergencehidden>8 and mindivcount<11 ? high[lbR] + voffset : na, offset=-off, title="8+ Hidden Bearish Divs found", text="8+", style=shape.labeldown, location=location.absolute, color=color.orange, textcolor=color.white, transp=0)

Overview

Multiple Divergences Rework NON-REPAINT by PeterO compares pivot highs and lows in price against indicator values within a customizable lookback window. Bullish and bearish divergence signals are drawn on the price chart only when a user-defined minimum threshold of concurring indicator divergences is met. Settings allow users to toggle specific oscillators, adjust pivot lookbacks, filter signal counts, and switch between repainting and non-repainting modes.

Details

Published by

theonetrade on GitHub

Code credit

Peter_O, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

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-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Repaint or not?boolfalseoffset
Minimum Div Count to Displayint2mindivcount
Pivot Lookback Rightint1lbR
Pivot Lookback Leftint3lbL
Max of Lookback Rangeint60rangeUpper
Min of Lookback Rangeint1rangeLower
Plot BullishbooltrueplotBull
Plot Hidden BullishbooltrueplotHiddenBull
Plot BearishbooltrueplotBear
Plot Hidden BearishbooltrueplotHiddenBear
MACDbooltruecalcmacd
MACD Histogrambooltruecalcmacda
Show all 20 settings
SettingTypeDefaultVariable
RSIbooltruecalcrsi
Stochasticbooltruecalcstoc
CCIbooltruecalccci
Momentumbooltruecalcmom
OBVbooltruecalcobv
Dioscbooltruecalcdi
VWmacdbooltruecalcvwmacd
Chaikin Money Flowbooltruecalccmf
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

257 stars

This overlay indicator looks for regular price divergences against a set of oscillators, using pivot highs and lows. It compares those pivots with RSI, MACD and its histogram, stochastic, CCI, momentum, OBV, a directional oscillator, volume-weighted MACD, Chai

Indicator v5 DivergenceOscillators & momentum Repaints
Updated 2 months ago · None stated GitHub repository of Snag - Best Futures V3

Price Divergence

by capissimo
114 stars

This indicator detects regular and hidden divergences across multiple technical factors plotted directly on the price chart. It evaluates price highs and lows against peaks and troughs identified by a five-bar fractal mechanism on RSI, RSI Stochastic, MACD, re

Indicator v4 DivergenceOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Price Divergence

RSI Div at dVWAP StDev

by cryptorife
75 stars

This indicator marks RSI divergences only when price trades beyond daily VWAP standard-deviation bands. It compares recent RSI extremes with price highs and lows over a lookback window, and it treats a divergence as valid only while RSI stays beyond overbought

Indicator v4 DivergenceOscillators & momentum Repaints
Updated 3 years ago · GPL-3.0 GitHub repository of RSI Div at dVWAP StDev

This indicator builds a momentum score from the rate of change of close, using a lookback that expands or contracts with ATR relative to its standard deviation. It divides that rate of change by price standard deviation, scales the result, and weights it by vo

Indicator v5 Oscillators & momentumVolatility & bands Repaints
Updated 2 months ago · None stated GitHub repository of Adaptive Volatility-Adjusted Momentum Score
2 stars

Oscillator Workbench — Chart plots a configurable blend of two built-in oscillators and an optional external oscillator on the price chart. It draws a weighted oscillator line and a reference moving average, coloring both by successive up or down states. Users

Indicator v5 Oscillators & momentumMoving averages
Updated 9 months ago · None stated GitHub repository of Oscillator Workbench — Chart [LucF]

More Divergence scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers