Average Volume

naquan24

Member
Good evening...on a 5 minute chart, is there a way to create a relative time volume chart so you can what the average volume was for the last 5 days for the current bar. (I.E, at 10:05am on lets say jan 5, see what the average volume was on 10:05am on Jan 4, 3rd, 2nd and 1st) and then have a line that shows if the current volume is higher or lower than the average.
 
Last edited:
Solution
Good evening...on a 5 minute chart, is there a way to create a relative time volume chart so you can what the average volume was for the last 5 days for the current bar. (I.E, at 10:05am on lets say jan 5, see what the average volume was on 10:05am on Jan 4, 3rd, 2nd and 1st) and then have a line that shows if the current volume is higher or lower than the average.

This gives you the option to use the at 10:05 that bar's volume or the 5 bar (not day) average volume at that bar to create a number of days you input for an average. This excludes the current day's bar and compares it to the average. If today is greater than the average, then the label will be colored green elsewise red.

The debug option allows you to test the...
Good evening...on a 5 minute chart, is there a way to create a relative time volume chart so you can what the average volume was for the last 5 days for the current bar. (I.E, at 10:05am on lets say jan 5, see what the average volume was on 10:05am on Jan 4, 3rd, 2nd and 1st) and then have a line that shows if the current volume is higher or lower than the average.

This gives you the option to use the at 10:05 that bar's volume or the 5 bar (not day) average volume at that bar to create a number of days you input for an average. This excludes the current day's bar and compares it to the average. If today is greater than the average, then the label will be colored green elsewise red.

The debug option allows you to test the script or otherwise modify it to your liking.

The image below is shown with the debug set to yes. The values below indicate each day;s value. The bubbles will display the Voltype value at the 10:05 bar each day.

Capture.jpg
Ruby:
input days    = 5;
input time    = 1005;
input avglen  = 5;
input Voltype = {default Volume, Avgvolume};

def ymd       = GetYYYYMMDD();
def candles   = !IsNaN(close);
def capture   = candles and ymd != ymd[1];
def dayCount  = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay   = (HighestAll(dayCount) - dayCount) ;
def x         = Between(thisDay, 1, days);

def volattime = if x and SecondsFromTime(time) == 0
                then (if Voltype == Voltype.Volume then VolumeAvg(length = avglen).vol else VolumeAvg(length = avglen).VolAvg) + volattime[1]
                else volattime[1];
def todayvol  = if thisDay == 0 and SecondsFromTime(time) == 0
                then (if  Voltype == Voltype.Volume
                      then VolumeAvg(length = avglen).vol
                      else VolumeAvg(length = avglen).VolAvg)
                else todayvol[1];

AddLabel(1, days + " Days @ " + AsPrice(time)  + " Total " + Voltype + ": " + Round(volattime, 0) + "  Avg : " + Round((volattime / days), 0), Color.WHITE);

AddLabel(1, " Today's " + Voltype + ": " + Round(todayvol, 0), if todayvol > (volattime / days) then Color.GREEN else Color.RED);


input debug = no;

AddChartBubble(debug and SecondsFromTime(1005) == 0, low, Round(if  Voltype == Voltype.Volume then VolumeAvg(length = avglen).vol else VolumeAvg(length = avglen).VolAvg, 0) );

plot y = if !debug then Double.NaN else thisDay == 0 and SecondsFromTime(1005) == 0;
y.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 
Solution
This gives you the option to use the at 10:05 that bar's volume or the 5 bar (not day) average volume at that bar to create a number of days you input for an average. This excludes the current day's bar and compares it to the average. If today is greater than the average, then the label will be colored green elsewise red.

The debug option allows you to test the script or otherwise modify it to your liking.

The image below is shown with the debug set to yes. The values below indicate each day;s value. The bubbles will display the Voltype value at the 10:05 bar each day.
SleepyZ thanks for this...can I ask...is there anyway of putting it as line instead of bubbles....cause I was trying to use a line to show the average volume as a line going across between the volume bars so I can see where there is a higher than average volume.
 
SleepyZ thanks for this...can I ask...is there anyway of putting it as line instead of bubbles....cause I was trying to use a line to show the average volume as a line going across between the volume bars so I can see where there is a higher than average volume.

Here is the modified script below shown as a line on the volume bars. The upper chart displays the original script.

Capture.jpg
Rich (BB code):
declare on_volume;

input days    = 5;
input time    = 1005;
input avglen  = 5;
input Voltype = {default Volume, Avgvolume};

def ymd       = GetYYYYMMDD();
def candles   = !IsNaN(close);
def capture   = candles and ymd != ymd[1];
def dayCount  = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay   = (HighestAll(dayCount) - dayCount) ;
def x         = Between(thisDay, 1, days);

def volattime = if x and SecondsFromTime(time) == 0
                then (if Voltype == Voltype.Volume then VolumeAvg(length = avglen).vol else VolumeAvg(length = avglen).VolAvg) + volattime[1]
                else volattime[1];
def todayvol  = if thisDay == 0 and SecondsFromTime(time) == 0
                then (if  Voltype == Voltype.Volume
                      then VolumeAvg(length = avglen).vol
                      else VolumeAvg(length = avglen).VolAvg)
                else todayvol[1];

plot avgtime = volattime/days;

AddLabel(1, days + " Days @ " + AsPrice(time)  + " Total " + Voltype + ": " + Round(volattime, 0) + "  Avg : " + Round((volattime / days), 0), Color.WHITE);

AddLabel(1, " Today's " + Voltype + ": " + Round(todayvol, 0), if todayvol > (volattime / days) then Color.GREEN else Color.RED);


input debug = no;

AddChartBubble(debug and SecondsFromTime(1005) == 0, low, Round(if  Voltype == Voltype.Volume then VolumeAvg(length = avglen).vol else VolumeAvg(length = avglen).VolAvg, 0) );

plot y = if !debug then Double.NaN else thisDay == 0 and SecondsFromTime(1005) == 0;
y.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 
Sleepy thank you for this but just I know how to use it....can you tell me where I can update it so uses just that days average. I know its difficult to get it to calculate the average volume for 9:30am for the past 5 days.....so I was trying to get it to simply use the average volume for just that day. That way when the market opens at 9:30am, it will use just the volume of 9:30am. That way by 10:05am and using a 5 minute chart, it would have just used 9:30am, 9:35am, 9:40am, 9:45am, 9:50am, 9:55am, and 10:00am, to determine what the average should be by 10:05am and so on. Is that possible? And having it show as a line?
 
Sleepy thank you for this but just I know how to use it....can you tell me where I can update it so uses just that days average. I know its difficult to get it to calculate the average volume for 9:30am for the past 5 days.....so I was trying to get it to simply use the average volume for just that day. That way when the market opens at 9:30am, it will use just the volume of 9:30am. That way by 10:05am and using a 5 minute chart, it would have just used 9:30am, 9:35am, 9:40am, 9:45am, 9:50am, 9:55am, and 10:00am, to determine what the average should be by 10:05am and so on. Is that possible? And having it show as a line?

It was easier to rewrite than modify the above script for your request

Capture.jpg
Ruby:
declare on_volume;

input begin   = 0930;
input till    = 1005;
def bars      = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
                   SecondsTillTime(till) > 0
                then bars[1] + 1
                else bars[1];
def todayvol  = if GetDay() == GetLastDay() and
                   SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
                then todayvol[1] + volume                     
                else todayvol[1];
plot avgtime = todayvol / bars;

input showlabel = yes;
AddLabel(showlabel, bars + " bars @ " + AsPrice(till)  + " Total Volume : " + Round(todayvol, 0) + "  Avg : " + Round((avgtime), 0), if volume > avgtime then Color.GREEN else Color.RED);

input debug = yes;

AddChartBubble(debug and SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0, low, "B: " + Round(volume, 0) + " \n T: " + Round(todayvol, 0) + " \n A:" + Round(avgtime, 0), Color.WHITE );

plot y = if !debug then Double.NaN else SecondsFromTime(0930) >= 0 and SecondsFromTime(1005) == 0;
y.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 
Make sure you have volume subgraph checked in chart settings for the type of symbol you are viewing
Yes...I clicked on the chart settings and the subgraph button was already check. Can you tell me if I missed something...below is what I copied and uploaded. I think put it in the lower column of the strategy. But I'm still getting the oooooo across the board. can you view the code and tell me if I copied it correctly?

declare on_volume;

input begin = 0930;
input till = 1005;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];
plot avgtime = todayvol / bars;

input showlabel = yes;
AddLabel(showlabel, bars + " bars @ " + AsPrice(till) + " Total Volume : " + Round(todayvol, 0) + " Avg : " + Round((avgtime), 0), if volume > avgtime then Color.GREEN else Color.RED);

input debug = yes;

AddChartBubble(debug and SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0, low, "B: " + Round(volume, 0) + " \n T: " + Round(todayvol, 0) + " \n A:" + Round(avgtime, 0), Color.WHITE );

plot y = if !debug then Double.NaN else SecondsFromTime(0930) >= 0 and SecondsFromTime(1005) == 0;
y.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 
Yes...I clicked on the chart settings and the subgraph button was already check. Can you tell me if I missed something...below is what I copied and uploaded. I think put it in the lower column of the strategy. But I'm still getting the oooooo across the board. can you view the code and tell me if I copied it correctly?

declare on_volume;

input begin = 0930;
input till = 1005;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];
plot avgtime = todayvol / bars;

input showlabel = yes;
AddLabel(showlabel, bars + " bars @ " + AsPrice(till) + " Total Volume : " + Round(todayvol, 0) + " Avg : " + Round((avgtime), 0), if volume > avgtime then Color.GREEN else Color.RED);

input debug = yes;

AddChartBubble(debug and SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0, low, "B: " + Round(volume, 0) + " \n T: " + Round(todayvol, 0) + " \n A:" + Round(avgtime, 0), Color.WHITE );

plot y = if !debug then Double.NaN else SecondsFromTime(0930) >= 0 and SecondsFromTime(1005) == 0;
y.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
Here is a share link to a chart with the above code for AAL 30D 5m chart http://tos.mx/QFvWa35
 
I imported to my screen and it still shows the ooooooos....I going to wait till live trading to see if it changes......also is there a way to take out those text bubbles/ notes....it blocks the volume....I just wanted to see the volume bars and the line.
 
I imported to my screen and it still shows the ooooooos....I going to wait till live trading to see if it changes......also is there a way to take out those text bubbles/ notes....it blocks the volume....I just wanted to see the volume bars and the line.

To not display the bubbles, set input debug to NO. The bubbles were just used to allow testing of the code by the user and coder.

Otherwise, if you are having trouble, either provide chart info you are using when this happens or share a link as I did.
 
Ok. I will try to express myself in a better way.
1) If B1 (current) is greater than B1 (of the previous bar) and B2 (current) is less than B2 (of the previous bar) then place an arrow above the price, on the upper chart.
2) If B1 (current) is less than B1 (of the previous bar) and B2 (current) is greater than B2 (of the previous bar) then place an arrow below the price, on the upper chart.
 
Ok. I will try to express myself in a better way.
1) If B1 (current) is greater than B1 (of the previous bar) and B2 (current) is less than B2 (of the previous bar) then place an arrow above the price, on the upper chart.
2) If B1 (current) is less than B1 (of the previous bar) and B2 (current) is greater than B2 (of the previous bar) then place an arrow below the price, on the upper chart.

Thanks, that will work, as I did not want to code without being sure.

The image below is a 30m chart with the begin time as 0930 as I could not find any example for today in my watchlist set for 1hr.

Capture.jpg
Rich (BB code):
#declare on_volume;

input begin   = 0900;
input till    = 1600;
def bars      = if getday()==getlastday() and SecondsFromTime(begin) >= 0 and
                   SecondsTillTime(till) > 0
                then bars[1] + 1
                else bars[1];
def todayvol  = if getday()==getlastday() and SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
                then todayvol[1] + volume                    
                else 0;
input symbol1 = "JBLU";
def todayvol1 = if getday()==getlastday() and SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
                then todayvol1[1] + volume(symbol1)                  
                else 0;
input symbol2 = "DAL";
def todayvol2 = if getday()==getlastday() and SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
                then todayvol2[1] + volume(symbol2)                  
                else 0;
def totvol   = todayvol + todayvol1 + todayvol2;
plot avgtime = totvol / bars;

input showlabel = yes;
AddLabel(showlabel, bars + " bars @ " + AsPrice(till)  + " Total Volume : " + Round(totvol, 0) + "  Avg : " + Round((avgtime), 0), if volume > avgtime then Color.GREEN else Color.RED);

input debug = yes;

#AddChartBubble(debug and SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0, low, "B: " + Round(volume, 0) + "\nB1: " + Round(volume(symbol1), 0) + "\nB2: " + Round(volume(symbol2), 0)+ " \n T: " + Round(totvol, 0) + " \n A:" + Round(avgtime, 0), Color.WHITE );

#plot y = if !debug then Double.NaN else SecondsFromTime(0930) >= 0 and SecondsFromTime(1005) == 0;
#y.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);


def B1 = if getday() == getlastday() then volume(symbol1) else 0;
def B2 = if getday() == getlastday() then volume(symbol2) else 0;
addlabel(debug, B1 + " " + B1[1] + " "  + (B1 > B1[1]),  color.white);
addlabel(debug, B2 + " " + B2[1] + " "  + (B2 < B2[1]), color.white);
plot up = If B1 > B1[1] and B2 < B2[1] then 1 else 0;#(place an arrow below the price on the upper chart).
plot dn = If B1 < B1[1] and B2 > B2[1] then 1 else 0;#(place arrow above the price on the chart above).
up.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
dn.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
 
Last edited:
http://tos.mx/sVBPKCD I think I finally got it to load...but now its only showing me the average line in blue...with no volume bars...

You have your volume bars overlapping the price graph. In the image below, go to chart settings and uncheck overlap volume in the cyan circle and you will see the volume bars in the volume subgraph with the average line.

 
[1]Just change the begin time and till times to match the 3 H chart setting. Looks like 1000-1300 would apply.

I added the debug code to the previous code above so you can test it and to assist in other timeframe setting changes you make.
Hello again SleepyZ !!! I am writing to congratulate you for the great work you do for newbies like me. This script is really very useful. I would like to ask you how I can add an alarm (Ej: Avgtime < Avgtime[1] ) and also ask you if that alarm can send me an email when activated.
 
Hello again SleepyZ !!! I am writing to congratulate you for the great work you do for newbies like me. This script is really very useful. I would like to ask you how I can add an alarm (Ej: Avgtime < Avgtime[1] ) and also ask you if that alarm can send me an email when activated.
There are Three Types of Alerts:
There are alerts written into studies. They only alert when the chart w/ the study is open on your screen
They cannot be sent to phone/email. They cannot have custom sounds.
There are alerts created on a chart for one specific stock that you want to alert on.
There are scanned watchlist alerts which alert whenever the results of the scan changes. These alerts can be 3min delayed.

Add the scan syntax to the bottom of your study:
Code:
plot scan = Avgtime < Avgtime[1] ;
scan.hide();
Select your study in the scan hacker.
make your condition
Code:
scan is true
Click on Alert When Scan Results Change:
https://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker
 

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