Directional Volatility & Volume Oscillator For ThinkOrSwim


New member
Does anyone have the code for the Directional Volatility & Volume Oscillator? I saw this posted on the Trade Algorithm YouTube site the other day and it looks very interesting.
Last edited by a moderator:
as requested.

Release note:
An oscillator that manages to display the direction of volatility and volume in a single indicator. This allows viewing the trend in concert with the volume strength. Thus a trader can check if the price movement has volatility and volume behind it or not.

#/ This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © PuguForex 2021
#indicator('Directional Volatility and Volume')
# Converrted and mod by Sam4Cok@Samer800 - 12/2022
declare lower;
input EnableBackgroundColor = yes;
input ColorBar            = no;
input src = close;
input VolatilityPeriod = 4;     #  'Volatility period'
input VolatilityMethod = AverageType.HULL;  # "Volatility smoothing"
input VolumePeriod     = 14;    #  'Volume period'
input VolumeMethod     = AverageType.HULL;  # "Volume smoothing"
input ZonePeriod       = 14;    #  'Zone period'
input ZoneMethod       = AverageType.HULL;  #  "Zone smoothing"

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

#--- Color
DefineGlobalColor("exUp" , CreateColor(0,179,0));
DefineGlobalColor("up"   , CreateColor(0,104,0));
DefineGlobalColor("exDn" , CreateColor(255,5,68));
DefineGlobalColor("dn"   , CreateColor(133,0,33));
DefineGlobalColor("volUp" , createcolor(173,216,230));
DefineGlobalColor("volDn" , CreateColor(230,173,188));

def zeroLine = MovingAverage(ZoneMethod, hl2  , ZonePeriod);
def val      = MovingAverage(VolatilityMethod, close, VolatilityPeriod) - zeroLine;
def znUp     = MovingAverage(ZoneMethod, high , ZonePeriod) - zeroLine;
def znDn     = MovingAverage(ZoneMethod, low  , ZonePeriod) - zeroLine;

def vol      = if close > open then volume else -volume;
def volSm    = MovingAverage(VolumeMethod, vol, VolumePeriod);

def upBr     = Crosses(val, znUp, CrossingDirection.ABOVE);
def dnBr     = Crosses(val, znDn, CrossingDirection.BELOW);
def movAvg   = MovingAverage(ZoneMethod, val, ZonePeriod);
def volatColor = if val > znUp then 1 else
                 if val < znDn then -1 else 0;# :
def ZoneColor = if volSm > 0 then 1 else if volSm < 0 then -1 else 0;
#--- PLots

plot VolumeUp = if volatColor>0 then na else znUp;    # 'Volume Up'
VolumeUp.AssignValueColor(if ZoneColor>0 then GlobalColor("volUp") else
                          if ZoneColor<0 then GlobalColor("volDn") else Color.GRAY);
plot VolumeDn = if volatColor<0 then na else znDn;    # 'Volume Dn'
VolumeDn.AssignValueColor(if ZoneColor>0 then GlobalColor("volUp") else
                          if ZoneColor<0 then GlobalColor("volDn") else Color.GRAY);

plot Volatility = val;    # 'Volatility'
Volatility.AssignValueColor(if volatColor>0 then
                            if val>val[1] then GlobalColor("exUp") else GlobalColor("up") else
                            if volatColor<0 then
                            if val<val[1] then GlobalColor("exDn") else GlobalColor("dn") else Color.GRAY);

#--- Signal
AddChart(high = if upBr and src>movAvg then pos else na,
         low = neg,
         open = pos,
         close = neg,
         type = ChartType.CANDLE, growcolor = CreateColor(0,78,0));
AddChart(high = if dnBr and src<movAvg then pos else na,
         low = neg,
         open = pos,
         close = neg,
         type = ChartType.CANDLE, growcolor = CreateColor(78,0,0));
#--- Bar Color
AssignPriceColor(if !ColorBar then Color.CURRENT else if volatColor>0 then
                 if val>val[1] and src>src[1] then GlobalColor("exUp") else GlobalColor("up") else
                 if val<val[1] and src<src[1] then GlobalColor("exDn") else GlobalColor("dn"));
# Background color
AssignBackgroundColor(if !EnableBackgroundColor then Color.CURRENT else if volatColor>0 and src>movAvg then CreateColor(1,25,16) else if  volatColor<0 and src<movAvg then CreateColor(38,0,0) else Color.CURRENT);

Last edited by a moderator:

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
193 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.