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.

Note: For GetAggregationPeriod, aggregations 1 Day and 24 hours are the same, even though they may produce different results on the charts. For example, an equality check for daily aggregation GetAggregationPeriod() >= AggregationPeriod.DAY  will return true when applied to a 24-hour aggregation chart.

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.