# Highest Volume of the year

##### New member
Hello,
Appreciate if someone can help with the below thinkscript. I am looking to show a plot on the chart on the day / bar of the highest volume of the past year. This script displays more than one day in the past year or sometimes doesn't display the plot at all .

def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;

def length = if IsDaily then 252 else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;
def highvol = Highest(volume, length);

plot top = if volume == highvol then 1 else Double.NaN;

top.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
top.SetDefaultColor(color.WHITE);

Solution
This below code seems to solve the problem:

def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;
def length = if IsDaily then 252 else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;

#def LastBar = HighestAll(if isNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN);
#def BarCD = LastBar - BarNumber() <= Length;
#def HighVol = HighestAll(if BarCD then Volume else Double.nan);
def highvol = HighestAll(volume);
#plot VolLine = if BarCD then HighVol else Double.nan;

plot top = if volume == highvol then volume else Double.NaN...
Ruby:
``````def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;
def length = if IsDaily then 252 else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;
#
def LastBar =
HighestAll(if isNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN)
;
def BarCD =
LastBar - BarNumber() <= Length
;
def HighVol =
HighestAll(if BarCD then Volume else Double.nan)
;
plot VolLine =
if BarCD then HighVol else Double.nan
;
#
plot top = if volume == highvol then volume else Double.NaN;
top.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
top.SetDefaultColor(color.WHITE);
top.setlineWeight(5);``````

Ruby:
``````def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;
def length = if IsDaily then 252 else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;
#
def LastBar =
HighestAll(if isNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN)
;
def BarCD =
LastBar - BarNumber() <= Length
;
def HighVol =
HighestAll(if BarCD then Volume else Double.nan)
;
plot VolLine =
if BarCD then HighVol else Double.nan
;
#
plot top = if volume == highvol then volume else Double.NaN;
top.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
top.SetDefaultColor(color.WHITE);
top.setlineWeight(5);``````
Thanks for the help Joshua, but unfortunately this renders the chart unusable. I am unable to see the bars / candles.https%3A//i.imgur.com/kbPI6BG.png[/img]']

Last edited:
Im posting from my phone at the moment, what am I looking at here, I can't see it? Is your volume overlayed in the price chart?

Try putting the volume in it's own panel and make sure the code is on the volume section in edit studies and tell me what happens.

Last edited:
Im posting from my phone at the moment, what am I looking at here, I can't see it? Is your volume overlayed in the price chart?
Yes Joshua, I have the volume overlayed on the chart. am attaching here 2 images one which shows the chart normally which is using my code and the other image which uses the code you gave above Original code, but doesn't show up any candles on the chart.

original code
New Code

This is what happens even with no volume overlay

It looks like the volume average is enabling the left side price axis and throwing off the scaling?

Hello,
Appreciate if someone can help with the below thinkscript. I am looking to show a plot on the chart on the day / bar of the highest volume of the past year. This script displays more than one day in the past year or sometimes doesn't display the plot at all .

def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;

def length = if IsDaily then 252 else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;
def highvol = Highest(volume, length);

plot top = if volume == highvol then 1 else Double.NaN;

top.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
top.SetDefaultColor(color.WHITE);
https://tos.mx/X8DGDT This may help, volume indicator showing total, buy, and sell volumes as a histogram. Also average volume as a line plot. Bars with a specified percent over the average volume are marked on the bar. Additional Volume information provided by labels.

This below code seems to solve the problem:

def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;
def length = if IsDaily then 252 else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;

#def LastBar = HighestAll(if isNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN);
#def BarCD = LastBar - BarNumber() <= Length;
#def HighVol = HighestAll(if BarCD then Volume else Double.nan);
def highvol = HighestAll(volume);
#plot VolLine = if BarCD then HighVol else Double.nan;

plot top = if volume == highvol then volume else Double.NaN;
top.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
top.SetDefaultColor(color.WHITE);
top.setlineWeight(5);

That will work assuming you have only one years worth of data on the chart. Otherwise, it will show you the highest volume for how ever far back the chart goes.

Ok, so I am home now and at an actual computer.

Change this line:

Code:
``````def BarCD =
LastBar - BarNumber() <= Length
;``````

to

Code:
``````def BarCD =
LastBar - BarNumber() + 1 <= Length
;``````

The start of the year was off by one bar if you want to get really specific, but that is not the problem, in fact, what is the problem? That is the highest volume in the last years worth of data, is it not?

Ok, so I am home now and at an actual computer.

Change this line:

Code:
``````def BarCD =
LastBar - BarNumber() <= Length
;``````

to

Code:
``````def BarCD =
LastBar - BarNumber() + 1 <= Length
;``````

The start of the year was off by one bar if you want to get really specific, but that is not the problem, in fact, what is the problem? That is the highest volume in the last years worth of data, is it not?

I do appreciate you getting back to me, but this too doesn't solve the problem as you can see we don't see the candlestick chart. I want to be able to see the chart as well as have a plot shown on it signifying the day of the highest volume to drawn my eye to it while studying the chart.

Last edited:

87k+ Posts
315 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?