# Calculate daily volume on hourly chart

##### New member
2019 Donor
Hi, is there a way to sum the volume on the hourly timeframe for the entire day from 4 am to 8 pm and then add a bubble at the end of each day with the total volume for that day?

Hi, is there a way to sum the volume on the hourly timeframe for the entire day from 4 am to 8 pm and then add a bubble at the end of each day with the total volume for that day?

here is one way

since you want something to happen within a time period, that is within a day, and doesn't span over midnight, we can define a variable that is true if the current bar is within the time period.
if that variable is true then add up the volume.

if there are no trades on the start or stop times or between them, my original formula won't work. period won't change to 0.
def last1 = (period and !period[-1]);

added another formula, to check for missing bars
def period_end = if (Secondstilltime(end) >= 0 and t >= 0) and t < t[1] then 1 else 0;

test on /ES (trades 23 hours a day, 6pm to 5pm)

if you need a time period to span over midnight, look at this

Code:
# vol_day_total_00

#Calculate daily volume on hourly chart

def v = volume;
def dayend = getday() <> getday()[-1];
def start = 0400;
def end = 2000;
def period = if ( SecondsFromTime(start) >= 0 and Secondstilltime(end) > 0 ) then 1 else 0;

def t = SecondsFromTime(start)[-1];
# works when bars dont exist , check if t is smaller
def period_end = if (Secondstilltime(end) >= 0 and t >= 0) and t < t[1]  then 1 else 0;
# works when bars exist
def last1 = (period and !period[-1]);
def last = last1 or  period_end ;

def vtotal = if !period then 0
else if period then vtotal[1] + v
else vtotal[1];
def m = 1000000;
def vadj = round(vtotal/m, 3);

, color.yellow, no);

#------------------------------

input test1 = no;
addchartbubble(test1 and period_end, high*1.001,
period + "\n" +
period_end + "\n" +
, color.cyan, yes);
#, (if period_end then color.cyan else color.gray), yes);
#

/ES , day starts at 6pm
has bars on desired start and stop times

AIG , no trades at 4am or 10pm
so bubble appears on last bar before midnight

hal_period

Last edited:

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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