does AggregationPeriod work for volume?

Cre8able

New member
I'm trying to create an indicator that can use higher timeframes for some of my indicators. Everything works except a volume related indicator. I know you can use open, close, high, low so it seems to me that I should be able to use volume since that is the other key value for a bar. But it didn't seem to give me the results I was expecting. Anyone know if it's possible and I just missed something?

I did discover an unfortunate thing about AggregationPeriod. You cant bury it inside a function then use the function to reference historical data using open[1] type notation.

if you have a function:
def bob = average(close(period = AggregationPeriod.THREE_DAYS), 20)

you cant use:
def sally = bob - bob[1]

you have to make a:
def bob1 = average(close(period = AggregationPeriod.THREE_DAYS)[1], 20)

then sally = bob - bob1

kinda a pain, but that's how thinkscript thinks you should do it

Solution
This works for me:
Code:
declare lower;

def Data = GetValue(data = volume(period = AggregationPeriod.DAY), "dynamic offset" = 0);

plot vol = data;

Generally speaking, it is best to make calls and define variables as containers once and then use the container, rather than using the call to close() or whatever inside another function.

In your code, you have this:
Code:
def bob = average(close(period = AggregationPeriod.THREE_DAYS), 20)
when the cleaner way is to do this:
Code:
def c = close(period = AggregationPeriod.THREE_DAYS);
def bob = average(c, 20)
this also allows you not to make two calls to the agg period when you define bob1:
Code:
def c = close(period = AggregationPeriod.THREE_DAYS);
def bob = average(c, 20);
def bob1 =...
This works for me:
Code:
declare lower;

def Data = GetValue(data = volume(period = AggregationPeriod.DAY), "dynamic offset" = 0);

plot vol = data;

Generally speaking, it is best to make calls and define variables as containers once and then use the container, rather than using the call to close() or whatever inside another function.

In your code, you have this:
Code:
def bob = average(close(period = AggregationPeriod.THREE_DAYS), 20)
when the cleaner way is to do this:
Code:
def c = close(period = AggregationPeriod.THREE_DAYS);
def bob = average(c, 20)
this also allows you not to make two calls to the agg period when you define bob1:
Code:
def c = close(period = AggregationPeriod.THREE_DAYS);
def bob = average(c, 20);
def bob1 = average(c[1], 20);

Hope that helps,
mashume

Not the exact question you're looking for?

87k+ Posts
126 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?