Indicator · Pine Script v5 · Own pane

DMI+OBV+RSI

by rajatjpatel· code credited to Hotchachachaaa

A separate-pane tool that merges three studies.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code166
Settings16inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago18 Oct 2022

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

166 lines of Pine Script v5 from DMI+OBV+RSI.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

DMI+OBV+RSI.txt
/// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ©Hotchachachaaa, requested creation by @AceJeff37---Discord @PheonixAlgo(RIP) for at least an approximation of his code for RSI divergence tags.
//@version=5
//
indicator("DMI+OBV+RSI", overlay=false)
//////////////////////////////////////////////////////////////////////

//--------------------------------------------------------------Code Insert----------------------------------------------------------

normalize(_src, _min, _max) => 
    var _historicMin = 10e10
    var _historicMax = -10e10
    _historicMin := math.min(nz(_src, _historicMin), _historicMin)
    _historicMax := math.max(nz(_src, _historicMax), _historicMax)
    _min + (_max - _min) * (_src - _historicMin) / math.max(_historicMax - _historicMin, 10e-10)

normalisedObv = normalize(ta.obv, 0, 50)
smaLength = input(title="OBV SMA length", defval=55)
normalisedOBVsma = ta.sma(normalisedObv, smaLength)
//plot(normalisedObv,  color=color.gray, linewidth=2, title="OBV")
//plot(normalisedOBVsma, color=color.orange, linewidth=1, title="OBV SMA")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
scaling= input.int(title="Scaling factor for OBV",minval=1,defval=1)
hist=(normalisedObv-normalisedOBVsma)*scaling
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))


adxLength = input.int(14, minval=1, title="DI length")
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
[diplus, diminus, adx] = ta.dmi(adxLength, lensig)
adxSma = input.int(2, minval=1, title="ADX SMA length")

normalisedAdx = normalize(ta.sma(adx, adxSma), 0, 100)
normalisedDirPlus = normalize(ta.sma(diplus, adxSma), 0, 100) 
normalisedDirMinus = normalize(ta.sma(diminus, adxSma), 0, 100)
//plot(normalisedAdx, color=normalisedDirPlus[1] > normalisedDirMinus and normalisedDirPlus > normalisedDirMinus ? color.green : color.red, linewidth=2)
//plot(normalisedDirPlus, color=color.green, title="+DI")
//plot(normalisedDirMinus, color=color.red, title="-DI")


secondEdge = hline(70, title="secondEdge")
thirdEdge = hline(50, title="thirdEdge")
fourthEdge = hline(30, title="fourthEdge")


bullColor = color.new(color.lime,25)
bearColor = color.new(color.fuchsia,25)

// Generate a bull gradient when position is 50-100%, bear gradient when position is 0-50%.
bColor = if normalisedDirPlus > normalisedDirMinus
    color.from_gradient(normalisedAdx,0, 100, color.new(bullColor, 100), bullColor)
else
    color.from_gradient(100-normalisedAdx,0, 100, bearColor, color.new(bearColor, 100))

//bgcolor(bColor)
fill(secondEdge, fourthEdge, color=bColor)


////////////////////////////////////RSI Divergence////////////////////////////////////////////////
lenrsidiv = input.int(title="RSI Period", minval=1, defval=14)
srcrsidiv = input(title="RSI Source", defval=close)
lbR = 5
//input(title="Pivot Lookback Right", defval=5)
lbL = 5
//input(title="Pivot Lookback Left", defval=5)
rangeUpper = 60
//input(title="Max of Lookback Range", defval=60)
rangeLower = 5
//input(title="Min of Lookback Range", defval=5)
plotBull = input.bool(title="Plot Bullish", defval=true)
plotHiddenBull = input.bool(title="Plot Hidden Bullish", defval=true)
plotBear = input.bool(title="Plot Bearish", defval=true)
plotHiddenBear = input.bool(title="Plot Hidden Bearish", defval=true)
bearColorrsidiv = color.red
bullColorrsidiv = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
osc = ta.rsi(srcrsidiv, lenrsidiv)

// ### Smoothed MA

showSmma = input.bool(title="Show Moving Average", defval=true, group = "Smoothed MA")

smmaLen = 50
//input(50, minval=1, title="SMMA Length", group = "Smoothed MA")
smmaSrc = osc
smma = 0.0
smma := na(smma[1]) ? ta.sma(smmaSrc, smmaLen) : (smma[1] * (smmaLen - 1) + smmaSrc) / smmaLen
plot(showSmma ? smma : na, linewidth=2, color=color.white)

// End ###

lineColor = (osc > smma) ?color.yellow :  color.yellow

plot(osc, title="RSI", linewidth=2, color=lineColor)
hline(50, title="Middle Line", linestyle=hline.style_solid)
// obLevel = hline(70, title="Overbought", linestyle=hline.style_dotted)
// osLevel = hline(30, title="Oversold", linestyle=hline.style_dotted)
//fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90)

plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Lower Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound
plot(plFound ? osc[lbR] : na,offset=-lbR,title="Regular Bullish",linewidth=2,color=(bullCond ? bullColorrsidiv : noneColor))
plotshape(bullCond ? osc[lbR] : na,offset=-lbR,title="Regular Bullish Label",text=" Bull ",style=shape.labelup,location=location.absolute,color=bullColorrsidiv,textcolor=textColor)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Higher Low
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
plot(plFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond ? hiddenBullColor : noneColor))
plotshape( hiddenBullCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColorrsidiv, textcolor=textColor)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Higher High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCond = plotBear and priceHH and oscLH and phFound
plot(phFound ? osc[lbR] : na, offset=-lbR, title="Regular Bearish", linewidth=2, color=(bearCond ? bearColorrsidiv : noneColor))
plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColorrsidiv, textcolor=textColor)

//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Lower High
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
plot(phFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond ? hiddenBearColor : noneColor))
plotshape(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColorrsidiv, textcolor=textColor)
     
// ### Alerts


if bearCond
    alert("Bearish Divergence")
else if hiddenBearCond
    alert("Hidden Bearish Divergence")
else if bullCond
    alert("Bullish Divergence")
else if hiddenBullCond
    alert("Hidden Bullish Divergence")

obvcrossup = ta.crossover(normalisedObv,normalisedOBVsma)
obvcrossdown = ta.crossunder(normalisedObv,normalisedOBVsma)

plotshape(obvcrossup,  location=location.bottom,  color=color.green, style=shape.triangleup, size = size.small )  
plotshape(obvcrossdown,  location=location.top, color=color.red, style=shape.triangledown, size = size.small )

Overview

A histogram shows normalized On Balance Volume minus its moving average, with different colors for growing and falling bars above and below zero. A shaded band between the 30 and 70 lines uses the directional movement index and ADX to color bullish or bearish pressure by strength. RSI divergence tags mark regular and hidden, bullish and bearish divergences, each with its own toggle. Lengths, smoothing and OBV scaling are adjustable.

Details

Published by

rajatjpatel on GitHub

Code credit

Hotchachachaaa, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Volume, 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.

Settings

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

SettingTypeDefaultVariable
OBV SMA lengthint55smaLength
Above   Growcolor#26A69Acol_grow_above
Fallcolor#B2DFDBcol_fall_above
Below Growcolor#FFCDD2col_grow_below
Fallcolor#FF5252col_fall_below
Scaling factor for OBVint1scaling
DI lengthint14adxLength
ADX Smoothingint14lensig
ADX SMA lengthint2adxSma
RSI Periodint14lenrsidiv
RSI Sourcesourceclosesrcrsidiv
Plot BullishbooltrueplotBull
Show all 16 settings
SettingTypeDefaultVariable
Plot Hidden BullishbooltrueplotHiddenBull
Plot BearishbooltrueplotBear
Plot Hidden BearishbooltrueplotHiddenBear
Show Moving AveragebooltrueshowSmma
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

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

MFI Divergences

by tistaharahap
25 stars

This indicator plots the Money Flow Index in a separate pane and marks regular and hidden bullish and bearish divergences between price pivots and the oscillator. It builds the index from positive and negative money flow, then finds pivot highs and lows using

Indicator v4 Oscillators & momentumVolume
Updated 6 years ago · None stated GitHub repository of MFI Divergences
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 2 days ago · MIT GitHub repository of CVD Bias [WavesUnchained]

DC-B v2.5

by crissrocca
9 stars

This indicator is an oscillator suite inspired by Market Cipher B and VuManChu Cipher B that plots in a separate pane. It combines a WaveTrend oscillator, a Money Flow Index (MFI) area, and an RSI indicator with automatic divergence detection. Visual signals h

Indicator v4 Oscillators & momentumDivergence
Updated 3 years ago · MPL-2.0 GitHub repository of DC-B v2.5

QPulse

by JasonTeixeira
9 stars

QPulse is a multi-factor indicator that draws in a separate pane to evaluate market momentum, volume flow, and volatility dynamics. It calculates volume delta, a cumulative delta proxy, advanced adaptive ATR, and a hybrid volume-weighted RSI with overbought an

Indicator v6 Oscillators & momentumVolatility & bands
Updated 13 days ago · Custom licence GitHub repository of QPulse

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