GetAggregationPeriod

GetAggregationPeriod ();

Description

The GetAggregationPeriod function returns the current aggregation period in milliseconds for time charts, in ticks for tick charts, and in dollars for range charts. The aggregation period returned is:

  • For time charts: the amount of milliseconds required to complete one candle
  • For tick charts: the amount of ticks required to complete one candle
  • For range charts: the price range required to complete a range bar

On time charts, you can use this function in combination with the aggregation period constants; for more information on thinkScript constants, see the Constants section.

Example

input lengthIntraday = 20;
input lengthDaily = 10;
plot data;
if GetAggregationPeriod() < AggregationPeriod.DAY {
data = Average(close, lengthIntraday);
} else {
data = Average(close, lengthDaily);
}

This example script plots a simple moving average with a length that depends on the current aggregation period. If the current aggregation period is shorter than one day, then the script plots the average with the length equal to the lengthIntraday. For aggregation periods of one day and greater, it plots the average with the length equal to lengthDaily.

You may also like
Chart Describer
Chart Describer is a thinkorswim gadget that provides you with recent technical analysis ...