Dual Volume Divergence Index QQE[DVDIQQE] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
pj0LcLv.png

Author Message:
his is an experimental study inspired by the Quantitative Qualitative Estimation indicator designed to identify trend and wave activity.

In this study, rather than using RSI for the calculation, the Dual Volume Divergence Index oscillator is utilized.
First, the DVDI oscillator is calculated by taking the difference between PVI and its EMA , and NVI and its EMA , then taking the difference between the two results.
Optional parameters for DVDI calculation are included within this script:
  • An option to use tick volume rather than real volume for the volume source
  • An option to use cumulative data, which sums the movements of the oscillator from the beginning to the end of TradingView's maximum window to give a more broad picture of market sentiment

Next, two trailing levels are calculated using the average true range of the oscillator. The levels are then used to determine wave direction.
Lastly, rather than using 0 as the center line, it is instead calculated by taking a cumulative average of the oscillator.

Custom bar colors are included.

CODE:
CSS:
#//@version=4
#study("Dual Volume Divergence Index Quantitative Qualitative Estimation [DW]", shorttitle="DVDIQQE [DW]", overlay=false)
#//by Donovan Wall
# Converted by Sam4Cok@Samer800 - 12/2022
declare lower;
#//Source
input BarColor = yes;
input ShowHistogram = yes;
input src = close;
input per   = 13;       # "Sampling Period"
input smper = 6;        # "Smoothing Period"
input fmult = 2.618;    # "Fast Trailing Level Range Multiplier"
input smult = 4.236;    # "Slow Trailing Level Range Multiplier"
input center_type = {Default Static, Dynamic};    # "Center Line Type"
input vol_type = {default Normal, Tick};          # "Volume Type"

#---- Calc
def na = Double.NaN;
#--- Color
DefineGlobalColor("exHi", CreateColor(5,255,166));
DefineGlobalColor("Hi"  , CreateColor(0,148,95));
DefineGlobalColor("exLo", CreateColor(255,10,112));
DefineGlobalColor("Lo"  , CreateColor(153,0,64));
DefineGlobalColor("Blue5"  , CreateColor(17,231,242));
#####  Script
script nz {
    input data         = 0;
    input replacement  = 0;
    def ret_val = if IsNaN(data) then replacement else data;
    plot return = ret_val;
}
#EMA(x, t)=>
script EMA {
    input x = close;
    input t = 10;
    def EMA;
    EMA = if(isNaN(EMA[1]) or EMA[1]==0, x , (x - EMA[1])*(2/(t + 1)) + EMA[1]);
    plot return = EMA;
}
#//Dual Volume Divergence Index Function
#DVDI(x, t1, t2, v_type)=>
script DVDI {
    input x = close;
    input t1 = 0;
    input t2 = 0;
    input v_type = "Normal";
    def tick = TickValue();
    def rng  = close - open;
    def tickrng;
    tickrng = if isNaN(tickrng[1]) or tickrng[1]==0 then tick else
              If(AbsValue(rng) < tick, tickrng[1], rng);
    def tickvol  = AbsValue(tickrng) / tick;
    def vol      = If(v_type == "Normal", (If(IsNaN(volume) or volume==0, tickvol, volume)), tickvol);
    def PVI;
    PVI     = If(vol > nz(vol[1],vol), PVI[1] + (x - nz(x[1],x)), PVI[1]);
    def psig     = EMA(PVI, t1);
    def pdiv     = EMA(PVI - psig, t2);
    def NVI;
    NVI     = If(vol < nz(vol[1],vol), NVI[1] - (x - nz(x[1],x)), NVI[1]);
    def nsig     = EMA(NVI, t1);
    def ndiv     = EMA(NVI - nsig, t2);
    def DVDI     = pdiv - ndiv;
    plot Return = DVDI;
}
#//Trailing Level Function
script tl {
input x = close;
input t = 13;
input m = 2.618;
    def wper  = (t*2) - 1;
    def rng   = AbsValue(x - x[1]);
    def avrng = EMA(rng, wper);
    def smrng = EMA(avrng, wper)*m;
    def tl;
    tl  =  if(x > nz(tl[1],x),(if((x - smrng) < nz(tl[1],x), nz(tl[1],x), (x - smrng))),
           (if((x + smrng) > nz(tl[1],x), nz(tl[1],x), (x + smrng))));
plot return = tl;
}
#//Cumulative Average Function
script cmean {
input x = close;
    def xsum;
    xsum   = nz(xsum[1]) + x;
    def tsum;
    tsum   = nz(tsum[1]) + 1;
    def cmean    = xsum/tsum;
  plot return = cmean;
}
#//DVDI Oscillator
def dvdi = DVDI(src, per, smper, vol_type);

#//Trailing Levels
def ftl = tl(dvdi, per, fmult);
def stl = tl(dvdi, per, smult);

#//Center Line
def center = if(center_type==center_type.Dynamic,cmean(dvdi),if(isNaN(close),na,0));

#//Colors
def dcolor = if (dvdi > ftl) and (dvdi > stl) and (dvdi > center) then 2 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi > center)  then 1 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi < center) then -2 else
             if (dvdi > ftl) and (dvdi > stl) and (dvdi < center) then -1 else 0;
def ccolor = if center > center[1] then 1 else
             if center < center[1] then -1 else 0;

#//Trailing Level Plots
plot stlplot = stl;    # "Slow Trailing Level"
stlplot.SetDefaultColor(Color.MAGENTA);

plot ftlplot = ftl;    # "Fast Trailing Level"
ftlplot.SetDefaultColor(Color.CYAN);
#//Trailing Levels Fill
AddCloud(ftlplot, stlplot, Color.CYAN, Color.MAGENTA); # "Trailing Zone Fill"

#//Center Line Plot
plot centerplot = center;        # "Center Line"
centerplot.AssignValueColor(if ccolor>0 then Color.GREEN else
                            if ccolor<0 then Color.RED else Color.DARK_GRAY);
#//DVDI Oscillator Plot
plot dvdiplot = dvdi;    #"DVDI Oscillator"
dvdiplot.SetLineWeight(2);
dvdiplot.SetHiding(!ShowHistogram);
dvdiplot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
dvdiplot.AssignValueColor(if dcolor==2 then GlobalColor("exHi") else
                          if dcolor==1 then GlobalColor("Hi") else
                          if dcolor==-2 then GlobalColor("exLo") else
                          if dcolor==-1 then GlobalColor("Lo") else Color.GRAY);
dvdiplot.SetLineWeight(3);

#//----DVDI Fill

AddCloud(centerplot,0, Color.GRAY, Color.GRAY);

#//Bar Color
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if dcolor==2 then GlobalColor("exHi") else
                 if dcolor==1 then GlobalColor("Hi") else
                 if dcolor==-2 then GlobalColor("exLo") else
                 if dcolor==-1 then GlobalColor("Lo") else Color.GRAY);

#---END CODE
 
Last edited by a moderator:
@samer800
Thanks for innovative thinking and creating this indicator! :)
pj0LcLv.png

Author Message:
his is an experimental study inspired by the Quantitative Qualitative Estimation indicator designed to identify trend and wave activity.

In this study, rather than using RSI for the calculation, the Dual Volume Divergence Index oscillator is utilized.
First, the DVDI oscillator is calculated by taking the difference between PVI and its EMA , and NVI and its EMA , then taking the difference between the two results.
Optional parameters for DVDI calculation are included within this script:
  • An option to use tick volume rather than real volume for the volume source
  • An option to use cumulative data, which sums the movements of the oscillator from the beginning to the end of TradingView's maximum window to give a more broad picture of market sentiment

Next, two trailing levels are calculated using the average true range of the oscillator. The levels are then used to determine wave direction.
Lastly, rather than using 0 as the center line, it is instead calculated by taking a cumulative average of the oscillator.

Custom bar colors are included.

CODE:
CSS:
#//@version=4
#study("Dual Volume Divergence Index Quantitative Qualitative Estimation [DW]", shorttitle="DVDIQQE [DW]", overlay=false)
#//by Donovan Wall
# Converted by Sam4Cok@Samer800 - 12/2022
declare lower;
#//Source
input BarColor = yes;
input ShowHistogram = yes;
input src = close;
input per   = 13;       # "Sampling Period"
input smper = 6;        # "Smoothing Period"
input fmult = 2.618;    # "Fast Trailing Level Range Multiplier"
input smult = 4.236;    # "Slow Trailing Level Range Multiplier"
input center_type = {Default Static, Dynamic};    # "Center Line Type"
input vol_type = {default Normal, Tick};          # "Volume Type"

#---- Calc
def na = Double.NaN;
#--- Color
DefineGlobalColor("exHi", CreateColor(5,255,166));
DefineGlobalColor("Hi"  , CreateColor(0,148,95));
DefineGlobalColor("exLo", CreateColor(255,10,112));
DefineGlobalColor("Lo"  , CreateColor(153,0,64));
DefineGlobalColor("Blue5"  , CreateColor(17,231,242));
#####  Script
script nz {
    input data         = 0;
    input replacement  = 0;
    def ret_val = if IsNaN(data) then replacement else data;
    plot return = ret_val;
}
#EMA(x, t)=>
script EMA {
    input x = close;
    input t = 10;
    def EMA;
    EMA = if(isNaN(EMA[1]) or EMA[1]==0, x , (x - EMA[1])*(2/(t + 1)) + EMA[1]);
    plot return = EMA;
}
#//Dual Volume Divergence Index Function
#DVDI(x, t1, t2, v_type)=>
script DVDI {
    input x = close;
    input t1 = 0;
    input t2 = 0;
    input v_type = "Normal";
    def tick = TickValue();
    def rng  = close - open;
    def tickrng;
    tickrng = if isNaN(tickrng[1]) or tickrng[1]==0 then tick else
              If(AbsValue(rng) < tick, tickrng[1], rng);
    def tickvol  = AbsValue(tickrng) / tick;
    def vol      = If(v_type == "Normal", (If(IsNaN(volume) or volume==0, tickvol, volume)), tickvol);
    def PVI;
    PVI     = If(vol > nz(vol[1],vol), PVI[1] + (x - nz(x[1],x)), PVI[1]);
    def psig     = EMA(PVI, t1);
    def pdiv     = EMA(PVI - psig, t2);
    def NVI;
    NVI     = If(vol < nz(vol[1],vol), NVI[1] - (x - nz(x[1],x)), NVI[1]);
    def nsig     = EMA(NVI, t1);
    def ndiv     = EMA(NVI - nsig, t2);
    def DVDI     = pdiv - ndiv;
    plot Return = DVDI;
}
#//Trailing Level Function
script tl {
input x = close;
input t = 13;
input m = 2.618;
    def wper  = (t*2) - 1;
    def rng   = AbsValue(x - x[1]);
    def avrng = EMA(rng, wper);
    def smrng = EMA(avrng, wper)*m;
    def tl;
    tl  =  if(x > nz(tl[1],x),(if((x - smrng) < nz(tl[1],x), nz(tl[1],x), (x - smrng))),
           (if((x + smrng) > nz(tl[1],x), nz(tl[1],x), (x + smrng))));
plot return = tl;
}
#//Cumulative Average Function
script cmean {
input x = close;
    def xsum;
    xsum   = nz(xsum[1]) + x;
    def tsum;
    tsum   = nz(tsum[1]) + 1;
    def cmean    = xsum/tsum;
  plot return = cmean;
}
#//DVDI Oscillator
def dvdi = DVDI(src, per, smper, vol_type);

#//Trailing Levels
def ftl = tl(dvdi, per, fmult);
def stl = tl(dvdi, per, smult);

#//Center Line
def center = if(center_type==center_type.Dynamic,cmean(dvdi),if(isNaN(close),na,0));

#//Colors
def dcolor = if (dvdi > ftl) and (dvdi > stl) and (dvdi > center) then 2 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi > center)  then 1 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi < center) then -2 else
             if (dvdi > ftl) and (dvdi > stl) and (dvdi < center) then -1 else 0;
def ccolor = if center > center[1] then 1 else
             if center < center[1] then -1 else 0;

#//Trailing Level Plots
plot stlplot = stl;    # "Slow Trailing Level"
stlplot.SetDefaultColor(Color.MAGENTA);

plot ftlplot = ftl;    # "Fast Trailing Level"
ftlplot.SetDefaultColor(Color.CYAN);
#//Trailing Levels Fill
AddCloud(ftlplot, stlplot, Color.CYAN, Color.MAGENTA); # "Trailing Zone Fill"

#//Center Line Plot
plot centerplot = center;        # "Center Line"
centerplot.AssignValueColor(if ccolor>0 then Color.GREEN else
                            if ccolor<0 then Color.RED else Color.DARK_GRAY);
#//DVDI Oscillator Plot
plot dvdiplot = dvdi;    #"DVDI Oscillator"
dvdiplot.SetLineWeight(2);
dvdiplot.SetHiding(!ShowHistogram);
dvdiplot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
dvdiplot.AssignValueColor(if dcolor==2 then GlobalColor("exHi") else
                          if dcolor==1 then GlobalColor("Hi") else
                          if dcolor==-2 then GlobalColor("exLo") else
                          if dcolor==-1 then GlobalColor("Lo") else Color.GRAY);
dvdiplot.SetLineWeight(3);

#//----DVDI Fill

AddCloud(centerplot,0, Color.GRAY, Color.GRAY);

#//Bar Color
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if dcolor==2 then GlobalColor("exHi") else
                 if dcolor==1 then GlobalColor("Hi") else
                 if dcolor==-2 then GlobalColor("exLo") else
                 if dcolor==-1 then GlobalColor("Lo") else Color.GRAY);

#---END CODE
 
pj0LcLv.png

Author Message:
his is an experimental study inspired by the Quantitative Qualitative Estimation indicator designed to identify trend and wave activity.

In this study, rather than using RSI for the calculation, the Dual Volume Divergence Index oscillator is utilized.
First, the DVDI oscillator is calculated by taking the difference between PVI and its EMA , and NVI and its EMA , then taking the difference between the two results.
Optional parameters for DVDI calculation are included within this script:
  • An option to use tick volume rather than real volume for the volume source
  • An option to use cumulative data, which sums the movements of the oscillator from the beginning to the end of TradingView's maximum window to give a more broad picture of market sentiment

Next, two trailing levels are calculated using the average true range of the oscillator. The levels are then used to determine wave direction.
Lastly, rather than using 0 as the center line, it is instead calculated by taking a cumulative average of the oscillator.

Custom bar colors are included.

CODE:
CSS:
#//@version=4
#study("Dual Volume Divergence Index Quantitative Qualitative Estimation [DW]", shorttitle="DVDIQQE [DW]", overlay=false)
#//by Donovan Wall
# Converted by Sam4Cok@Samer800 - 12/2022
declare lower;
#//Source
input BarColor = yes;
input ShowHistogram = yes;
input src = close;
input per   = 13;       # "Sampling Period"
input smper = 6;        # "Smoothing Period"
input fmult = 2.618;    # "Fast Trailing Level Range Multiplier"
input smult = 4.236;    # "Slow Trailing Level Range Multiplier"
input center_type = {Default Static, Dynamic};    # "Center Line Type"
input vol_type = {default Normal, Tick};          # "Volume Type"

#---- Calc
def na = Double.NaN;
#--- Color
DefineGlobalColor("exHi", CreateColor(5,255,166));
DefineGlobalColor("Hi"  , CreateColor(0,148,95));
DefineGlobalColor("exLo", CreateColor(255,10,112));
DefineGlobalColor("Lo"  , CreateColor(153,0,64));
DefineGlobalColor("Blue5"  , CreateColor(17,231,242));
#####  Script
script nz {
    input data         = 0;
    input replacement  = 0;
    def ret_val = if IsNaN(data) then replacement else data;
    plot return = ret_val;
}
#EMA(x, t)=>
script EMA {
    input x = close;
    input t = 10;
    def EMA;
    EMA = if(isNaN(EMA[1]) or EMA[1]==0, x , (x - EMA[1])*(2/(t + 1)) + EMA[1]);
    plot return = EMA;
}
#//Dual Volume Divergence Index Function
#DVDI(x, t1, t2, v_type)=>
script DVDI {
    input x = close;
    input t1 = 0;
    input t2 = 0;
    input v_type = "Normal";
    def tick = TickValue();
    def rng  = close - open;
    def tickrng;
    tickrng = if isNaN(tickrng[1]) or tickrng[1]==0 then tick else
              If(AbsValue(rng) < tick, tickrng[1], rng);
    def tickvol  = AbsValue(tickrng) / tick;
    def vol      = If(v_type == "Normal", (If(IsNaN(volume) or volume==0, tickvol, volume)), tickvol);
    def PVI;
    PVI     = If(vol > nz(vol[1],vol), PVI[1] + (x - nz(x[1],x)), PVI[1]);
    def psig     = EMA(PVI, t1);
    def pdiv     = EMA(PVI - psig, t2);
    def NVI;
    NVI     = If(vol < nz(vol[1],vol), NVI[1] - (x - nz(x[1],x)), NVI[1]);
    def nsig     = EMA(NVI, t1);
    def ndiv     = EMA(NVI - nsig, t2);
    def DVDI     = pdiv - ndiv;
    plot Return = DVDI;
}
#//Trailing Level Function
script tl {
input x = close;
input t = 13;
input m = 2.618;
    def wper  = (t*2) - 1;
    def rng   = AbsValue(x - x[1]);
    def avrng = EMA(rng, wper);
    def smrng = EMA(avrng, wper)*m;
    def tl;
    tl  =  if(x > nz(tl[1],x),(if((x - smrng) < nz(tl[1],x), nz(tl[1],x), (x - smrng))),
           (if((x + smrng) > nz(tl[1],x), nz(tl[1],x), (x + smrng))));
plot return = tl;
}
#//Cumulative Average Function
script cmean {
input x = close;
    def xsum;
    xsum   = nz(xsum[1]) + x;
    def tsum;
    tsum   = nz(tsum[1]) + 1;
    def cmean    = xsum/tsum;
  plot return = cmean;
}
#//DVDI Oscillator
def dvdi = DVDI(src, per, smper, vol_type);

#//Trailing Levels
def ftl = tl(dvdi, per, fmult);
def stl = tl(dvdi, per, smult);

#//Center Line
def center = if(center_type==center_type.Dynamic,cmean(dvdi),if(isNaN(close),na,0));

#//Colors
def dcolor = if (dvdi > ftl) and (dvdi > stl) and (dvdi > center) then 2 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi > center)  then 1 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi < center) then -2 else
             if (dvdi > ftl) and (dvdi > stl) and (dvdi < center) then -1 else 0;
def ccolor = if center > center[1] then 1 else
             if center < center[1] then -1 else 0;

#//Trailing Level Plots
plot stlplot = stl;    # "Slow Trailing Level"
stlplot.SetDefaultColor(Color.MAGENTA);

plot ftlplot = ftl;    # "Fast Trailing Level"
ftlplot.SetDefaultColor(Color.CYAN);
#//Trailing Levels Fill
AddCloud(ftlplot, stlplot, Color.CYAN, Color.MAGENTA); # "Trailing Zone Fill"

#//Center Line Plot
plot centerplot = center;        # "Center Line"
centerplot.AssignValueColor(if ccolor>0 then Color.GREEN else
                            if ccolor<0 then Color.RED else Color.DARK_GRAY);
#//DVDI Oscillator Plot
plot dvdiplot = dvdi;    #"DVDI Oscillator"
dvdiplot.SetLineWeight(2);
dvdiplot.SetHiding(!ShowHistogram);
dvdiplot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
dvdiplot.AssignValueColor(if dcolor==2 then GlobalColor("exHi") else
                          if dcolor==1 then GlobalColor("Hi") else
                          if dcolor==-2 then GlobalColor("exLo") else
                          if dcolor==-1 then GlobalColor("Lo") else Color.GRAY);
dvdiplot.SetLineWeight(3);

#//----DVDI Fill

AddCloud(centerplot,0, Color.GRAY, Color.GRAY);

#//Bar Color
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if dcolor==2 then GlobalColor("exHi") else
                 if dcolor==1 then GlobalColor("Hi") else
                 if dcolor==-2 then GlobalColor("exLo") else
                 if dcolor==-1 then GlobalColor("Lo") else Color.GRAY);

#---END CODE
Have you written a paper on how to use the above indicator? Tks Capt. Bob
 
Have you written a paper on how to use the above indicator? Tks Capt. Bob

The DVDI (the histogram) is used to identify potential trend reversals in the market.
When the DVDI value is positive (above 0) it suggests that there may be a buying opportunity in the market. when negative then a selling opportunity.

The cyan and magenta lines are the range of the oscillator. They can be used as the oversold / overbought levels.

Definitely research more about DVDI before using in trading.
Never use in isolation. Always review multiple timeframes.
 
Last edited:
I have moded the colors and been trading with this on 5 min chart in small cap land. It is one of the better Vol Indys out there thats for sure. I will post the moded code below. I was hoping to have some help on taking it to next level. In small cap land once it lights up bear/selling it most often sells off and lights up green it can spike and go to the moon ! lol. I have it set green to white for Bull strength/weakness but for Bear values i would like to remove the white and keep red/yellow only. This would make it better to pick bull/bear moves and holds by reducing the noise.

Code:
#//@version=4
#study("Dual Volume Divergence Index Quantitative Qualitative Estimation [DW]", shorttitle="DVDIQQE [DW]", overlay=false)
#//by Donovan Wall
# Converted by Sam4Cok@Samer800 - 12/2022
declare lower;

input BarColor = yes;
input ShowHistogram = yes;
input src = close;
input per   = 13;       # "Sampling Period"
input smper = 6;        # "Smoothing Period"
input fmult = 2.618;    # "Fast Trailing Level Range Multiplier"
input smult = 4.236;    # "Slow Trailing Level Range Multiplier"
input center_type = {default Static, Dynamic};    # "Center Line Type"
input vol_type = {default Normal, Tick};          # "Volume Type"

#---- Calc
def na = Double.NaN;
#--- Color
DefineGlobalColor("exHi", CreateColor(5, 255, 166));
DefineGlobalColor("Hi"  , CreateColor(0, 148, 95));
DefineGlobalColor("exLo", CreateColor(255, 10, 112));
DefineGlobalColor("Lo"  , CreateColor(153, 0, 64));
DefineGlobalColor("Blue5"  , CreateColor(17, 231, 242));
#####  Script
script nz {
    input data         = 0;
    input replacement  = 0;
    def ret_val = if IsNaN(data) then replacement else data;
    plot return = ret_val;
}
#EMA(x, t)=>
script EMA {
    input x = close;
    input t = 10;
    def EMA;
    EMA = If(IsNaN(EMA[1]) or EMA[1] == 0, x , (x - EMA[1]) * (2 / (t + 1)) + EMA[1]);
    plot return = EMA;
}
#//Dual Volume Divergence Index Function
#DVDI(x, t1, t2, v_type)=>
script DVDI {
    input x = close;
    input t1 = 0;
    input t2 = 0;
    input v_type = "Normal";
    def tick = TickValue();
    def rng  = close - open;
    def tickrng;
    tickrng = if IsNaN(tickrng[1]) or tickrng[1] == 0 then tick else
              If(AbsValue(rng) < tick, tickrng[1], rng);
    def tickvol  = AbsValue(tickrng) / tick;
    def vol      = If(v_type == "Normal", (If(IsNaN(volume) or volume == 0, tickvol, volume)), tickvol);
    def PVI;
    PVI     = If(vol > nz(vol[1], vol), PVI[1] + (x - nz(x[1], x)), PVI[1]);
    def psig     = EMA(PVI, t1);
    def pdiv     = EMA(PVI - psig, t2);
    def NVI;
    NVI     = If(vol < nz(vol[1], vol), NVI[1] - (x - nz(x[1], x)), NVI[1]);
    def nsig     = EMA(NVI, t1);
    def ndiv     = EMA(NVI - nsig, t2);
    def DVDI     = pdiv - ndiv;
    plot Return = DVDI;
}
#//Trailing Level Function
script tl {
    input x = close;
    input t = 13;
    input m = 2.618;
    def wper  = (t * 2) - 1;
    def rng   = AbsValue(x - x[1]);
    def avrng = EMA(rng, wper);
    def smrng = EMA(avrng, wper) * m;
    def tl;
    tl  =  If(x > nz(tl[1], x), (If((x - smrng) < nz(tl[1], x), nz(tl[1], x), (x - smrng))),
           (If((x + smrng) > nz(tl[1], x), nz(tl[1], x), (x + smrng))));
    plot return = tl;
}
#//Cumulative Average Function
script cmean {
    input x = close;
    def xsum;
    xsum   = nz(xsum[1]) + x;
    def tsum;
    tsum   = nz(tsum[1]) + 1;
    def cmean    = xsum / tsum;
    plot return = cmean;
}
#//DVDI Oscillator
def dvdi = DVDI(src, per, smper, vol_type);

#//Trailing Levels
def ftl = tl(dvdi, per, fmult);
def stl = tl(dvdi, per, smult);

#//Center Line
def center = If(center_type == center_type.Dynamic, cmean(dvdi), If(IsNaN(close), na, 0));

#//Colors
def dcolor = if (dvdi > ftl) and (dvdi > stl) and (dvdi > center) then 2 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi > center)  then 1 else
             if (dvdi < ftl) and (dvdi < stl) and (dvdi < center) then -2 else
             if (dvdi > ftl) and (dvdi > stl) and (dvdi < center) then -1 else 0;
def ccolor = if center > center[1] then 1 else
             if center < center[1] then -1 else 0;

#//Trailing Level Plots
plot stlplot = stl;    # "Slow Trailing Level"
stlplot.SetDefaultColor(Color.MAGENTA);

plot ftlplot = ftl;    # "Fast Trailing Level"
ftlplot.SetDefaultColor(Color.CYAN);
#//Trailing Levels Fill
AddCloud(ftlplot, stlplot, Color.CYAN, Color.MAGENTA); # "Trailing Zone Fill"

#//Center Line Plot
plot centerplot = center;        # "Center Line"
centerplot.AssignValueColor(if ccolor > 0 then Color.GREEN else
                            if ccolor < 0 then Color.RED else Color.DARK_GRAY);
#//DVDI Oscillator Plot
plot dvdiplot = dvdi;    #"DVDI Oscillator"
dvdiplot.SetLineWeight(5);
dvdiplot.SetHiding(!ShowHistogram);
dvdiplot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
dvdiplot.AssignValueColor(if dcolor == 2 then Color.green else
                          if dcolor == 3 then Color.gray  else
                          if dcolor == -2 then Color.RED else
                          if dcolor == -1 then Color.yelLOW else Color.WHITE);
dvdiplot.SetLineWeight(5);

#//----DVDI Fill

AddCloud(centerplot, 0, Color.GRAY, Color.GRAY);

#//Bar Color
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if dcolor == 2 then Color.green else
                 if dcolor == 3 then GlobalColor("Hi") else
                 if dcolor == -2 then Color.RED else
                 if dcolor == -1 then Color.yelLOW else Color.white);

#---END CODE
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
525 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top