 # ThinkorSwim Plot Highest Volume Bar

#### XeoNoX

##### Well-known member
VIP
I was wondering if someone could help make this thinkscript, its just drawing HORIZONTAL lines at the price high and price low of the highest volume bar within the last 240 bars as pictured below. I get tired of manually having to do this all the time. Much appreciation if someone can help with this. Example below.

I can get this far in finding the highest volume bar, but i don't know how to plot it with the price lines.

Code:
``````input barsago = 240;

def HighestVolume =  Highest(volume, barsago);`````` Edit: Found this by Mobius. High Volume Nodes (plots the high/low price of the highest volume bar within x bars). Code:
``````# High Volume Nodes

# Mobius

# V01.02.2018

# Looks for the highest volume candle in "n" periods and plots the candle range.

# As Volatility increases this study has two values. Plotting a current high volume node as a channel which price will be drawn back to and test since a very high volume node will move price quickly, and price will retest that area. And, with the legacy plots a way to quickly see if larger traders, those that can generate a high volume node, are accumulating or distributing inventory.

input n = 20;

input LegacyPoints = yes;

def h = high;

def l = low;

def c = close;

def v = volume;

def x = barNumber();

def HighVolume = if ((v - Lowest(v, n)) / (Highest(v, n) - Lowest(v, n))) >= 1

then x

else Double.NaN;

def hh = if !IsNaN(HighVolume)

then h

else hh;

def ll = if !IsNaN(HighVolume)

then l

else ll;

plot hhLine = if x >= HighestAll(HighVolume)

then HighestAll(if IsNaN(c)

then hh

else Double.NaN)

else Double.NaN;

hhLine.SetDefaultColor(Color.GRAY);

plot llLine = if x >= HighestAll(HighVolume)

then HighestAll(if IsNaN(c)

then ll

else Double.NaN)

else Double.NaN;

llLine.SetDefaultColor(Color.GRAY);

plot legacy = if LegacyPoints and !IsNaN(HighVolume)

then l - (2*TickSize())

else Double.NaN;

legacy.SetStyle(Curve.POINTS);

legacy.SetLineWeight(3);

legacy.SetDefaultColor(Color.Gray);

# End Code High Volume Nodes``````

Last edited:
• Jonas99

#### markos

##### Well-known member
VIP
@XeoNoX Try this snippet. Hacked from @tomsk share. I'm sure this is incorrect, but I don't have access to the editor.

Code:
``````input period = 240;

def HighestVolume =  Highest (volume, period);

plot highLine = HighestAll (if isNaN then high (period) else Double.NaN);
plot LowLine = LowestAll (if isNaN then high (period) else Double.NaN);``````

#### XeoNoX

##### Well-known member
VIP
@markos That didn't work. and it returned some errors, I need it to plot at the largest volume bar, hence thats my dilema that i cant figure out. Anyone have any suggestions? i know it can be done, i just cant figure it out.

I tried this and it doesn't work, but it grabs at least the volume bar, lol, my brain is going crazy trying to figure it out.

Code:
``````declare upper;

input period = 240;
def na = Double.NaN;
def HighestVolume =  Highest (volume, period);

plot highLine = HighestAll (if na  then HighestAll (period) else Double.NaN);
plot LowLine = LowestAll (if na then Lowest (period) else Double.NaN);

highline.SetDefaultColor(GetColor(9));
highline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

i tried this and it doesnt work, but it grabs atleast the volume bar, lol, my brain is going crazy trying to figure it out, ill wait for you @tomsk and thanks if you can figure it out!

Last edited:

#### tomsk

##### Well-known member
VIP
@markos Hey, a valiant effort! It is probably easiest to capture the bar number where that high volume occurred and then note the high/low levels. After which you can then plot the lines forward from the bar number identified. I am working on this, should have this done in 5, maybe 10 minutes.

@XeoNoX Per your request, here is your COMPLETED study. I have used the input of 240 bars that you mentioned in your description. This can be configurable in the user interface.

Here is the methodology - As with most things in the ThinkScript world, it would simplify things if you captured the bar number when the event took place. Then take note of the high/low at the bar number. Then you can do your plots forward from that bar number to the end of the chart. I have tested this against both intraday as well as daily, and ran it against charts of PCG (think that was your exmaple), AAPL, FB, etc

Code:
``````# Plots High/Low Price at Highest Volume
# tomsk
# 12.4.2019

input barsago = 240;

def bar = barNumber();
def HighVolBar = if ((volume - Lowest(volume, barsago)) /
(Highest(volume, barsago) - Lowest(volume, barsago))) >= 1
then bar
else Double.NaN;
def VolHighLevel = if !IsNaN(HighVolBar) then high else VolHighLevel;
def VolLowLevel = if !IsNaN(HighVolBar) then low else VolLowLevel;

plot HighLine = if bar >= HighestAll(HighVolBar) then VolHighLevel else Double.NaN;
plot LowLine = if bar >= HighestAll(HighVolBar) then VolLowLevel else Double.NaN;

HighLine.SetDefaultColor(Color.CYAN);
HighLine.SetLineWeight(3);
LowLine.SetDefaultColor(Color.YELLOW);
LowLine.SetLineWeight(3);
# End Plots High/Low Price at Highest Volume``````

• markos and XeoNoX

#### XeoNoX

##### Well-known member
VIP
yup, i would have never figured that out, thats advanced coding, brother @tomsk you are gifted, thank you very much. i am in amazment you did that in 10 minutes. i been trying for 2 days. And my average studies take me about a week and are no where near this complex. thanks again brother for your time.

#### tomsk

##### Well-known member
VIP
@XeoNoX I have seen your intermediate work, really nice to see you try different things.
Keep at it, I have no doubt that you'll be a master very soon.

Actually I was helping a user in another chatroom code something not too dissimilar - He was looking at plotting a horizontal line when there was a 50/200 EMA crossover. Same concept applies but different variables need to be tracked.

#### XeoNoX

##### Well-known member
VIP
i have a few questions if you dont mind explaining. Why did you VOLUME MINUS LOWEST VOLUME from previous 240 bars? what does this do? in regular English it sounds like you subtracted the highest and lowest volume bar from 240 bars ago??? im so confused mind teaching me in a quick explination if you have time?

and what does the "/" and ">=1" do? And im still trying to figure out how the Double.NaN is used. Can you explain by any chance? thanks @tomsk #### tomsk

##### Well-known member
VIP
That is a standard way of comparing range of high-low volumes across an extended period.
Compute the ratio divided by the range of the high-low volume.

If the value that is returned is > 1 then you got your higher volume scenario.
Let's say the ratio returned is 0.4, then you immediately know that you're running at 40% of the high-low volume

It does this computation as it works through every single bar across the chart
Double.NaN is the standard ThinkScript way of assigning NO VALUE
It's just the way I've learnt to do this.

EDIT: I thought it might be instructive to illustrate this by way of a simple example
Let's say you are trading AMZN and want to know how it is performing relative to it's high to low range
Run the following script and you'll see that it is at 18%, so not doing too good today.
Compare that with a ticker symbol of AAPL, it is running at about 68% so is doing good today
That is the general principle I was using in my calculations above.

Code:
``````# Range Performance
# tomsk
# 12.5.2019

input symb = "AMZN";

def h = high(symbol = symb, period = AggregationPeriod.DAY);
def l = low(symbol = symb, period = AggregationPeriod.DAY);
def c = close(symbol = symb, period = AggregationPeriod.DAY);
def R = (c - l) / (h - l);

AddLabel(1, symb + " currently at " + AsPercent(R) + " of daily range", Color.Yellow);
# End Range Performance``````

Last edited:
• SolidChiken, markos and XeoNoX

##### Member
@tomsk you are the man!!!! i was wondering if its a way to make a chart label on the daily chart of the highest total volume day of the year and also have the actual day it happened as well?

#### tomsk

##### Well-known member
VIP
@tradeking313 Per your request here is a chart label that displays highest volume of the year together with the date that was traded.
make sure you run this on a DAILY aggregation. Interesting to note that on a stock like AAPL, the highest volume was precisely one year ago, on 1/3/2019. Have fun running this against your favorite stocks!

Code:
``````# Highest Daily Volume Label
# tomsk
# 1.3.2020

def H = volume == HighestAll(volume);
def HV = if H then volume else HV;
def MM = HighestAll(if H then GetMonth() else Double.NaN);
def DD = HighestAll(if H then GetDayOfMonth(GetYYYYMMDD()) else Double.NaN);
def YY = HighestAll(if H then GetYear() else Double.NaN);
AddLabel(1, "Highest Daily Volume (" + HV + ") Traded On " + MM + "/" + DD + "/" + AsPrice(YY), Color.Yellow);
# End Highest Daily Volume Label``````

##### Member
@XeoNoX @tomsk i love the plotting of the highest volume bar on the Daily chart. Great work!!!..Now im wondering if theres a way to create a scanner that finds stocks that has hit its highest volume bar on the Daily aggregation within X bars ago. ( i.e. 5 days ago)

#### tomsk

##### Well-known member
VIP
@tradeking313 Sure thing - place the following code directly in the scanner. It will find the highest daily volume that triggered within the last 5 bars. Running this scan against the S&P 500 I obtained 1 result and for the NASDAQ Comp, there were 56 results.

Code:
``volume == HighestAll(volume) within 5 bars``

#### Ginu09

##### Member
Hey everyone, I'm new to the forum. I wanted to ask, I'm trying to plot the highs of the 5 highest volume candles on a daily chart with an added constraint that the prices should be incrementally higher of those candles.

By that I mean, if I take the highest volume candle just to the left of today with high P1, then I’m looking for the next one left of it P2 where P2 > P1, then P3 > P2, P4 > P3 and P5 > P4. By extension, these may not end up being the highest volume candles (as they may fall between these candles with lower prices) but it is an added constraint.

The logic would be:
-Find the 5 highest volume candle on the daily chart.
-Plot the high of the first candle (P1) closest to today.
-Zero price all prices to the left below that price.
-Find the 4 highest volume candles where price > P1, etc.

Can someone help me to tweak one of the related resistance scripts? I'd really appreciate it. Thanks!

Typically high volume bars are retraced and price will range within that bars range for some time before breaking out to a new level. This study plots those bars range as pivots that can be traded as any other pivot study. http://tos.mx/gu3Cf3o

#### Kliphten

##### New member
@tomsk Is there a way to have this plot on each session? The use of HighestAll() on the bar means the plot only shows up on the last bar with the greatest volume. I'm stuck getting this to plot the highest volume bar's high/low each day. Thanks!

Code:
``plot HighLine = if bar >= HighestAll(HighVolBar) then VolHighLevel else Double.NaN;``

I tried something like this instead of above...

Code:
``plot HighLine = if bar >= GetValue(HighVolBar, GetMaxValueOffset(HighVolBar, 999), 999) then VolHighLevel else Double.NaN;``

Since bars in past are all lower, this is fine. I just don't want it looking into the future for bars with higher volume, which HighestAll() does. However, this does not seem to work.

Also, when there is a higher volume bar later in the day, I want the high/low to be drawn from that bar, so the previous high/lows are removed. Is this even possible?

#### Mnschmid18

##### New member
Hello, I am new here and looking for help. I would like to create a scanner for the highest volume bar of the day on 5 minute or 10 min chart. Of course it is typically the first candle of the day so omitting that one would be ideal. Would anyone know how to accomplish this? Your help is much appreciated.

Code:
``````#Description:  Identify bars with high volume relative to the tick count.  Such bars could indicate a block trade, or a possible change in trend.
#Author: Dilbert
#Requested By:
# Ver     Date     Auth      Change
# V1      090717   Dilbert   1st code cut

#
# Trading Notes:  Identify bars with high volume relative to the tick_count.  Such bars could indicate a block trade, or a possible change in trend.
declare lower;
input AvgType = AverageType.EXPONENTIAL;
input MaLength = 20;
def V = volume;
def TC = tick_count;
plot TradeSize = V / TC;

input displace = 0;
input SdLength = 20;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;

def sDev = StDev(data = TradeSize[-displace], length = SdLength);

def MA = MovingAverage(AvgType,  TradeSize, MaLength);
plot Dot = if TradeSize > Ma + (sDev * Num_Dev_up) then TradeSize else Double.NaN;
Dot.SetPaintingStrategy(PaintingStrategy.Points);
Dot.SetLineWeight(5)``````

#### LennyZ1

##### New member
Is there a way to plot the 10 highest volume bars price based on the passed in chart (3YW, 180 D hourly, etc)? This way, can create s/r price lines. And if optional also plot the low price of the high volume bars?

Code:
``````# High Volume Candles
# Mobius
# Chat Room Request 02.07.2020

Input n = 60;

def v = volume;
def c = close;
def nan = double.nan;
def x = barNumber();
def HV = highest(v, n);
def xV = if v == HV
then x
else xV;
def HVc = if v == HV
then c
else HVc;
plot HVcandle = if x >= highestAll(xV)
then highestAll(if isNaN(c[-1])
then HVc
else nan)
else nan;
HVcandle.SetStyle(Curve.Firm);
HVcandle.SetLineWeight(2);
HVcandle.SetDefaultColor(Color.Yellow);
AddChartBubble(x == HighestAll(x), HVcandle, "n"+n, HVcandle.TakeValueColor());
# End Code High Volume Candle``````

#### Learnbot

##### Active member
Hi guys/gals,

Quick question, like many of the studies posted on this forum about adding label to high of the day and low of the day price in TOS, is there a way to add label to high of the day and low of the day volume bar?

What I’m trying to do is, divide current bar volume by highest (so far) volume and return in percentage

Thank you

Last edited by a moderator:

#### An.Drey

##### New member
To improve my strategy, I want to supplement my scanner. I need to find the bar with the highest volume on the 5min timeframe for yesterday (but not a last bar). I want the scanner to find when the closing of the current candle is below the low of this bar.
The low of this bar should not have been breakdown yesterday. My thinkscript knowledge is not enough to implement this. I hope for your help.

@tomsk Is there a way to modify this script to find only bar with highest volume where current price not breakdown low line? Thanks! Last edited by a moderator:

#### BenTen

Staff member
Staff
VIP
I modified the script that @korygill created here and replaced the A/D (Advanced Decline) line with volume. This indicator will plot the previous day's highest volume as a line on the current trading day.

Not sure how useful this is. I thought I'd share it for anyone using volume as a tool to help them trade. thinkScript Code
Code:
``````# Previous Day's Highest Volume Line
# Based on the existing script of Kory Gill (@korygill) for BenTen at usethinkscript.com
#

declare lower;
declare once_per_bar;

input OpenTime = 0930;

def bn = BarNumber();
def nan = double.NaN;
def sft = SecondsFromTime(Opentime);

def vol = volume;
def hVal;
def lVal;

if bn == 1 then
{
hVal = nan;
lVal = nan;
}
else if bn == 2 then
{
hVal = vol;
lVal = vol;
}
else
{
if sft == 0 then
{
hVal = vol;
lVal = vol;
}
else
{
hVal = Max(hVal, vol);
lVal = Min(lVal, vol);
}
}

def pdh = if sft[-1] == 0 then hVal else pdh;
def pdl = if sft[-1] == 0 then lVal else pdl;

plot ppdh = pdh;
plot ppdl = pdl;
ppdh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdh.SetDefaultColor(GetColor(1));
ppdl.SetDefaultColor(GetColor(0));

plot pvol = vol;

def IsUp = close > open;
def IsDown = close < open;

pvol.AssignValueColor(if vol > pdh and isDown then color.red else if vol > pdh and isup then color.green else color.gray);``````

• korygill

#### Hohoba

##### New member
First of all, thank you @tomsk for the code, super helpful! And great question from @XeoNoX So apparently the output varies with different time frames, is there a way to show the results of 1-min time frame on a 2-min chart? Thank you so much!