Total volume of certain period 1 day ago

kvr53

New member
As an example, it's now at 21:00 Tuesday, how do I make a column showing total volume from 9:30 to 13:00 for yesterday (Monday)

Saw some codes about total volume, but the number they show is of the same trading day at the time they check the column. If it's Tuesday, the column shows total volume 9:30-13:00 for Tuesday

I want that total volume to be 1 daily bar ago as of the time I check it
 
Solution
@kvr53
Ruby:
def Start_Time = 0930;
def End_Time = 1300;
def vol = volume;
def Day = GetDay();
def LastDay = GetLastDay();

def PM_Total_Volume;
if SecondsTillTime(Start_Time) == 0 and Day < LastDay {
PM_Total_Volume = vol;
}else if SecondsFromTime(Start_Time) > 0 and SecondsTillTime(End_Time) > 0 and Day < LastDay {
PM_Total_Volume = PM_Total_Volume[1] + vol;
}else {
PM_Total_Volume = PM_Total_Volume[1];}

addlabel(yes,"Yesterdays TimeFrame Total Volume: " + PM_Total_Volume,color.white);
@kvr53
Ruby:
def Start_Time = 0930;
def End_Time = 1300;
def vol = volume;
def Day = GetDay();
def LastDay = GetLastDay();

def PM_Total_Volume;
if SecondsTillTime(Start_Time) == 0 and Day < LastDay {
PM_Total_Volume = vol;
}else if SecondsFromTime(Start_Time) > 0 and SecondsTillTime(End_Time) > 0 and Day < LastDay {
PM_Total_Volume = PM_Total_Volume[1] + vol;
}else {
PM_Total_Volume = PM_Total_Volume[1];}

addlabel(yes,"Yesterdays TimeFrame Total Volume: " + PM_Total_Volume,color.white);
 
Solution
@kvr53
Ruby:
def Start_Time = 0930;
def End_Time = 1300;
def vol = volume;
def Day = GetDay();
def LastDay = GetLastDay();

def PM_Total_Volume;
if SecondsTillTime(Start_Time) == 0 and Day < LastDay {
PM_Total_Volume = vol;
}else if SecondsFromTime(Start_Time) > 0 and SecondsTillTime(End_Time) > 0 and Day < LastDay {
PM_Total_Volume = PM_Total_Volume[1] + vol;
}else {
PM_Total_Volume = PM_Total_Volume[1];}

addlabel(yes,"Yesterdays TimeFrame Total Volume: " + PM_Total_Volume,color.white);
Thank you for the post, tried your codes just now at 22:00, It doesn't show the correct sum of volume 9:30-13:00 for 1 daily bar ago

Have you tested them? You can change the time to 9:30-9:33, so it's easier to manually count the volume and compare it to what this label shows, they don't match though.
 
@kvr53 current code does not include the bar at end time as that volume is occurring after the end time. If you want it to include that bar then change:
Ruby:
}else if SecondsFromTime(Start_Time) > 0 and SecondsTillTime(End_Time) > 0 and Day < LastDay

to this:
Ruby:
}else if SecondsFromTime(Start_Time) > 0 and SecondsTillTime(End_Time) >= 0 and Day < LastDay

also, if you want to see the chart bubble for that bar then change:
Ruby:
addchartbubble(SecondsFromTime(Start_Time) >= 0 and SecondsTillTime(End_Time) > 0, high, "Total Vol\n" + PM_Total_volume+"\n"+vol,color.white,yes);

to;
Ruby:
addchartbubble(SecondsFromTime(Start_Time) >= 0 and SecondsTillTime(End_Time) >= 0, high, "Total Vol\n" + PM_Total_volume+"\n"+vol,color.white,yes);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
258 Online
Create Post

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