Average Volume

Im looking for a script that draws a strait line on todays chart of what the average volume is for all of the previous day 5 minute candles are, but only while the market was open, for example there is 78 5 minute candles while the market is open, I want the average of those 5 minute candles
 
Solution
Im looking for a script that draws a strait line on todays chart of what the average volume is for all of the previous day 5 minute candles are, but only while the market was open, for example there is 78 5 minute candles while the market is open, I want the average of those 5 minute candles

See if this helps

Ruby:
#Define Days
def ymd = GetYYYYMMDD();
def candles  = !IsNaN(close);
def capture  = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;

#Define Regular Trading Hours
def rth = Between(GetTime(), RegularTradingStart(GetYYYYMMDD()), RegularTradingEnd(GetYYYYMMDD()));

#Define Number of Bars based upon Chart...
Im looking for a script that draws a strait line on todays chart of what the average volume is for all of the previous day 5 minute candles are, but only while the market was open, for example there is 78 5 minute candles while the market is open, I want the average of those 5 minute candles

See if this helps

Ruby:
#Define Days
def ymd = GetYYYYMMDD();
def candles  = !IsNaN(close);
def capture  = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;

#Define Regular Trading Hours
def rth = Between(GetTime(), RegularTradingStart(GetYYYYMMDD()), RegularTradingEnd(GetYYYYMMDD()));

#Define Number of Bars based upon Chart Aggregation
def bars = 390 / (GetAggregationPeriod() / 60000);

#Define RTH volume for Prior Day to Current Day
def rthvol = if thisDay == 1 and rth then rthvol[1] + volume else rthvol[1];

#Plot Prior Day's RTH Average Volume on Today's Chart
plot prior_rth_volume = rthvol / bars;
AddLabel(1, "Prior Day Total RTH Volume: " + rthvol + " /  " + bars + " Bars  = Average Volume: " + round(prior_rth_volume,0), color.cyan);
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Im looking for a script that draws a strait line on todays chart of what the average volume is for all of the previous day 5 minute candles are, but only while the market was open, for example there is 78 5 minute candles while the market is open, I want the average of those 5 minute candles

sometimes i think i see things a little differently.
here is my version,

i took this
...a straight line on todays chart of the average volume for all of the previous day 5 minute candles...
to mean,
find an average from the previous bars of today. not previous days.

as more volume bars appear on the current day, an average of just those is calculated.

Ruby:
# vol_avg_per_day_0

declare on_volume;

def istoday = if GetLastDay() == GetDay() then 1 else 0;
def diffday = if getDay()[1] != GetDay() then 1 else 0;

def na = Double.NaN;
def bn = BarNumber();
def lastbn = HighestAll( if IsNaN(close) then 0 else bn);
def v = volume;

#Define Regular Trading Hours
def rth = Between(GetTime(), RegularTradingStart(GetYYYYMMDD()), RegularTradingEnd(GetYYYYMMDD()));

def vol_ttl = if diffday then v
  else if rth then vol_ttl[1] + v
  else 0;

def daybarcnt = if diffday then 1
  else if rth then daybarcnt[1] + 1
  else 0;

def volavg = if daybarcnt > 0 then (vol_ttl / daybarcnt) else 0;

# horz avg
def curr_avg = if diffday then GetValue( volavg , -(lastbn - bn) )
  else curr_avg[1];

# draw a horz line, of the vol avg, on current bar
plot horz_avg = if istoday and !isnan(close) then curr_avg else na;
horz_avg.setdefaultcolor(color.lime);

# draw vol avg for today
plot today_avg = if istoday and !isnan(close) then volavg else na;
today_avg.setdefaultcolor(color.magenta);
#

purple line, is average for today
lime line, horizontal line from the average on current bar
pvnc5da.jpg
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
422 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