Current Day volume

BasicBobby

New member
Can someone help me create a label that starts counting volume from open(excludes Premarket), and the label turns yellow when current volume is past 50% of premarket volume, and turns green when its past 100% of premarket volume.
 
Can someone help me create a label that starts counting volume from open(excludes Premarket), and the label turns yellow when current volume is past 50% of premarket volume, and turns green when its past 100% of premarket volume.


compare accumulated volume of the day to after hours volume.

once i got going on this, i decided to add a couple things.

draw a horizontal line on each day, colored based on the ratio, vol/AH vol

i wasn't sure which after hours time you wanted, so the user can pick the range.
can choose which after hours volume data to compare to,
. pre time - midnight to 9:30am
. post time - 4pm to midnight
. pre+post , both added together

labels,
. show which AH type is picked
. percent levels color legend
. current bar percent and color

percent levels
0 to 50 , gray
50 to 100 , yellow
100 to 500 , green
500 to 1000 , cyan
. > 1000 , magenta


Ruby:
# compare_pre_vol_01

# compare accumulated volume of the day to after hours volume.
# https://usethinkscript.com/threads/current-day-volume.10512/

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

def v = volume;
def cls = close;

def diffday = if getday() != getday()[1] then 1 else 0;

input ah_volume_type = { "Pre Vol", "Post Vol", default "Pre + Post Vol" };

def start = 0930;
def end = 1600;
def daystart = if SecondsFromTime(start) == 0 then 1 else 0;
def daytime = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def start2 = 0;
# pre time - midnight to 9:30am
def pretime = if SecondsFromTime(start2) >= 0 and SecondsTillTime(start) > 0 then 1 else 0;

def end2 = 2359;
# post time - 4pm to midnight
def poststart = if SecondsFromTime(end) == 0 then 1 else 0;
def posttime = if SecondsFromTime(end) >= 0 and SecondsTillTime(end2) > 0 then 1 else 0;

def midnite = if SecondsFromTime(end2) == 0 then 1 else 0;


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

# calc mid level for chart
#  this makes study complex
#def big = 999999;
#def highest = HighestAll(if daytime then high else 0);
#def lowest = LowestAll(if daytime then low else big);
#def rng = highest - lowest;
#def mid = lowest + (rng / 2);



# calc mid level for each day, for colored line
def agg = aggregationPeriod.day;
def highest = high(period = agg);
def lowest = low(period = agg);
def rng = highest - lowest;
def mid = lowest + (rng / 2);
#def open1 = open(period = agg);
#def close1 = close(period = agg);

#def cls_rng_per = 100*((cls-lowest)/rng);

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

#4pm to midnight
def volpost =
 if bn == 1 then 0
 else if poststart then v
 else if posttime then volpost[1] + v
 else volpost[1];

#midnight to 9.30
def volpre =
 if bn == 1 then 0
 else if diffday then v
 else if pretime then volpre[1] + v
 else volpre[1];

#9.30 to 4pm
def vol =
 if bn == 1 then 0
 else if daystart then v
 else if daytime then vol[1] + v
 else vol[1];

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

# input prevolume = { default "Pre Vol", "Post Vol", "Pre + Post Vol" };

#def prevol2;
def vol_ah;
def vtype;
switch ( ah_volume_type) {
case "Pre Vol":
  vol_ah = volpre;
  vtype = 1;
case "Post Vol":
  vol_ah = volpost;
  vtype = 2;
case "Pre + Post Vol":
  vol_ah = volpre + volpost;
  vtype = 3;
}

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

input show_AH_volume_type_label = yes;
addlabel(show_AH_volume_type_label, "    " , color.black);
addlabel(show_AH_volume_type_label, "Pre Vol data:  " +
( if vtype == 1 then "Pre, midnight to 9:30am"
else if vtype == 2 then "Post, 4pm to midnight"
else if vtype == 3 then "Pre + Post, all after hours"
else "-")
, color.yellow);


#daytime vol % of pre vol
def dayvolper =  round(100 * (vol / vol_ah),1);

# percent levels, for colors
def per1 = 50;
def per2 = 100;
def per3 = 500;
def per4 = 1000;


DefineGlobalColor("color01", color.gray);
DefineGlobalColor("color02", color.yellow);
DefineGlobalColor("color03", color.green);
DefineGlobalColor("color04", color.cyan);
DefineGlobalColor("color05", color.magenta);


input show_percent_level_legend_labels = yes;
addlabel(show_percent_level_legend_labels, "    " , color.black);
addlabel(show_percent_level_legend_labels, "Percent levels" , color.orange);
addlabel(show_percent_level_legend_labels, " 0 " , globalColor("color01"));
addlabel(show_percent_level_legend_labels, ">" + per1 + " %" , globalColor("color02"));
addlabel(show_percent_level_legend_labels, ">" + per2 + " %" , globalColor("color03"));
addlabel(show_percent_level_legend_labels, ">" + per3 + " %" , globalColor("color04"));
addlabel(show_percent_level_legend_labels, ">" + per4 + " %" , globalColor("color05"));


input show_current_vol_ratio_label = yes;
addlabel(show_current_vol_ratio_label, "    " , color.black);
AddLabel(show_current_vol_ratio_label, dayvolper + " %"
, ( if dayvolper < per1 then globalColor("color01")
else if dayvolper >= per1 and dayvolper < per2 then globalColor("color02")
else if dayvolper >= per2 and dayvolper < per3 then globalColor("color03")
else if dayvolper >= per3 and dayvolper < per4 then globalColor("color04")
else globalColor("color05")));


# color line , diff colors for each % rng
input volume_ratio_colored_line = yes;
plot cc = if volume_ratio_colored_line and daytime then mid else na;
cc.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
cc.AssignValueColor(
( if dayvolper < per1 then globalColor("color01")
else if dayvolper >= per1 and dayvolper < per2 then globalColor("color02")
else if dayvolper >= per2 and dayvolper < per3 then globalColor("color03")
else if dayvolper >= per3 and dayvolper < per4 then globalColor("color04")
else globalColor("color05")));
cc.setlineweight(2);
cc.hidebubble();


# -----------------------------------------------------
# -----------------------------------------------------
# test data

input test_data = 0;


# -----------------------------
# identify the 3 time periods  pre, daytime, post
# if pre+post - then change, make them same color . in 2nd row. 1st row, dont draw

def y4 = 0.003;
input test1_bubble_rows_of_vol_per_period = no;
# post vol
addchartbubble( test1_bubble_rows_of_vol_per_period and vtype == 2, (mid * ( 1 - y4)),
volpost + " post" , (if posttime then Color.dark_ORANGE else color.gray), no);

# pre vol
addchartbubble( test1_bubble_rows_of_vol_per_period and vtype == 1, (mid * ( 1 - y4)),
volpre + " pre", (if pretime then Color.plum else Color.gray), no);

# pre+post vol
addchartbubble( test1_bubble_rows_of_vol_per_period and vtype == 3, (mid * ( 1 - y4)),
(volpre + volpost) + " pre", (if posttime then Color.dark_ORANGE else if pretime then Color.plum else Color.gray), no);

addchartbubble( test1_bubble_rows_of_vol_per_period and daytime, (mid * ( 1 - y4)),
vol + " v", (if daytime then Color.dark_green else Color.gray), no);

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


# def dayvolper =  round(100 * (vol - vol_ah)/vol_ah,1);
input test2_vol_and_ratio_bubbles = no;
addchartbubble(test2_vol_and_ratio_bubbles and daytime, (mid * ( 1 + y4)),
 vol_ah + "\n" +
 vol + "\n" +
 dayvolper
,( if dayvolper < per1 then globalColor("color01")
else if dayvolper >= per1 and dayvolper < per2 then globalColor("color02")
else if dayvolper >= per2 and dayvolper < per3 then globalColor("color03")
else if dayvolper >= per3 and dayvolper < per4 then globalColor("color04")
else globalColor("color05")), yes);


#input test5_highest_lowest_labels = no;
#addlabel(test5_highest_lowest_labels, "    ", color.black);
#addlabel(test5_highest_lowest_labels, "Hi " + highest, color.yellow);
#addlabel(test5_highest_lowest_labels, "Lo " + lowest, color.yellow);
#addlabel(test5_highest_lowest_labels, "rng " + rng, color.yellow);
#addlabel(test5_highest_lowest_labels, "mid " + mid, color.yellow);


# color line , diff colors for each time , pre, day, post
#input test3_period_color_line = no;
#plot uu = if test3_period_color_line then mid+3 else na;
#uu.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
#uu.AssignValueColor( if daytime then Color.GREEN else if pretime then Color.MAGENTA else Color.ORANGE);
#uu.setlineweight(2);
#


chart notes
GsS3dLT.jpg


settings
FnxhwXB.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
267 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