Volume estimator, for 1 minute chart for thinkorswim

halcyonguy

Moderator - Expert
VIP
Lifetime
estimate 1 minute volume levels, based on the same time on past days.

display a purple volume bar, after the last bar, that represents a target value, for the current 1 minute volume bar.

this looks back at volume bars, of the same time, over multiple days(the quantity on the chart), and finds an average, to determine a target.

it shows the previous and the current volume bars.
set the chart to 1 minute.
this is a lower study. the volume bar chart doesn't need to be on.
the previous and current volume bars are color coded depending on the price candle.
. if an up bar then green.
. if a down bar then red.

i'm a visual guy. i don't like to squint. i like to make things that are easy to see. this is why i made a wider bar option.
2 output options, determined by this input , show_wider_vol_bars
. = no , 3 normal sized bars.
. = yes , 6 bars are used to represent each of the 3 bars. making it easier to see when zoomed out.

3 labels, quantity of days used in average, current volume, target volume.

notes:
I used a chart of 1m 5days. it is set up with constants to work on a 1 minute chart.
as the current volume bar rises, it will affect the average, which affects the target level.
it uses an offset of 390 to look back 1 day at the same time. 390 min in a day. extended hours need to be off.
if a day has missing bars from a halt or no volume, the average and target will be off.
(i started out wanting to use clouds, but ran into rec errors. so i just used histograms. ..why some vars start with cld_)

i made it from this request
https://usethinkscript.com/threads/...ustom-coding-graveyard.8162/page-2#post-75650
post 32 @BLL

Ruby:
# vol_past_curr_future_0e

#-----------------
# halcyonguy
# 22-03-03
# volume estimator
#-----------------

# notes:
# use a chart of  1m 5days.
# this looks back at vol bars of the same time, over multiple days, and finds an avg, to determine a target.
# as current vol bar rises, it will affect the future bar target level
# and depending on how many days are used in the average
# uses offset of 390. 390 min in a day. ext hours need to be off

# -------------------------------------------------------------
declare lower;

def na = double.nan;
def bn = barnumber();
def v = volume;

def lastbar = !isnan(close[0]) and isnan(close[-1]);

# time enable for previous bar and lastbar
def x = if ( lastbar[-1] or lastbar[0] ) then 1 else 0;

plot z = 0;
z.assignValueColor( color.gray);

# calc day #
def d = getday();
def newday = d[1] <> d;
def daycnt = if bn == 1 then 1 else if newday then daycnt[1] + 1 else daycnt[1];

# look at several past days , at bars at the same time, as the current bar,
# read v[390] and add it to current bar
#  and avg them, and compare to current vol
def off = 390;
def vbarsum = if daycnt == 1 then v else vbarsum[off] + v;
def vavg = floor(vbarsum/daycnt);

input show_wider_vol_bars = no;
addlabel(1, "target volume from " + daycnt + " day avg", color.yellow);
addlabel(1, "current volume " + v, color.cyan);

# prev and current
plot Vol1 = if !show_wider_vol_bars and x then volume else na;
Vol1.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Vol1.assignValueColor(if close > open then color.GREEN else if close < open then color.RED else color.LIGHT_GRAY);

# future
plot Vol2 = if !show_wider_vol_bars and lastbar[1] then vavg[1] else na;
Vol2.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Vol2.assignValueColor( color.magenta);

def predictedv = if lastbar[0] then vavg[0] else predictedv[1];
addlabel(1, "predicted vol " +  predictedv , color.magenta);

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

# ---- wider bars ---------------------------
# prev ------------------------------------------

# the group of 6 bars starts 13 bars before last bar, [-13]
def cld_p = if ( lastbar[-13] or lastbar[-12] or lastbar[-11] or lastbar[-10] or lastbar[-9] or lastbar[-8] ) then 1 else 0;

def cld_p_top = if lastbar[-13] then v[-12] else if cld_p then cld_p_top[1] else na;

def cld_p_dir = if lastbar[-13] and close[-12] > open[-12] then 1
 else if lastbar[-13] and close[-12] < open[-12] then -1 
 else if lastbar[-13] then 0 
 else na;

def cld_p_dir2 = if cld_p == 0 then na
else if lastbar[-13] then cld_p_dir
else cld_p_dir2[1];

plot Vol_p = if show_wider_vol_bars and cld_p then cld_p_top else na;
Vol_p.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Vol_p.assignValueColor(if cld_p_dir2 == 1 then color.GREEN else if cld_p_dir2 == -1 then color.RED else color.LIGHT_GRAY);

# current ----------------------------------------

# the group of 6 bars starts 5 bars before last bar, [-5]
# the right bar of the 6 bars, aligns with the lastbar
def cld_c = if ( lastbar[0] or lastbar[-1] or lastbar[-2] or lastbar[-3] or lastbar[-4] or lastbar[-5] ) then 1 else 0;

input testc1 = no;
addchartbubble(testc1 and cld_c, 0, "-", color.cyan, no);

def cld_c_top = if lastbar[-5] then v[-5] else if cld_c then cld_c_top[1] else na;

def cld_c_dir = if lastbar[-5] and close[-5] > open[-5] then 1
 else if lastbar[-5] and close[-5] < open[-5] then -1 
 else if lastbar[-5] then 0 
 else na;

def cld_c_dir2 = if cld_c == 0 then na
else if lastbar[-5] then cld_c_dir
else cld_c_dir2[1];

plot Vol_c = if show_wider_vol_bars and cld_c then cld_c_top else na;
Vol_c.setPaintingStrategy(paintingStrategy.HISTOGRAM);
#Vol_c.assignValueColor(if cld_c_dir == 1 then color.GREEN else if cld_c_dir == -1 then color.RED else color.LIGHT_GRAY);
Vol_c.assignValueColor(if cld_c_dir2 == 1 then color.GREEN else if cld_c_dir2 == -1 then color.RED else color.LIGHT_GRAY);

# future------------------------------------------

# the group of 6 bars starts 3 bars after last bar, [3]
def cld_f = if ( lastbar[3] or lastbar[4] or lastbar[5] or lastbar[6] or lastbar[7] or lastbar[8] ) then 1 else 0;

def cld_f_top = if lastbar[3] then vavg[3] else if cld_f then cld_f_top[1] else na;

plot Vol_f = if show_wider_vol_bars and cld_f then cld_f_top else na;
Vol_f.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Vol_f.assignValueColor( color.magenta);
#


normal bars
6ndC1Wz.jpg


show_wider_vol_bar = yes
uses 6 bars to represent each bar. easier to see when zoomed out
RcTVV81.jpg
 

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