Page 1 of 1

Dual Volume Divergence Index

PostPosted: Sun Feb 11, 2018 6:38 am
by isamegrelo
Code:


//@version=2
study(title="Dual Volume Divergence Index [DW]", shorttitle="DVDI [DW]")
//by Donovan Wall

//This is an experimental variation of Paul L. Dysart's Positive Volume Index and Negative Volume Index that tracks the divergences between the PVI and its EMA, and the NVI and its EMA, then plots both together for comparison.
//This tool can be used to identify trending price activity.

//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Period
per = input(255, minval=1, title="EMA Period")

//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Rate of Change
roc = roc(close, 1)

//Positive Volume Divergence Index
pvi = volume > volume[1] ? nz(pvi[1]) + roc : nz(pvi[1])
psig = ema(pvi, per)
pdiv = pvi - psig
pcolor = pvi > psig ? lime : pvi < psig ? red : na

//Negative Volume Divergence Index
nvi = volume < volume[1] ? nz(nvi[1]) - roc : nz(nvi[1])
nsig = ema(nvi, per)
ndiv = nvi - nsig
ncolor = nvi < nsig ? lime : nvi > nsig ? red : na

//Divergence Color
dcolor = (pdiv > ndiv) and (pdiv < 0) ? green : (pdiv > ndiv) and (pdiv > 0) ? lime : (ndiv > pdiv) and (ndiv < 0) ? maroon : (ndiv > pdiv) and (ndiv > 0) ? red : na

//Center
cent = 0

//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Plots
//----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Index Center
centplot = plot(cent, color=orange, title="Center Line")

//Index Plots
pplot = plot(pdiv, color=lime, title="PVI Divergence")
nplot = plot(ndiv, color=red, title="NVI Divergence")

//Fills
fill(pplot, nplot, color=dcolor, transp=60)

//Bar Colorization
barcolor(dcolor)

Re: Dual Volume Divergence Index

PostPosted: Mon Feb 12, 2018 9:30 am
by Apprentice