• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

Daily Sum of Volume Question

xfitzz

New member
VIP
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?
 

rad14733

Well-known member
VIP
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
#Created 2020-09-09 by rad14733
#
input showTodaysVolumeLabel = yes;
def todaysVolume = volume(period = "DAY");
AddLabel(showTodaysVolumeLabel, "Todays Volume: " + todaysVolume, Color.WHITE);
 

xfitzz

New member
VIP
@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:

mashume

Well-known member
VIP
@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
 

xfitzz

New member
VIP
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.

qMwKlCU.png


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

New member
VIP
@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:

Similar threads

Top