AggregationPeriodvariable returns the time frame of your choice for the script to pull data from. This is useful for implementing multi-timeframe into an existing indicator.
You can this to assign a specific aggregation period for your indicator. It works for backtesting strategies as well.
Here is a list of supported
AggregationPeriodthat you can define in your thinkScript code.
What does AggregationPeriod.DAY mean in thinkScript? This defines the aggregation period equal to the Daily timeframe.
Expanding further into an usable script:
input aggregationPeriod = AggregationPeriod.HOUR; def price = close(period = aggregationPeriod); input length = 50; input displace = 0; plot SMA = Average(price[-displace], length);
In the code above, we're using the AggregationPeriod of the HOUR (1HR) timeframe. When you add this script to your chart, it will plot the 50 SMA (simple moving average) of the Hourly chart. When you switch to another timeframe lower than the 1HR chart, the moving average line remains unchanged.
Important to note that in ThinkorSwim, you can display data from a higher timeframe onto a lower timeframe. The opposite CAN NOT be done. If you apply the code above to the Daily chart, you will not see the moving average. That is because the HOUR period is less than the Daily period.
Additional scripts related to AggregationPeriod