# Daily Sum of Volume Question

#### xfitzz

##### New member
Hi all,

I'm looking for code that will plot the daily sum of a certain day only. I've played around with the TotalSum function, but it obviously changes if I go above Today's time frame. Anyway I can limit it to just today's total sum from 9:30 to 4:00?

Have you checked THIS script to see if it will do your bidding or maybe extract just the code you need...???

Daily Sum of what, Volume...???

Yes, I've checked that. I figured I could extract the code and change the "today" from "def today = Volume(period = "Day"); to "def today = (My Study name)(period = "Day");, but it does not work.

Here you go... I dug around and found a study I wrote a couple weeks ago and forgot about... It probably won't exclude extended trading hours...

Ruby:
``````#Todays_Volume_Label
#
input showTodaysVolumeLabel = yes;
def todaysVolume = volume(period = "DAY");
AddLabel(showTodaysVolumeLabel, "Todays Volume: " + todaysVolume, Color.WHITE);``````

@rad14733 One last question - maybe you can help me here as well.

Here is the code from a previous thread. I've got my comments below.

Code:
``````declare lower;
input LookBack = 20;
def nMinutes = GetAggregationPeriod() / 60000;
def nBars = RoundUp(390 / nMinutes, 0);

def pvSum = fold idx = 1 to LookBack + 1 with a=0 do a + GetValue(volume, idx * nBars, LookBack * nBars);

def pvAvg = pvSum / LookBack;
def VolPct = (volume / pvAvg) * 100;

plot avgLine = 100;
avgLine.SetDefaultColor(Color.GRAY);
avgLine.SetStyle(Curve.LONG_DASH);

def lastUp = if IsNaN(lastUp[1]) then 0 else if (close > open) then VolPct else lastUp[1];
def lastDn = if IsNaN(lastDn[1]) then 0 else if (close < open) then VolPct else lastDn[1];

plot Vol = VolPct;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.DefineColor("Bullish", Color.CYAN);
Vol.DefineColor("Bullish Smaller", CreateColor(0, 128, 128));
Vol.DefineColor("Bearish", Color.MAGENTA);
Vol.DefineColor("Bearish Smaller", CreateColor(128, 0, 128));
Vol.AssignValueColor(if (close > open) and (VolPct > lastUp[1]) then Vol.Color("bullish" ) else if close > open then Vol.Color("bullish smaller" ) else if close < open and VolPct > lastDn[1] then Vol.Color("bearish" ) else Vol.Color("bearish smaller" ));
Vol.SetLineWeight(3);``````

#My comments/question: is there a way to get the daily sum (as in today's daily sum only that resets each morning at 9:30 AM at new market open) for the plot Vol?

Thank you!

Last edited by a moderator:
@rad14733 @BenTen any help with the above? Looking for the total from market open of the plot Vol. Should start at 0 every morning at 9:30. I've tried many different things but cannot get it the daily sum to be correct.

@rad14733 @BenTen any help with the above? Looking for the total from market open of the plot Vol. Should start at 0 every morning at 9:30. I've tried many different things but cannot get it the daily sum to be correct.
@mashume you may be able to tell me if this is possible as well. Thank you!

@mashume you may be able to tell me if this is possible as well. Thank you!
Not at my station with ToS, but perhaps something like this:

Code:
``````def pvSum =
if SecondsFromTime(0930) >= 0 then
fold idx = 1 to LookBack + 1
with a=0
do a + GetValue(volume, idx * nBars, LookBack * nBars)
else
0;``````

You don't, of course, need that much whitespace... it just makes it easier for me to think in a text editor.

-mashume

Not at my station with ToS, but perhaps something like this:

Code:
``````def pvSum =
if SecondsFromTime(0930) >= 0 then
fold idx = 1 to LookBack + 1
with a=0
do a + GetValue(volume, idx * nBars, LookBack * nBars)
else
0;``````

You don't, of course, need that much whitespace... it just makes it easier for me to think in a text editor.

-mashume
Thanks for the help! I think this is going down the correct path.

See image attached. These are the values from the time based volume. At 9:48 it was 0.89. Is there a way that at 9:30 it starts at 0.00 and collects that daily running sum? Thanks again @mashume !

@xfitzz

Code:
``````def pvSum =
if SecondsFromTime(0930) > 0 then
pvSum[1] + VOLUME
else
0;``````

?

@mashume Unfortunately no. Most values range around 1. If its a spike in volume it can range up to 4 or 5 or even as high as 10.

I'll throw out the values (1 min) of Tesla here for the first 5 minutes:
9:30 - 3.92
9:31 - 2.30
9:32 - 2.00
9:33 - 2.53
9:34 - 1.61

So through the first 5 minutes our sum is 12.36. With the code above it would add actual volume, which is hundreds of thousands of shares. I'm specifically looking at the plot for the the daily sum starting a 0 each day. Hope this makes sense. Sorry for any confusion.

@mashume sorry to bother! Was curious if you saw this last comment and if this is even possible.

Last edited by a moderator:

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