Advanced Volume Indicator for ThinkorSwim

Welkin

Welkin

Active member
VIP

Updates & Features:

  • Showing Volume Bars as Candlesticks is now optional and can be toggled on/off in the study settings
  • Added Labels to show Day and Current Volume/ Avg Relative Volume / and Vol Relative to Previous
When the chart time frame > daily time frame the daily volume label will be hidden.
The Blue is volume average with a default length of 20.
The Orange line is a 2-sigma (2 deviations from the average) volume filter.
The Magenta line is a 3-sigma volume filter .
When volume is greater than the average a blue triangle will be plotted above the volume candlestick. When above the 2-sigma line it will be orange, and when above the 3-sigma it will be magenta.
When current volume exceeds the averages the label will change from gray to blue/orange/magenta depending on which is crossed.
If the daily vol exceeds the daily vol average the label will change from gray to blue.
  • Added Buy/Sell Str for current aggregation and a 2nd aggregation
    Note that this does not provide the true buy and sell volume, as this data is not available through TOS for individual stocks, although there are market internals that show up and down volume available for the different exchanges. Alternatively up and down tick data can be utilized to try and estimate buy and sell volume, but you do not know how many contracts/shares there are in a given tick. This method is just a workaround by finding the percent difference of the close price relative to a candles range (high - low) and multiplying it by volume.
    BuyStr = (close - low) / (high - low)
    SellStr = (high - close) / (high - low)
    This is also kind of similar to how a part of ADL or CMF is calculated, which uses (close - low) - (high - close) / (high - low)
  • Added option to paint volume bars reflecting Buy/Sell strength
  • Added option to show 2nd aggregation Buy/Sell strength clouds in the background
  • Added options to repaint volume bars if they exceed the averages.
  • Added option to color volume bars gray(or whatever color you want) if they are below average.
  • Added a tolerance level that can be set ( currently 1.25) that if the current bar is 1.25x greater volume relative to the previous volume bar it will be painted (currently yellow by default) even if it is not above the volume average, sigma2, or sigma3.
  • Added Label for Extended Trading Hours total volume (ETH TVOL), not showing by default, change ShowEthTotalVol to yes for it to be visible. If the chart aggregation is >= daily then it will not show.
  • Added $TICK Label
  • Added $TICK vertical lines which are plotted when $TICK > 1000 or < -1000 (this level can also be adjusted in the study settings if you want to plot at a level other than +/-1000)
  • Added an option to paint price bars according to how you've customized the volume settings




thinkScript Code

Code:
#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 BuySellStrAgg2 = AggregationPeriod.THIRTY_MIN;
def BuySellStrAggregation2 = if GetAggregationPeriod() < BuySellStrAgg2 then BuySellStrAgg2 else GetAggregationPeriod();
AddLabel(if GetAggregationPeriod() < BuySellStrAgg2 then 0 else 1, "Adjust BuySellStrAgg2 in Study Settings", Color.YELLOW);
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 PriceRange = high - low;
def TopShadowRange = if open >= close then high - open else high - close;
def BottomShadowRange = if open <= close then open - low else close - low;
def BodyRange = PriceRange - (TopShadowRange + BottomShadowRange);
def VolumeTopShadowValue = (1 - (TopShadowRange / PriceRange)) * volume;
def VolumeBottomShadowValue = ((BottomShadowRange / PriceRange) * volume);
def BodyRangeVolValue = ((BodyRange + BottomShadowRange) / PriceRange) * volume;
#def DayVolAgg = if GetAggregationPeriod() < AggregationPeriod.DAY then AggregationPeriod.DAY else if GetAggregationPeriod() >= AggregationPeriod.DAY then AggregationPeriod.WEEK else GetAggregationPeriod();
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 = ((close - low) / PriceRange) * 100;
def SellStr = ((high - close) / PriceRange) * 100;

def BuyStr2 = ((close("period" = BuySellStrAggregation2) - low("period" = BuySellStrAggregation2)) / (high("period" = BuySellStrAggregation2) - low("period" = BuySellStrAggregation2))) * 100;
def SellStr2 = ((high("period" = BuySellStrAggregation2) - close("period" = BuySellStrAggregation2)) / (high("period" = BuySellStrAggregation2) - low("period" = BuySellStrAggregation2))) * 100;

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

BuyVol.SetDefaultColor(VolColor.Color("Bullish"));
BuyVol.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
#BuyVol2.SetDefaultColor(Color.GREEN);
#BuyVol2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#SellVol2.SetDefaultColor(Color.GREEN);
#SellVol2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot Vol = volume;
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, volume, 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 = volume / volume[1];

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

#current aggregation's volume labels
AddLabel(ShowBarVolLabel, "Vol: " + volume + " / " + 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 volume else if !conf then CompoundValue(1, ETH_VOL[1] + volume, volume) 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 GetAggregationPeriod() >= BuySellStrAggregation2 and ShowBuySellStrength then 1 else 0,"Check BuySellAgg2 > Current Agg", Color.YELLOW);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, " ", Color.BLACK);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "2", Color.GRAY);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "Sell " + Round(SellStr2, 2) + "%", if SellStr2 > BuyStr2 then Color.RED else Color.DARK_RED);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !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 close > open 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 volume > VolSigma3 then VolColor.Color("VolSigma3") else if PaintAboveAvgVolBars and volume > VolSigma2 then VolColor.Color("VolSigma2") else if PaintAboveAvgVolBars and volume > VolAvg then VolColor.Color("VolAvg") else if PaintAccordingToRelPrevVol and RelPrevVol >= RelativetoPrevVolTolerance then VolColor.Color("Relative to Prev") else if PaintBelowAvgVol and volume < VolAvg then VolColor.Color("Below Average") else if close > open then VolColor.Color("Bullish") else VolColor.Color("Bearish"));

AssignPriceColor(if PaintPriceAsVol and PaintAboveAvgVolBars and volume > VolSigma3 then VolColor.Color("VolSigma3") else if PaintPriceAsVol and PaintAboveAvgVolBars and volume > VolSigma2 then VolColor.Color("VolSigma2") else if PaintPriceAsVol and PaintAboveAvgVolBars and volume > 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 volume < 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);
Shareable Link: https://tos.mx/jIx0x2n

With Show Volume As Candlesticks Toggled On:

With Show Volume As Candlesticks Toggled Off:

With Show Buy/Sell Strength On Volume Bars and Buy/SellStrength 2nd Aggregation In Background toggled On:

With All Volume Bar Paint Options Disabled:

With Price Paint Bars On:



Upper Study for VSA

I created this indicator to accompany the main volume indicator for those who use VSA (Volume Spread Analysis), what this does is draws a line across at high and low of bars with high interest volume.



https://tos.mx/ak3uWTh
Code:
#Companion indicator to the Advanced Volume Study for Volume Spread Analysis
#[email protected]
declare upper;
input PaintPriceAsVol = no;
input AvgDayVolLength = 5;
input AvgVolLength = 20;
input ShowDayVolLabel = yes;
input ShowBarVolLabel = yes;
input ShowEthTotalVolLabel = no;
input ShowTickLabel = yes;
input VolAverageType = AverageType.SIMPLE;
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 ShowVerticalTickLines = yes;
def ShowVertLines = if ShowVerticalTickLines and GetAggregationPeriod() < AggregationPeriod.DAY then 1 else 0;
input TickLevel = 1000;



def NA = Double.NaN;

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);
def Vol = volume;

def VolAvg = MovingAverage(VolAverageType, volume, 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);

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

#####
#VSA start test
#####
def VSig3H = if volume > VolSigma3 then high else VSig3H[1];
def VSig2H = if volume > VolSigma2 and volume < VolSigma3 then high else VSig2H[1];
def VSigAH = if volume > VolAvg and volume < VolSigma2 then high else VSigAH[1];
def VSig3L = if volume > VolSigma3 then low else VSig3L[1];
def VSig2L = if volume > VolSigma2 and volume < VolSigma3 then low else VSig2L[1];
def VSigAL = if volume > VolAvg and volume < VolSigma2 then low else VSigAL[1];

plot VSig3Hc = Vsig3H;
plot VSig2Hc = Vsig2H;
plot VSigAHc = VSigAH;
plot VSig3Lc = Vsig3L;
plot VSig2Lc = Vsig2L;
plot VSigALc = VSigAL;


VSig3Hc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSig2Hc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSigAHc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSig3Lc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSig2Lc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSigALc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSig3Hc.SetDefaultColor(Color.MAGENTA);
VSig2Hc.SetDefaultColor(Color.DARK_ORANGE);
VSigAHc.SetDefaultColor(CreateColor(0,125,225));
VSig3Lc.SetDefaultColor(Color.MAGENTA);
VSig2Lc.SetDefaultColor(Color.DARK_ORANGE);
VSigALc.SetDefaultColor(CreateColor(0,125,225));


#####
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 = volume / volume[1];

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

#current aggregation's volume labels
AddLabel(ShowBarVolLabel, "Vol: " + volume + " / " + 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 volume else if !conf then CompoundValue(1, ETH_VOL[1] + volume, volume) else ETH_VOL[1];

AddLabel(if !ShowEthTotalVolLabel 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);


AssignPriceColor(if PaintPriceAsVol and PaintAboveAvgVolBars and volume > VolSigma3 then VolColor.Color("VolSigma3") else if PaintPriceAsVol and PaintAboveAvgVolBars and volume > VolSigma2 then VolColor.Color("VolSigma2") else if PaintPriceAsVol and PaintAboveAvgVolBars and volume > 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 volume < VolAvg then VolColor.Color("Below Average") else Color.CURRENT);

Watchlist Columns


Code:
#[email protected]
#Advanced Volume Watchlist Column
#Add-on to https://tos.mx/jIx0x2n
#Relative to Avg Vol / Relative to Previous Volume bar

input VolAverageType = AverageType.SIMPLE;
input AvgVolLength = 20;
input RelativetoPrevVolTolerance = 1.25;

def Vol = volume;
def Num_Dev1 = 2.0;
def Num_Dev2 = 3.0;
def averageType = AverageType.SIMPLE;
def sDev = StDev(data = Vol, length = AvgVolLength);
def VolAvg = MovingAverage(VolAverageType, volume, AvgVolLength);
def VolSigma2 = VolAvg + Num_Dev1 * sDev;
def VolSigma3 = VolAvg + Num_Dev2 * sDev;
def RelVol = Vol / VolAvg[1];
def RelPrevVol = volume / volume[1];
AssignBackgroundColor(if Vol > VolSigma3 then Color.MAGENTA else if Vol > VolSigma2 then Color.DARK_ORANGE else if Vol > VolAvg then CreateColor(0, 100, 200) else if RelPrevVol >= RelativetoPrevVolTolerance then Color.YELLOW else Color.GRAY);

AddLabel(1, Round(RelVol, 2) + "x / " + Round(RelPrevVol, 2) +"x", Color.BLACK);

Code:
#Buy/Sell Strength Column
def o = open;
def h = high;
def l = low;
def c = close;
def PR = h - l;
def BuyStr = ((c - l) / PR) * 100;

AddLabel(1,Round(BuyStr,1)+" | " + Round(100-BuyStr,1)+"%", Color.BLACK);

AssignBackgroundColor(if BuyStr >= 70 then Color.Green else if BuyStr > 50 then Color.DARK_GREEN else if BuyStr <= 30 then Color.RED else if BuyStr < 50 then Color.DARK_RED else Color.GRAY);
 
Last edited:
zeek

zeek

Active member
2019 Donor
updated with some significant changes for those interested
Very nice additions, i like it a lot👍

Regarding the buy/sell strength, would it be possible to also show this for a certain period of time, let’s say the last 30 minutes instead of just the current bar? @Welkin
 
Welkin

Welkin

Active member
VIP
Very nice additions, i like it a lot👍

Regarding the buy/sell strength, would it be possible to also show this for a certain period of time, let’s say the last 30 minutes instead of just the current bar? @Welkin
done, you can now set a 2nd aggregation for buy sell candle strength. take note that it will not show if your current aggregation is >= 2nd aggregation you set.
 
I

Ishaam

Member
VIP
Hi @Welkin , is it possible that you can script the code for this indicator so that it only shows the Volume Sell/Buy strength for the time frame that you have it on plus the higher (2nd aggregation) time frame. For example, on a 5min time frame, show the buy/sell volume and compare it to the 10min time frame volume.

Note, I have this as labels on the volume by turning almost everything off on the study, seems to do the trick for now, but just wondering if the code could be a bit more simpler to show only the Sell/Buy volume strength, many thanks.
 
Welkin

Welkin

Active member
VIP
Hi @Welkin , is it possible that you can script the code for this indicator so that it only shows the Volume Sell/Buy strength for the time frame that you have it on plus the higher (2nd aggregation) time frame. For example, on a 5min time frame, show the buy/sell volume and compare it to the 10min time frame volume.

Note, I have this as labels on the volume by turning almost everything off on the study, seems to do the trick for now, but just wondering if the code could be a bit more simpler to show only the Sell/Buy volume strength, many thanks.
so essentially what you want is just the labels?
https://tos.mx/DZwBFIi
Code:
#[email protected]
#Volume Labels
input AvgDayVolLength = 5;
input AvgVolLength = 20;
input ShowDayVolLabel = yes;
input ShowBarVolLabel = yes;
input ShowBuySellStrength = yes;
input BuySellStrAggregation2 = AggregationPeriod.THIRTY_MIN;
input VolAverageType = AverageType.SIMPLE;

def NA = Double.NaN;
def PriceRange = high - low;
def DayVol = volume("period" = AggregationPeriod.DAY);
def AvgDayVol = Average(DayVol,AvgDayVolLength);

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);

def Vol = volume;
def VolAvg = MovingAverage(VolAverageType, Volume, 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);

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

#Current Candle Buy and Sell Strength
def BuyStr = ((close - low)/PriceRange)*100;
def SellStr = ((high - close)/PriceRange)*100;


def BuyStr2 = ((close("period"=BuySellStrAggregation2) - low("period"=BuySellStrAggregation2))/(high("period"=BuySellStrAggregation2) - low("period"=BuySellStrAggregation2)))*100;
def SellStr2 = ((high("period"=BuySellStrAggregation2) - close("period"=BuySellStrAggregation2))/(high("period"=BuySellStrAggregation2) - low("period"=BuySellStrAggregation2)))*100;


def RelDayVol = DayVol / AvgDayVol;
def RelPrevDayVol = DayVol / volume("period" = AggregationPeriod.DAY)[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;
def RelPrevVol = volume / volume[1];

#current aggregation's volume labels
AddLabel(ShowBarVolLabel, "Vol: " + volume +" / "+ 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"));

#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 GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, " ", Color.BLACK);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "2", Color.GRAY);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "Sell "+Round(SellStr2,2) +"%", if SellStr2 > BuyStr2 then Color.RED else Color.DARK_RED);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "Buy "+Round(BuyStr2,2) +"%", if BuyStr2 > SellStr2 then Color.GREEN else Color.DARK_GREEN);
 
zeek

zeek

Active member
2019 Donor
Have a question for you @Welkin , i noticed that the Todays Volume label does not show anything in pre-market and was wondering if there is any way to make this work with extended hours included?
 
Welkin

Welkin

Active member
VIP
Have a question for you @Welkin , i noticed that the Todays Volume label does not show anything in pre-market and was wondering if there is any way to make this work with extended hours included?
The day's volume is pulled from the daily aggregation period, and a new daily candle doesn't begin until the market open. The second label showing volume from the current aggregation should show you the premarket unless you have ETH hidden on the chart. What are you wanting shown for ETH volume? the total?
 
YungTraderFromMontana

YungTraderFromMontana

Well-known member
good stuff, what do the darker and lighter colors within the candle reperesent? For example on grey candles there is a dark grey and a lighter grey.
 
Welkin

Welkin

Active member
VIP
good stuff, what do the darker and lighter colors within the candle reperesent? For example on grey candles there is a dark grey and a lighter grey.
its the same color, just the way the histograms overlap with one another in order to make it look like a candlestick makes them appear slightly different in shade due to their opacity.
 
zeek

zeek

Active member
2019 Donor
The day's volume is pulled from the daily aggregation period, and a new daily candle doesn't begin until the market open. The second label showing volume from the current aggregation should show you the premarket unless you have ETH hidden on the chart. What are you wanting shown for ETH volume? the total?
Ok, i see. Yes, it`s the total traded volume in pre-market that i`m interested to see as a label.
 
T

Trading51

Active member
2019 Donor
Great work, would this work on Futures for the Globex session and still, be accurate just checking thanks again.
 
Welkin

Welkin

Active member
VIP
Ok, i see. Yes, it`s the total traded volume in pre-market that i`m interested to see as a label.
here you go, added ETH TVOL label

Code:
#[email protected]
#v4.23.2020
input AvgDayVolLength = 5;
input AvgVolLength = 20;
input ShowDayVolLabel = yes;
input ShowBarVolLabel = yes;
input ShowBuySellStrength = yes;
input ShowEthTotalVol = yes;
input BuySellStrAggregation2 = AggregationPeriod.THIRTY_MIN;
input VolAverageType = AverageType.SIMPLE;

def NA = Double.NaN;
def PriceRange = high - low;
def DayVol = volume("period" = AggregationPeriod.DAY);
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);

def Vol = volume;
def VolAvg = MovingAverage(VolAverageType, Volume, 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);

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

#Current Candle Buy and Sell Strength
def BuyStr = ((close - low)/PriceRange)*100;
def SellStr = ((high - close)/PriceRange)*100;


def BuyStr2 = ((close("period"=BuySellStrAggregation2) - low("period"=BuySellStrAggregation2))/(high("period"=BuySellStrAggregation2) - low("period"=BuySellStrAggregation2)))*100;
def SellStr2 = ((high("period"=BuySellStrAggregation2) - close("period"=BuySellStrAggregation2))/(high("period"=BuySellStrAggregation2) - low("period"=BuySellStrAggregation2)))*100;


def RelDayVol = DayVol / AvgDayVol;
def RelPrevDayVol = DayVol / volume("period" = AggregationPeriod.DAY)[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;
def RelPrevVol = volume / volume[1];

#current aggregation's volume labels
AddLabel(ShowBarVolLabel, "Vol: " + volume +" / "+ 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
def ETH_VOL = if !conf and conf[1] then volume else if !conf then CompoundValue(1, ETH_VOL[1] + volume, volume) 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"));

#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 GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, " ", Color.BLACK);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "2", Color.GRAY);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "Sell "+Round(SellStr2,2) +"%", if SellStr2 > BuyStr2 then Color.RED else Color.DARK_RED);
AddLabel(if GetAggregationPeriod() >= BuySellStrAggregation2 or !ShowBuySellStrength then 0 else 1, "Buy "+Round(BuyStr2,2) +"%", if BuyStr2 > SellStr2 then Color.GREEN else Color.DARK_GREEN);
 
Last edited:
K

KKaiser

Member
VIP
Thanks Welkin. I am very new to scripts. This looks very informative for day trading, I copy/pasted the script on my chart, but I am not able to add the below two Volume graphs on my chart. I added VolumeAvg, while selecting studying. Thanks for your help.
 
Top