Calculate daily volume on hourly chart

AD²

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
https://usethinkscript.com/threads/average-daily-range-indicator-for-thinkorswim.244/#post-66296

Code:
# vol_day_total_00

#https://usethinkscript.com/threads/calculate-daily-volume-on-hourly-chart.14002/
#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);

addchartbubble(last, low*0.999,
vadj + "M"
, color.yellow, no);

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

input test1 = no;
addchartbubble(test1 and period_end, high*1.001,
period + "\n" +
period_end + "\n" +
vadj
, 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
AAk5zXe.jpg


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

hal_period
 
Last edited:

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