Volume Average / Current Volume / ATR On Chart For ThinkOrSwim

Anyone have TOS version of this?


Link to this chart

https://www.tradingview.com/script/qhg2ixwI-Volume-Average-Current-Volume-ATR-On-Chart/

Chart as image

https://www.tradingview.com/i/qhg2ixwI/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dalozification

//@version=4
study("Volume Average / Current Volume / ATR On Chart",overlay=true)

enablePercentageOnChart = input(title="Enable/Disable Showing RVOL % On Chart", type=input.bool, defval=true)

length = input(14, title="ATR Period", minval=1)
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
atrmultiplier = input(title="ATR Multiplier", type=input.float, defval=0.5, minval=.01, maxval=100, step=0.05)

ma_function(source, length) =>
if smoothing == "RMA"
rma(source, length)
else
if smoothing == "SMA"
sma(source, length)
else
if smoothing == "EMA"
ema(source, length)
else
wma(source, length)


catr = ma_function(tr(true), length)
atrVal = (catr * atrmultiplier)
// Calculate 30 Bar Vol Average
avgCnt = input(title="Number Of Bars Used For Averaging", type=input.integer, defval=30)
vol = security(syminfo.tickerid, timeframe.period, volume)
cvol = array.new_float(0)
for i = 0 to avgCnt-1
array.push(cvol,vol)

currentAvgVol = array.avg(cvol)
currentResolutionPercentAvg = round((vol / currentAvgVol)*100,0)
pColor = color.white
if currentResolutionPercentAvg >= 200
pColor := color.green
else
if currentResolutionPercentAvg >= 100
pColor := color.orange

codiff = 0.0
if currentResolutionPercentAvg >= 100
codiff := 1

if codiff > 0 and enablePercentageOnChart
label= label.new( bar_index, high,
text=tostring(currentResolutionPercentAvg)+"%",
color=color.white,
textcolor= pColor,
size=size.small,
style = label.style_none,
yloc = yloc.belowbar)

tblPos = input(title="Position on Chart", defval="Top Right", options=["Top Left", "Top Middle", "Top Right", "Bottom Left", "Bottom Center", "Bottom Right", "Middle Left", "Middle Right" ])
tblposition = tblPos == "Top Left" ? position.top_left : tblPos == "Top Right" ? position.top_right : tblPos == "Bottom Left" ? position.bottom_left : tblPos == "Bottom Right" ? position.bottom_right : tblPos == "Middle Left" ? position.middle_left : tblPos == "Bottom Center" ? position.bottom_center : tblPos == "Top Center" ? position.top_center : tblPos == "Middle Right" ? position.middle_right: position.top_center

tblBorderColor = input(title="Border Color", type=input.color, defval=#000000)
celllBgColor = input(title="Background Color", type=input.color, defval=#000000)
cellTextColor = input(title="Text Color", type=input.color, defval=#FFFFFF)



var resultsTable = table.new(position = tblposition, columns = 1, rows = 4, bgcolor = #ffffff, border_width = 1,frame_color = tblBorderColor, frame_width = 4)
table.clear(resultsTable, 0, 0)
table.cell(resultsTable, column=0, row=0, text="Relative Vol: "+tostring(currentResolutionPercentAvg,"")+"%", text_color=pColor, text_halign=text.align_right, text_valign=text.align_center, bgcolor=celllBgColor)
table.cell(resultsTable, column=0, row=1, text="Current: "+tostring(vol,"###,###,###,###"), text_color=pColor, text_halign=text.align_right, text_valign=text.align_center, bgcolor=celllBgColor)
table.cell(resultsTable, column=0, row=2, text=timeframe.period+" Avg: "+tostring(currentAvgVol,"###,###,###,###"), text_color=cellTextColor, text_halign=text.align_right, text_valign=text.align_center, bgcolor=celllBgColor)
table.cell(resultsTable, column=0, row=3, text="ATR: "+tostring(atrVal,"######.00"), text_color=cellTextColor, text_halign=text.align_right, text_valign=text.align_center, bgcolor=celllBgColor)
check the below

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © dalozification
#study("Volume Average / Current Volume / ATR On Chart",overlay=true)
# converted by Sam4Cok@Samer800 -02/2023 - request from UseThinkScript.com member

input enablePercentageOnChart = yes;    # "Enable/Disable Showing RVOL % On Chart"
input enableWedges = yes;
input avgCnt = 30;#(title="Number Of Bars Used For Averaging", type=input.integer, defval=30)
input atrLength = 14;                      # "ATR Period"
input atrSmoothing = AverageType.WILDERS;  # "Smoothing"
input atr_multiplier = 0.5;              # "ATR Multiplier"

def CurrentAgg = GetAggregationPeriod();
def AggPeriod = CurrentAgg / 60 / 1000;

def atrmultiplier = min(max(atr_multiplier, 0.01), 100);

def tr = TrueRange(High, Close, Low);
def catr = MovingAverage(atrSmoothing, tr, atrLength);
def atrVal = ROUND((catr * atrmultiplier), 2);

#/ Calculate 30 Bar Vol Average

def vol = volume;
def CurrentAvgVol = Average(vol, avgCnt);

def currentResPercAvg = round((vol / currentAvgVol)*100, 0);
def pColor;
if currentResPercAvg >= 200 {
    pColor = 1;
    } else
    if currentResPercAvg >= 100 {
        pColor = -1;
    } else {
    pColor = 0;
}

def codiff = currentResPercAvg >= 100;

plot rVol = if codiff and enableWedges then 1 else Double.NaN;
rVol.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
rVol.AssignValueColor(if pColor>0 then Color.CYAN else Color.MAGENTA);


AddChartBubble(enablePercentageOnChart and codiff, low - tickSize()*5, currentResPercAvg + "%", if pColor>0 then Color.GREEN else Color.LIGHT_ORANGE, no);
AddLabel(1,"Relative Vol ("+currentResPercAvg +"%", if pColor>0 then Color.GREEN else if pColor<0 then Color.RED else Color.WHITE);
AddLabel(1,"Current Vol (" + vol + ")", if pColor>0 then Color.GREEN else if pColor<0 then Color.RED else Color.WHITE);
AddLabel(1, AggPeriod + "Min Avg (" + currentAvgVol + ")", Color.WHITE);
AddLabel(1,"ATR (" + atrVal + ")", Color.WHITE);

#--- END CODE
 
hey samer thanks for this code! Are you able to take the bubble calculations from this code below you modified. Im trying to make it into a upper chart study like you have made here with AddChartBubble(enablePercentageOnChart);

CSS:
#Advanced Volume Study
#[email protected]
#v5.22.2020
declare on_volume;
input ShowVolumeAsCandlesticks = no;
input ShowBuySellStrengthOnVolumeBars = no;
input ShowBuySellStrength2ndAgg = no;
input AvgDayVolLength = 5;
input AvgVolLength = 20;
input ShowDayVolLabel = yes;
input ShowBarVolLabel = yes;
input ShowEthTotalVol = no;
input ShowBuySellStrength = yes;

#----------------------------------------
input bars  = 5;
def bar     = if BarNumber() >= 1
              then BarNumber()
              else bar[1] + 1;
def BuySellStrAgg2 = bar % bars == 0;# AggregationPeriod.THIRTY_MIN;
#----------------------------------------

input VolAverageType = AverageType.SIMPLE;
#if ShowBuySellStrengthOnVolumeBars is toggled on then the following volume bar paint options will not show, only the VolSignal Triangle set at the top of the bars will be painting according to volume average levels.
input PaintAboveAvgVolBars = yes;
input PaintAccordingToRelPrevVol = yes;
input RelativetoPrevVolTolerance = 1.25; #if volume is 1.25x greater than previous bar it will paint even if it is still below the average/sigma2/sigma3
input PaintBelowAvgVol = yes;
input PaintPriceAsVol = no;
input ShowVerticalTickLines = yes;
def ShowVertLines  = if ShowVerticalTickLines and GetAggregationPeriod() < AggregationPeriod.DAY then 1 else 0;
input TickLevel     = 1000;
input ShowTickLabel = yes;


def NA = Double.NaN;
def h  = high;
def l  = low;
def c  = close;
def o  = open;
def v  = volume;
def PriceRange              = h - l;
def TopShadowRange          = if o >= c then h - o else h - c;
def BottomShadowRange       = if o <= c then o - l else c - l;
def BodyRange               = PriceRange - (TopShadowRange + BottomShadowRange);
def VolumeTopShadowValue    = (1 - (TopShadowRange / PriceRange)) * v;
def VolumeBottomShadowValue = ((BottomShadowRange / PriceRange) * v);
def BodyRangeVolValue       = ((BodyRange + BottomShadowRange) / PriceRange) * v;
def DayVolAgg               = if GetAggregationPeriod() < AggregationPeriod.DAY then AggregationPeriod.DAY else GetAggregationPeriod();
def DayVol    = volume("period" = DayVolAgg);
def AvgDayVol = Average(DayVol, AvgDayVolLength);
def Start     = 0930;
def End       = 1600;
def conf      = SecondsFromTime(Start) >= 0 and SecondsFromTime(End) <= 0;

plot VolColor = NA;
VolColor.DefineColor("Bullish", Color.GREEN);
VolColor.DefineColor("Bearish", Color.RED);
VolColor.DefineColor("VolAvg", CreateColor(0, 100, 200));
VolColor.DefineColor("VolSigma2", Color.DARK_ORANGE);
VolColor.DefineColor("VolSigma3", Color.MAGENTA);
VolColor.DefineColor("Relative to Prev", Color.YELLOW);
VolColor.DefineColor("Below Average", Color.GRAY);
VolColor.DefineColor("ETH TVOL", Color.GRAY);
VolColor.DefineColor("TICK Vert", Color.GRAY);

#Current Candle Buy and Sell Strength
def BuyStr    = ((c - l) / PriceRange) * 100;
def SellStr   = ((h - c) / PriceRange) * 100;

def bar2count = if bar % bars == 0
                then bar2count[1] + 1
                else bar2count[1];
plot x2 = bar;
x2.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
def high2     = if IsNaN(h)
                then high2[1]
                else if BarNumber() == bar
                then Highest(h, bars)
                else if bar2count != bar2count[1]
                then Highest(h, bars) else Double.NaN;
def close2    = if IsNaN(c)
                then close2[1]
                else if BarNumber() == bar
                then c
                else if bar2count != bar2count[1]
                then c else Double.NaN;
def low2      = if IsNaN(l)
                then low2[1]
                else if BarNumber() == bar
                then Lowest(l, bars)
                else  if bar2count != bar2count[1]
                then Lowest(l, bars) else Double.NaN;
def volume2   = if IsNaN(v)
                then volume2[1]
                else if BarNumber() == bar
                then  Highest(v, bars)
                else if bar2count != bar2count[1]
                then Highest(v, bars) else Double.NaN;
def v2       = volume2;

def BuyStr2  = if IsNaN((close2 - low2) / (high2 - low2) * 100)
               then BuyStr2[1]
               else (close2 - low2) / (high2 - low2) * 100;
def SellStr2 = if IsNaN((high2 - close2) / (high2 - low2) * 100)
               then SellStr2[1]
               else (high2 - close2) / (high2 - low2) * 100;

plot BuyVol = if ShowBuySellStrengthOnVolumeBars then (BuyStr / 100) * v else NA;
def SellVol = (SellStr / 100) * v;
def BuyVol2 = (BuyStr2 / 100) * volume2;
def SellVol2 = (SellStr2 / 100) * volume2;
AddCloud(if ShowBuySellStrength2ndAgg then BuyVol2 else NA, 0, VolColor.Color("Bullish"), VolColor.Color("Bullish"), yes);
AddCloud(if ShowBuySellStrength2ndAgg then v2 else NA, BuyVol2, VolColor.Color("Bearish"), VolColor.Color("Bearish"), yes);

BuyVol.SetDefaultColor(VolColor.Color("Bullish"));
BuyVol.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

plot Vol          = v;
plot VolumeBottom = if !ShowVolumeAsCandlesticks or ShowBuySellStrengthOnVolumeBars then NA else VolumeBottomShadowValue;
plot VolumeBody   = if !ShowVolumeAsCandlesticks or ShowBuySellStrengthOnVolumeBars then NA else BodyRangeVolValue;

VolumeBottom.HideTitle();
VolumeBody.HideTitle();

plot VolAvg = MovingAverage(VolAverageType, v, AvgVolLength);

#2Sigma and 3Sigma Vol Filter
def Num_Dev1          = 2.0;
def Num_Dev2          = 3.0;
def averageType       = AverageType.SIMPLE;
def sDev = StDev(data = Vol, length = AvgVolLength);

plot VolSigma2 = VolAvg + Num_Dev1 * sDev;
plot VolSigma3 = VolAvg + Num_Dev2 * sDev;


def RelDayVol     = DayVol / AvgDayVol[1];
def RelPrevDayVol = DayVol / volume("period" = DayVolAgg)[1];
#Daily aggregation volume labels
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if ShowDayVolLabel then 1 else 0, "DayVol: " + DayVol + " / " + Round(RelDayVol, 2) + "x Avg(" + AvgDayVolLength + ") / " + Round(RelPrevDayVol, 2) + "x Prev", if DayVol > AvgDayVol then VolColor.Color("VolAvg") else VolColor.Color("Below Average"));

def RelVol = Vol / VolAvg[1];
def RelPrevVol = v / v[1];

#Triangle Vol Signal
plot VolSignal = if Vol > VolSigma3 then v else if Vol > VolSigma2 then v else if Vol > VolAvg then volume else if RelPrevVol >= RelativetoPrevVolTolerance then v else NA;

#current aggregation's volume labels
AddLabel(ShowBarVolLabel, "Vol: " + v + " / " + Round(RelVol, 2) + "x Avg(" + AvgVolLength + ") / " + Round(RelPrevVol, 2) + "x Prev",  if Vol > VolSigma3 then VolColor.Color("VolSigma3") else if Vol > VolSigma2 then VolColor.Color("VolSigma2") else if Vol > VolAvg then VolColor.Color("VolAvg") else VolColor.Color("Below Average"));

#ETH Total Vol Label
def ETH_VOL = if !conf and conf[1] then v else if !conf then CompoundValue(1, ETH_VOL[1] + v, v) else ETH_VOL[1];

AddLabel(if !ShowEthTotalVol then 0 else if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else 1, "ETH TVOL: " + ETH_VOL, VolColor.Color("ETH TVOL"));

#$TICK Vertical Lines
def tickc = close("$TICK");
def tickh = high("$TICK");
def tickl = low("$TICK");

AddVerticalLine(if ShowVertLines and (tickh > TickLevel) or ShowVertLines and (tickl < -TickLevel) then 1 else 0, if (tickh > TickLevel) then tickh else if (tickl < -TickLevel) then tickl else Double.NaN, VolColor.Color("TICK Vert"));

#$TICK Label
AddLabel(if ShowTickLabel then 1 else 0, "$TICK: " + tickc, if tickc > 0 then Color.GREEN else Color.RED);

#current candle Buy/Sell strength labels
AddLabel(if ShowBuySellStrength then 1 else 0, " ", Color.BLACK);
AddLabel(if ShowBuySellStrength then 1 else 0, "1", Color.GRAY);
AddLabel(if ShowBuySellStrength then 1 else 0, "Sell " + Round(SellStr, 2) + "%", if SellStr > BuyStr then Color.RED else Color.DARK_RED);
AddLabel(if ShowBuySellStrength then 1 else 0, "Buy " + Round(BuyStr, 2) + "%", if BuyStr > SellStr then Color.GREEN else Color.DARK_GREEN);

#2nd Aggregation Buy/Sell strength labels
#AddLabel(if ShowBuySellStrength then 1 else 0, "Check BuySellAgg2 > Current Agg", Color.YELLOW);
AddLabel(if !ShowBuySellStrength then 0 else 1, " ", Color.BLACK);
AddLabel(if !ShowBuySellStrength then 0 else 1, "2", Color.GRAY);
AddLabel(if !ShowBuySellStrength then 0 else 1, "Sell " + Round(SellStr2, 2) + "%", if SellStr2 > BuyStr2 then Color.RED else Color.DARK_RED);
AddLabel(if !ShowBuySellStrength then 0 else 1, "Buy " + Round(BuyStr2, 2) + "%", if BuyStr2 > SellStr2 then Color.GREEN else Color.DARK_GREEN);

VolumeBottom.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
VolumeBottom.AssignValueColor(Color.BLACK);
VolumeBody.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

VolumeBody.AssignValueColor(if PaintAboveAvgVolBars and Vol > VolSigma3 then VolColor.Color("VolSigma3") else if PaintAboveAvgVolBars and Vol > VolSigma2 then VolColor.Color("VolSigma2") else if PaintAboveAvgVolBars and Vol > VolAvg then VolColor.Color("VolAvg") else if PaintAccordingToRelPrevVol and RelPrevVol >= RelativetoPrevVolTolerance then VolColor.Color("Relative to Prev") else if  PaintBelowAvgVol and Vol < VolAvg then VolColor.Color("Below Average") else if c > o then VolColor.Color("Bullish") else VolColor.Color("Bearish"));
#VolumeTop.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
#VolumeTop.AssignValueColor(if close > open then Color.Black else Color.Black);

VolAvg.SetDefaultColor(VolColor.Color("VolAvg"));
VolSigma2.SetDefaultColor(VolColor.Color("VolSigma2"));
VolSigma3.SetDefaultColor(VolColor.Color("VolSigma3"));

Vol.SetPaintingStrategy(if !ShowVolumeAsCandlesticks or ShowBuySellStrengthOnVolumeBars then PaintingStrategy.SQUARED_HISTOGRAM else PaintingStrategy.HISTOGRAM);

Vol.SetLineWeight(1);
Vol.AssignValueColor(if ShowBuySellStrengthOnVolumeBars then VolColor.Color("Bearish") else if PaintAboveAvgVolBars and v > VolSigma3 then VolColor.Color("VolSigma3") else if PaintAboveAvgVolBars and v > VolSigma2 then VolColor.Color("VolSigma2") else if PaintAboveAvgVolBars and v > VolAvg then VolColor.Color("VolAvg") else if PaintAccordingToRelPrevVol and RelPrevVol >= RelativetoPrevVolTolerance then VolColor.Color("Relative to Prev") else if PaintBelowAvgVol and v < VolAvg then VolColor.Color("Below Average") else if c > o then VolColor.Color("Bullish") else VolColor.Color("Bearish"));

AssignPriceColor(if PaintPriceAsVol and PaintAboveAvgVolBars and v > VolSigma3 then VolColor.Color("VolSigma3") else if PaintPriceAsVol and PaintAboveAvgVolBars and v > VolSigma2 then VolColor.Color("VolSigma2") else if PaintPriceAsVol and PaintAboveAvgVolBars and v > VolAvg then VolColor.Color("VolAvg") else if PaintPriceAsVol and PaintAccordingToRelPrevVol and RelPrevVol >= RelativetoPrevVolTolerance then VolColor.Color("Relative to Prev") else if PaintPriceAsVol and PaintBelowAvgVol and v < VolAvg then VolColor.Color("Below Average") else Color.CURRENT);

VolSignal.AssignValueColor(if Vol > VolSigma3 then VolColor.Color("VolSigma3") else if Vol > VolSigma2 then VolColor.Color("VolSigma2") else if Vol > VolAvg then VolColor.Color("VolAvg") else if RelPrevVol >= RelativetoPrevVolTolerance then VolColor.Color("Relative to Prev") else VolColor.Color("Below Average"));
VolSignal.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
VolAvg.SetLineWeight(2);
VolSignal.SetLineWeight(1);



########################################
#Buy/Sell Bubbles

input show_buy_sell_bubbles = no;
input bubblemover           = 0;
def b                       = bubblemover;
def b1                      = b + 1;

def periods     = bar % bars == 0;
def periodCount = CompoundValue(1, if periods then periodCount[1] + 1 else periodCount[1], 0);
def thisperiod  = (HighestAll(periodCount) - periodCount) ;

AddChartBubble(show_buy_sell_bubbles and thisperiod[b1] != thisperiod[b], VolAvg[b], Round(SellStr2[b1]) + "%", if Round(SellStr2[b1]) > Round(BuyStr2[b1]) then Color.RED else Color.GRAY);
AddChartBubble(show_buy_sell_bubbles and thisperiod[b1] != thisperiod[b] , VolAvg[b], Round(BuyStr2[b1]) + "%", if Round(SellStr2[b1]) > Round(BuyStr2[b1]) then Color.GRAY else Color.GREEN);

input show_buy_sell_bubbles_last = yes;
AddChartBubble(show_buy_sell_bubbles_last and IsNaN(close[-1]) and !IsNaN(close) and BarNumber() == bar and thisperiod == thisperiod[1], VolAvg, Round(SellStr2) + "%", if Round(SellStr2) > Round(BuyStr2) then Color.RED else Color.GRAY);
AddChartBubble(show_buy_sell_bubbles_last and IsNaN(close[-1]) and !IsNaN(close) and BarNumber() == bar , VolAvg, Round(BuyStr2) + "%" , if Round(SellStr2) > Round(BuyStr2) then Color.GRAY else Color.GREEN);
#######################################
 

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
169 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