Hour Volume Average

TMG

New member
Hello Everyone,
I'm trying to create 1-hour volume average out of 1 month and label it on the chart (upper declare).
Here is the script I'm trying to create it and seems like I'm doing it wrong? Need help.

upper declare

#Inputs
input ShowHOURAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input ShowCurrentBar = yes;


#Volume Data

def volLast30DayAvg = (volume(period = "HOUR")[1] + volume(period = "HOUR")[2] + volume(period = "HOUR")[3] + volume(period = "HOUR")[4] + volume(period = "HOUR")[5] + volume(period = "HOUR")[6] + volume(period = "HOUR")[7] + volume(period = "HOUR")[8] + volume(period = "HOUR")[9] + volume(period = "HOUR")[10] + volume(period = "HOUR")[11] + volume(period = "HOUR")[12] + volume(period = "HOUR")[13] + volume(period = "HOUR")[14] + volume(period = "HOUR")[15] + volume(period = "HOUR")[16] + volume(period = "HOUR")[17] + volume(period = "HOUR")[18] + volume(period = "HOUR")[19] + volume(period = "HOUR")[20] + volume(period = "HOUR")[21] + volume(period = "HOUR")[22] + volume(period = "HOUR")[23] + volume(period = "HOUR")[24] + volume(period = "HOUR")[25] + volume(period = "HOUR")[26] + volume(period = "HOUR")[27] + volume(period = "HOUR")[28] + volume(period = "HOUR")[29] + volume(period = "HOUR")[30]) / 30;
def today = volume(period = "HOUR");
def hour = volume(period = "HOUR");
def curVolume = volume;

AddLabel(ShowHOURAvg, "HOUR Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOfHOUR >= UnusualVolumePercent then Color.GREEN else if percentOfHOUR >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

Thank you
 
Solution
Well, for starters, that huge brick of code could be written as:

Code:
def volLast30DayAvg = Average(Volume(period = AggregationPeriod.HOUR),30);

Beyond that, your question / description of the problem needs to be expanded upon.
Well, for starters, that huge brick of code could be written as:

Code:
def volLast30DayAvg = Average(Volume(period = AggregationPeriod.HOUR),30);

Beyond that, your question / description of the problem needs to be expanded upon.
 
Solution
@TMG
Idea I just had and yours sounds similar:
I always find Volume can be difficult to discern with most of the day being so compressed by the opening and closing.
It would be interesting to see a Volume Average indicator that took the average for an exact time over past X days.

For example, on a 15-minute chart, the 10:30 to 10:45 bar would be related to that same bar on the past 30+/- days

Is that what you were going for? If not, what do you think of the concept?
 
Last edited by a moderator:

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