Cumulative Volume Chart, Watchlists, Scan, Label for ThinkorSwim

first, let me say good job on trying to do it and tackling the use of a fold. Fold loops are tricky and can take a while to get figured out, but it looks like you've got the basic set up pretty close.

1. There are 6.5 hours in a trading day, or 390 minutes.
So there will be 78 , 5 minute bars. At the closing bell that bar is not counted. that is an after hours.

2. Most of the time looking back X number of bars will work. but occasionally on some stocks there is a time period with no trades, so there won't be the usual quantity of bars per the day, and that will throw off studies like this.

3. In your fold loop the start number is bigger than the end number, so it won't even run through one iteration..
In a fold, think of it as running through a series of offset numbers. so maybe start at 0 or 1 to some bigger number.

4. When working in fold loops try to use getvalue to read data instead of the normal offset.
Instead of this,
do v + volume[index];
use this,
do v + getvalue(volume, index);

------------------------------

This version will have issues with missing bars during the day, ( no volume or halts), but should get you some numbers.
add up volume during the day, for each day.

i added code to calculate how many bars in a day, so it will work on any time, less than a day.
the chart doesn't have to be 5 minutes.

it looks back x bars and reads a volume total from yesterday.

Ruby:
# prev_day_vol_0

# [URL]https://usethinkscript.com/threads/getting-yesterdays-cumulative-volume-at-todays-time.10673/[/URL]
# Getting Yesterdays cumulative volume at today's time

# for charts with a period less than a day.
# get the chart agg time and convert to minutes. then calculate how many bars are in the trading day, on the chart.
def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60);
# 6.5 hours in a normal trading day, 390 minutes.
def daybars = 390/chartmin;

addlabel(1, "bar min " + chartmin, color.yellow);
addlabel(1, "bars / day " + daybars, color.yellow);

# 78 for 5min bars
# def daybars = 78;

def isstart = If secondsfromtime(930) == 0 then 1 else 0;
def dayvol = If isstart then volume else if secondsfromtime(930) > 0 and secondstilltime(1600) > 0 then dayvol[1] + volume else dayvol[1];
#def prevdayvol = dayvol[daybars];
def prevdayvol = getvalue(dayvol, daybars);

addlabel(1, "yesterdays volume " + prevdayvol, color.yellow);
addlabel(1, "todays volume " + dayvol, color.yellow);
addlabel(1, "day to day vol factor " + round(dayvol/prevdayvol,2), color.yellow);

input test1_vol_bubbles = no;
addchartbubble(test1_vol_bubbles, volume,
prevdayvol + " prev\n" +
dayvol + " curr"
, (if isstart then color.yellow else color.gray), yes);
#

with test bubbles turned on , on a 30min chart
shows previous day accrued volume over current day accrued volume
3w1Xb9g.jpg


getvalue has a 3rd parameter that should be used, max offset, to prevent bad code from causing endless loops.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetValue
so this is ploting current candle vs 24hrs ago ?
 
Wow that’s a nice script.
how would you set up a 30 min to see the bubbles?
im not getting anything
do we have to change "def daybars = 390/chartmin; " to 13 for 30min?
 
Wow that’s a nice script.
how would you set up a 30 min to see the bubbles?
im not getting anything
do we have to change "def daybars = 390/chartmin; " to 13 for 30min?
Beinga ble to see the bubbles on your volume chart is an input in the code that defaults to off, so change the value and they will show up.
 
Would like to be able to compare for any ticker the daily volume to the volume in the last one minute.

I can’t figure out how to get this done, gather cumulative daily volume and then compare it the latest minute, and if it’s above a certain ratio ultimately I’d want to Trigger an alert then play with some other ideas.

Thanks! Very appreciated
 
@farawayz ,
it can be done like this:
Code:
declare lower;
def startTime = 930;
def cv = if secondsFromTime(startTime) > 0 then cv[1] + VOLUME else 0;
plot v_to_cv_ratio = VOLUME / cv;
However, I doubt it will be of much use as the ratio will start at 1 (when the latest candle is the whole of the day's volume so far) and approach 0 as the day progresses in a fairly predictable fashion.

It might be useful to plot the difference between the expected decay curve and the actual curve like this:
Code:
declare lower;
def startTime = 930;
def cv = if secondsFromTime(startTime) > 0 then cv[1] + VOLUME else 0;
def v_to_cv_ratio = VOLUME / cv;
def bars_since_open = if secondsFromTime(startTime) > 0 then bars_since_open[1] + 1 else 0;
def expected_curve = log((1 / bars_since_open) + 1);
plot difference_from_expected_decay = v_to_cv_ratio - expected_curve;
plot zero = 0;

This will focus on where there is greater volume as a portion of the day's cumulative volume in the most recent candle than expected.

In any case, it is an interesting idea. Please do write back with your observations and whether and how you find the approach interesting in your trading.

Cheers, and happy trading,
-mashume
 
first i wanna start from a user-defined high or low, then count cumulative volume including this bar until it reached 25 units(one units equals 100,000k shares), i wanna plot a arrow on that bar which reached 25 units volume, the 25th bar volume is included

is there a way to do this?
 
In terms of the basics...

Counting volume is fairly strait forward.

Def Vol = Vol[1] + Volume;

So is detecting the arrow.

Def Cross = Crosses(Vol, 25 * 100000, CrossingDirection.ABOVE);

You could also make it easy to edit the unit / size.

Input Units = 25;
Input UnitSize = 100000;
Def Cross = Crosses(Vol, Units * UnitSize, CrossingDirection.ABOVE);

Although, I am not sure what you mean by user-defined high or low.

I would need more detail to actually write a functional version.
 
In terms of the basics...

Counting volume is fairly strait forward.

Def Vol = Vol[1] + Volume;

So is detecting the arrow.

Def Cross = Crosses(Vol, 25 * 100000, CrossingDirection.ABOVE);

You could also make it easy to edit the unit / size.

Input Units = 25;
Input UnitSize = 100000;
Def Cross = Crosses(Vol, Units * UnitSize, CrossingDirection.ABOVE);

Although, I am not sure what you mean by user-defined high or low.

I would need more detail to actually write a functional version.
by user-defined low i mean mannually chose a low to start the calculation. I have assembled one version based on your work

input anchorDate = 20200422;
input anchorTime = 0930;
input Units = 25;
input UnitSize = 100000;

def tradeStartEST = 0930;
def tradeEndEST = 1600;
def inPeriod = if SecondsTillTime(tradeStartEST) <= 0 and SecondsTillTime(tradeEndEST) > 0 then 1 else 0;

def revisedDate = if SecondsTillTime(anchorTime) <= 0 and !inPeriod then anchorDate + 1 else if SecondsTillTime(anchorTime) <= 0 and inPeriod then anchorDate else anchorDate;

def postAnchorDate = if GetYYYYMMDD() >= revisedDate then 1 else 0;
def postAnchorTime = if SecondsTillTime(anchorTime) <= 0 then 1 else 0;

def Vol = Vol[1] + volume;

plot Cross = if postAnchorDate and postAnchorTime then Crosses(Vol, Units * UnitSize, CrossingDirection.ABOVE) else double.nan;

But this doens't plot, may i know where did i make it wrong?
 
@MLlalala
RqIRIT5.png

Ruby:
input anchorDate = 20200422;
input anchorTime = 0930;
input Units = 25;
input UnitSize = 100000;

def tradeStartEST = 0930;
def tradeEndEST = 1600;
def inPeriod = if SecondsFromTime(tradeStartEST) >= 0 and SecondsTillTime(tradeEndEST) >= 0 then 1 else 0;

#These are doing nothing, not sure what they are supposed to do.
#def revisedDate = if SecondsTillTime(anchorTime) <= 0 and !inPeriod then anchorDate + 1 else if SecondsTillTime(anchorTime) <= 0 and inPeriod then anchorDate else anchorDate;
#def postAnchorDate = if GetYYYYMMDD() >= revisedDate then 1 else 0;
#def postAnchorTime = if SecondsTillTime(anchorTime) <= 0 then 1 else 0;

def Vol = if !SecondsFromTime(tradeStartEST) then volume else Vol[1] + volume;
#Chart bubbles to visualize.
#addchartbubble(yes,high,vol,if vol < Units * UnitSize then color.white else color.gray,yes);
#addchartbubble(yes,high,Units * UnitSize,color.white,yes);

plot Cross = if inPeriod and Crosses(Vol, Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);
 
@MLlalala
RqIRIT5.png

Ruby:
input anchorDate = 20200422;
input anchorTime = 0930;
input Units = 25;
input UnitSize = 100000;

def tradeStartEST = 0930;
def tradeEndEST = 1600;
def inPeriod = if SecondsFromTime(tradeStartEST) >= 0 and SecondsTillTime(tradeEndEST) >= 0 then 1 else 0;

#These are doing nothing, not sure what they are supposed to do.
#def revisedDate = if SecondsTillTime(anchorTime) <= 0 and !inPeriod then anchorDate + 1 else if SecondsTillTime(anchorTime) <= 0 and inPeriod then anchorDate else anchorDate;
#def postAnchorDate = if GetYYYYMMDD() >= revisedDate then 1 else 0;
#def postAnchorTime = if SecondsTillTime(anchorTime) <= 0 then 1 else 0;

def Vol = if !SecondsFromTime(tradeStartEST) then volume else Vol[1] + volume;
#Chart bubbles to visualize.
#addchartbubble(yes,high,vol,if vol < Units * UnitSize then color.white else color.gray,yes);
#addchartbubble(yes,high,Units * UnitSize,color.white,yes);

plot Cross = if inPeriod and Crosses(Vol, Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);
Thank you, i have modified a little to make it more flexible based on your work:

input anchorDate = 20200422;
input anchorTime = 0930;
input Units = 25;
input UnitSize = 100000;
input n=5;

def tradeStartEST = 0930;
def tradeEndEST = 1600;
def inPeriod = if SecondsFromTime(tradeStartEST) >= 0 and SecondsTillTime(tradeEndEST) >= 0 then 1 else 0;

#These are doing nothing, not sure what they are supposed to do.
#def revisedDate = if SecondsTillTime(anchorTime) <= 0 and !inPeriod then anchorDate + 1 else if SecondsTillTime(anchorTime) <= 0 and inPeriod then anchorDate else anchorDate;
#def postAnchorDate = if GetYYYYMMDD() >= revisedDate then 1 else 0;
#def postAnchorTime = if SecondsTillTime(anchorTime) <= 0 then 1 else 0;

def Vol = if !SecondsFromTime(tradeStartEST) then volume else Vol[1] + volume;
#Chart bubbles to visualize.
#addchartbubble(yes,high,vol,if vol < Units * UnitSize then color.white else color.gray,yes);
#addchartbubble(yes,high,Units * UnitSize,color.white,yes);

plot Cross = if inPeriod and n>=1 and Crosses(Vol, Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);
plot Cross1 = if inPeriod and n>=2 and Crosses(Vol, 2*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);
plot Cross2 = if inPeriod and n>=3 and Crosses(Vol, 3*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);
plot Cross3 = if inPeriod and n>=4 and Crosses(Vol, 4*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);
plot Cross4 = if inPeriod and n>=5 and Crosses(Vol, 5*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);


This seems to work on intraday chart, however, when plotted on daily chart, it has problems. Let's say i plot it on QQQ, the anchor day is 11/22/2021, the arrows will show before this date which should NOT be allowed, the script is desgined to show ONLY the equivolume cycles after the anchor date. I have no idea why this happens
 
@MLlalala
To not plot before anchorDate,
Change:
Ruby:
def inPeriod = if SecondsFromTime(tradeStartEST) >= 0 and SecondsTillTime(tradeEndEST) >= 0 then 1 else 0;
to:
Ruby:
def inPeriod = if GetYYYYMMDD() >= anchorDate and SecondsFromTime(tradeStartEST) >= 0 and SecondsTillTime(tradeEndEST) >= 0 then 1 else 0;

Also, when do you want the cumulative volume count to start?
 
@MLlalala
To not plot before anchorDate,
Change:
Ruby:
def inPeriod = if SecondsFromTime(tradeStartEST) >= 0 and SecondsTillTime(tradeEndEST) >= 0 then 1 else 0;
to:
Ruby:
def inPeriod = if GetYYYYMMDD() >= anchorDate and SecondsFromTime(tradeStartEST) >= 0 and SecondsTillTime(tradeEndEST) >= 0 then 1 else 0;

Also, when do you want the cumulative volume count to start?
I want the count to start from the anchor date(for daily chart) or anchor time( for intraday), including the anchor date/time volume
 
I want the count to start from the anchor date(for daily chart) or anchor time( for intraday), including the anchor date/time volume
Change:
Ruby:
def Vol = if !SecondsFromTime(tradeStartEST) then volume else Vol[1] + volume;
to:
Ruby:
def Vol = if GetAggregationPeriod() < AggregationPeriod.DAY and GetYYYYMMDD() >= anchorDate and !SecondsFromTime(tradeStartEST) then volume else if GetAggregationPeriod() == AggregationPeriod.DAY and GetYYYYMMDD() == anchorDate then volume else Vol[1] + volume;

Also, you didn't assign painting strategies to your additional plots correctly, try:
Ruby:
plot Cross = if inPeriod and n>=1 and Crosses(Vol, Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross.setpaintingStrategy(paintingStrategy.ARROW_UP);
cross.assignValueColor(color.green);
plot Cross1 = if inPeriod and n>=2 and Crosses(Vol, 2*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross1.setpaintingStrategy(paintingStrategy.ARROW_UP);
cross1.assignValueColor(color.blue);
plot Cross2 = if inPeriod and n>=3 and Crosses(Vol, 3*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross2.setpaintingStrategy(paintingStrategy.ARROW_UP);
cross2.assignValueColor(color.violet);
plot Cross3 = if inPeriod and n>=4 and Crosses(Vol, 4*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross3.setpaintingStrategy(paintingStrategy.ARROW_UP);
cross3.assignValueColor(color.lime);
plot Cross4 = if inPeriod and n>=5 and Crosses(Vol, 5*Units * UnitSize, CrossingDirection.ABOVE) then low else Double.NAN;
cross4.setpaintingStrategy(paintingStrategy.ARROW_UP);
cross4.assignValueColor(color.orange);
 

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