 # does AggregationPeriod work for volume?

#### Cre8able

##### New member
VIP
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 type notation.

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

you cant use:
def sally = bob - bob

you have to make a:
def bob1 = average(close(period = AggregationPeriod.THREE_DAYS), 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 =...``````

#### mashume

##### Well-known member
VIP
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, 20);``````

Hope that helps,
mashume

• MerryDay