# Directional Volume Indicator

#### ron4bama

##### New member
Where do I find the code for the directional volume indicator

Is this the one you're looking for?

Code:
#Hguru
#I use the settings 5,2,1,1.0, 10,30,30,3,Waverage

declare lower;
input Length = 10;
input Smooth = 3;
input Step = 1;
input colorcandles= yes;

input EffectVolPct = 1.00 ;  # Consider deflting volume for more accurate DVI reading

def Vol = EffectVolPct * volume;
################
def Body = close - open;
def BarRange = high - low;
def RealBarRange = 2 * BarRange - AbsValue(Body);
#Calc NetBar Volume for Bar  .. beware of the odd case of 0 price movement during bar..
def NBV = if BarRange > 0 then volume * Body / RealBarRange else 0;

# Calc Directional Volume .. this will already be scaled to +100/-100
def DV = 100 * WMA (NBV, Length) / WMA(Vol, Length);
def DVO =  if Smooth > 0 then WMA(DV, Smooth) else DV;
plot K_DVO =  if Step > 0 then Round(DVO / Step, 0) * Step else DVO ;

plot BaseLine = 0;
BaseLine.SetDefaultColor (Color.BLUE );
BaseLine.HideTitle ();
BaseLine.HideBubble ();

K_DVO.SetLineWeight (2);
K_DVO.DefineColor("PositiveUp", Color.GREEN);
K_DVO.DefineColor("NegativeDown", Color.RED);
K_DVO.DefineColor("Reverse", Color.ORANGE);
K_DVO.AssignValueColor(if K_DVO >= BaseLine then if K_DVO >= K_DVO[1] then K_DVO.Color("PositiveUp") else K_DVO.Color("Reverse") else if K_DVO <= K_DVO[1] then K_DVO.Color("NegativeDown") else K_DVO.Color("Reverse"));

plot LZ = BaseLine + DeadZone;
LZ.SetStyle (Curve.SHORT_DASH);
LZ.SetDefaultColor (Color.DARK_GRAY);
plot SZ = BaseLine - DeadZone;
SZ.SetStyle (Curve.SHORT_DASH);
SZ.SetDefaultColor (Color.DARK_GRAY);
SZ.HideTitle ();
SZ.HideBubble ();
LZ.HideTitle ();
LZ.HideBubble ();

input MidZone = 30;
plot mLZ = BaseLine + MidZone;
mLZ.SetStyle (Curve.SHORT_DASH);
mLZ.SetDefaultColor (Color.LIGHT_GREEN);
plot mSZ = BaseLine - MidZone;
mSZ.SetStyle (Curve.SHORT_DASH);
mSZ.SetDefaultColor (Color.DARK_ORANGE);
mSZ.HideTitle ();
mSZ.HideBubble ();
mLZ.HideTitle ();
mLZ.HideBubble ();

#Converted to upper box study by Eric on 8/27/13

#Hint: BetterVolume_v3 \n Shows volume and dbl average as well as Vol_Buzz \n VolBuzz is
#current bar volume vs the average volume for a relatively longer period = VolAvgPeriod \n
# The directional volume is the Net of Buy vs Sell avg vol for N = Length bars \n v3 adds
# informative labels with dynamic coloring & options in visualization - in V3 we switch to Barry
# Taylor's algo for directional volume calc \n RedK @ Live . com  ---  Mayl 2013

#declare lower;

input VolAvgPeriod = 30;

def ShowLabels = yes;
input VxNetSmooth = 3;
def VolSlowAvg = Average(volume, VolAvgPeriod);
def VolFastAvg = WMA(volume, Length);

def FastVRatio = Round((VolFastAvg / VolSlowAvg * 100), 1);
input VolPressureCalc = { default "WAverage", "Sum" };

def Vx =  if VolPressureCalc == VolPressureCalc.Sum then Sum(volume, Length) else WMA(volume, Length) ;
def C = close;
def O = open;
def Range = high - low;
def VolUp = if C > O and Range <> 0 then (Range / (2 * Range + O - C)) * volume
else if C < O and Range <> 0 then ((Range + C - O) / (2 * Range + C - O)) * volume
else 0.5 * volume;
def VolDn = volume - VolUp;

def VxPlus = if VolPressureCalc == VolPressureCalc.Sum then Sum (VolUp, Length) else WMA (VolUp, Length);
def VxMinus = if VolPressureCalc == VolPressureCalc.Sum then Sum (VolDn, Length) else WMA (VolDn, Length);
def VxNetRaw = VxPlus - VxMinus ;
def VxNet = 2 * WMA(VxNetRaw, VxNetSmooth) - WMA(WMA(VxNetRaw, VxNetSmooth), VxNetSmooth);
def VxRatio = Round(100 * VxNetRaw / Vx, 1);

#NN note: plot it to make sure the color logic is right
#plot vxr = VxRatio;
#vxr.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

#NN note: define the color conditions
def midrange = VxRatio >= -10 and VxRatio <= 10;#yellow
def up = VxRatio > 10 and VxRatio <= 18;#green
#def high = VxRatio >= 18;#bright green
def down = VxRatio >= -18 and VxRatio < -10;#red
#def low = VxRatio < -18;#bright red

#NN note: this has to be below the color conditions
#commented out since only needed it for debugging
#vxr.AssignValueColor(if VxRatio >-10 then if midrange then Color.YELLOW else if up then Color.GREEN else Color.LIME else if down then Color.DARK_RED else Color.RED);

#AddLabel (ShowLabels , "VxNet: " + VxRatio + "%", if between(VxRatio, -10, 10) then color.blue else if VxRatio >= 10 then color.green else color.dark_orange);

AddLabel (ShowLabels , "VxNet: " + VxRatio + "%", if VxRatio > -10 then if midrange then Color.BLUE else if up then Color.GREEN else Color.YELLOW else if down then Color.RED else Color.MAGENTA);
#AddLabel(1, if VxRatio >-10 then if midrange then "YELLOW" else if up then "GREEN" else "LIME" else if down then "DARK_RED" else "LIGHT_RED", if VxRatio >-10 then if midrange then Color.YELLOW else if up then Color.GREEN else Color.LIME else if down then Color.DARK_RED else Color.LIGHT_RED);

# Squeeze by Mobius @ My Trade with color mod by Lar
# Look at Cloud Color as a possible indication of direction once squeeze ends
def nK = 1.5;
def nBB = 2.0;
def lengthsqueeze = 20;
def price_s = close;
def h_s = high;
def c_s = close;
def l_s = low;

def BBHalfWidth = StDev(price_s, lengthsqueeze);
def KCHalfWidth = nK * Average(TrueRange(h_s,  c_s,  l_s),  lengthsqueeze);
def isSqueezed = nBB * BBHalfWidth / KCHalfWidth < 1;

# Squeeze for Longer Term Trend Indicator
plot BBS_Ind = if isSqueezed then BaseLine else Double.NaN;
BBS_Ind.SetDefaultColor(Color.RED);
BBS_Ind.SetPaintingStrategy(PaintingStrategy.POINTS);
BBS_Ind.SetLineWeight(3);
BBS_Ind.HideBubble();

# Count of Periods in consecutive squeeze
rec count = if isSqueezed then count[1] + 1 else 0;

AddLabel(yes, if isSqueezed then Concat("Caution -> Squeeze ", count) else "No Squeeze", Color.BLUE);

AssignPriceColor(if colorcandles then if K_DVO >= BaseLine then if K_DVO >= K_DVO[1] then K_DVO.Color("PositiveUp") else K_DVO.Color("Reverse") else if K_DVO <= K_DVO[1] then K_DVO.Color("NegativeDown") else K_DVO.Color("Reverse") else color.current);

87k+ Posts
200 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?