Can a study be made to calculate volume within a certain time bracket?

YungTraderFromMontana

Well-known member
I'm always looking for ways to make my strategy more reliable and I have been interested in volume. Usually because of times when their is often liquidity a majority of the volume is traded within the first 3 and last 3 minutes of trading, I want to see if their is a correlation between volume traded outside of these liquidity points and continuation gap ups.

To do this I'd need a study that excludes volume traded within the first 3 minutes and last 3 minutes of trading, hopefully someone can help.
 
See if this helps, @YungTraderFromMontana

Code:
# Volumed - Aggregates time segmented volume blocks
# Farmin
# 7.16.2018

# Kickstart: DMonkey, UpTheCreek
# We discussed that daily volume vs summed volume aren't the same for equities

#hint:<b>Volumed</b>\nShows aggregated volume by market time segment - premarket, RTH and afterhours.  Use on a 30m chart or less.  All times are Eastern. N.B. Counts reset at midnight.
 
#Declarations
declare lower;
declare hide_on_daily;

#inputs
input Begin_precount_at = 0400;
input Stop_precount_before = 0930;
input Begin_mktcount_at = 0930;
input Stop_mktcount_before = 1600;
input Begin_aftrcount_at = 1600;
input Stop_aftrcount_before = 2000;

input show_labels = yes;
input debug = no;

#calcs
def v = if IsNaN(volume) then 0 else volume;
def na = Double.NaN;

def Count_Pre = SecondsFromTime(Begin_precount_at) >= 0
              && SecondsTillTime(Stop_precount_before) > 0;
def Count_Mkt = SecondsFromTime(Begin_mktcount_at) >= 0
              && SecondsTillTime(Stop_mktcount_before) > 0;
def Count_Aftr = SecondsFromTime(Begin_aftrcount_at) >= 0
              && SecondsTillTime(Stop_aftrcount_before) > 0;

def save_prior = GetDay() != GetDay()[1] ;

def Start_Counting_Pre = Count_Pre && !Count_Pre[1];

def Cum_Vol_Pre =
              if save_prior && !Start_Counting_Pre
              then 0
              else if Start_Counting_Pre
                   then v
                   else if Count_Pre
                        then Cum_Vol_Pre[1] + v
                        else Cum_Vol_Pre[1];

def prior_pre = if save_prior then cum_Vol_pre[1] else prior_pre[1];

def Start_Counting_Mkt = Count_Mkt && !Count_Mkt[1];

def Cum_Vol_Mkt =
              if save_prior && !Start_Counting_Mkt
              then 0
              else if Start_Counting_Mkt
                   then v
                   else if Count_Mkt
                        then Cum_Vol_Mkt[1] + v
                        else Cum_Vol_Mkt[1];

def prior_mkt = if save_prior then cum_Vol_Mkt[1] else prior_mkt[1];

def Start_Counting_Aftr = Count_Aftr && !Count_Aftr[1];

def Cum_Vol_Aftr =
              if save_prior && !Start_Counting_Aftr
              then 0
              else if Start_Counting_Aftr
                   then v
                   else if Count_Aftr
                        then Cum_Vol_Aftr[1] + v
                        else Cum_Vol_Aftr[1];

def prior_aftr = if save_prior then cum_Vol_aftr[1] else prior_aftr[1];

#Plots
plot Cumulative_PreSession_Volume = if Count_Pre
                                 then Cum_Vol_Pre
                                 else na;
Cumulative_PreSession_Volume.setDefaultColor(color.DARK_ORANGE);
Cumulative_PreSession_Volume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot Cumulative_MktSession_Volume = if Count_Mkt
                                 then Cum_Vol_Mkt
                                 else na;
Cumulative_MktSession_Volume.setDefaultColor(Color.YELLOW);
Cumulative_MktSession_Volume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot Cumulative_AftrSession_Volume = if Count_Aftr
                                 then Cum_Vol_Aftr
                                 else na;
Cumulative_AftrSession_Volume.setDefaultColor(Color.MAGENTA);
Cumulative_AftrSession_Volume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);


AddChartBubble(SecondsTillTime(Stop_precount_before) == 0, Cum_Vol_Pre, Cum_Vol_Pre, Color.DARK_ORANGE, 1);

AddChartBubble(SecondsTillTime(Stop_mktcount_before) == 0, Cum_Vol_Mkt, Cum_Vol_Mkt, Color.YELLOW, 0);

AddChartBubble(GetDay() != GetDay()[-1], Cum_Vol_Aftr, Cum_Vol_Aftr, Color.MAGENTA, 1);

addlabel(show_labels, "PreVol: " + cum_Vol_Pre + " MktVol: " + cum_Vol_Mkt + " AfterVol: " + cum_Vol_Aftr + " = " + (cum_Vol_Pre + cum_Vol_Mkt + cum_Vol_Aftr) + " | Reported by Daily agg: " + volume(period = AggregationPeriod.Day), Color.LIGHT_GRAY );

addlabel(show_labels, "PreVol: " + prior_Pre + " MktVol: " + prior_Mkt + " AfterVol: " + prior_Aftr + " = " + (prior_Pre + prior_Mkt + prior_Aftr) + " | Reported by Daily agg: " + volume(period = AggregationPeriod.Day)[1], Color.GRAY );

###   End Code   ###
 

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