# Make t the aggregation period into an integer?

#### DanielManahan

##### Member
I want to get the integer, the number of candles in an aggregation period such as year.

for example if we are in the beginning of the year that number will be small and in the end of the year that number will approach 250 or the total number of stock trading days of the year.

my code would read like this

Def Period = AggregationPeriod.Year; # use the total number of days in the year for this variable. and later the defined variable Period would be used for some other parameters that require a data collection for an average such as VWAP or Simple Moving Average or Relative Strength Index.

but this won't work. I need the correct syntax to do this if this is possible.

Solution
I want to get the integer, the number of candles in an aggregation period such as year.

for example if we are in the beginning of the year that number will be small and in the end of the year that number will approach 250 or the total number of stock trading days of the year.

my code would read like this

Def Period = AggregationPeriod.Year; # use the total number of days in the year for this variable. and later the defined variable Period would be used for some other parameters that require a data collection for an average such as VWAP or Simple Moving Average or Relative Strength Index.

but this won't work. I need the correct syntax to do this if this is possible.

if you want to work with data from days, then you would use...
I want to get the integer, the number of candles in an aggregation period such as year.

for example if we are in the beginning of the year that number will be small and in the end of the year that number will approach 250 or the total number of stock trading days of the year.

my code would read like this

Def Period = AggregationPeriod.Year; # use the total number of days in the year for this variable. and later the defined variable Period would be used for some other parameters that require a data collection for an average such as VWAP or Simple Moving Average or Relative Strength Index.

but this won't work. I need the correct syntax to do this if this is possible.

if you want to work with data from days, then you would use
= AggregationPeriod.day.
if you use year, you are saying you want to group a whole years worth of data into 1 candle. there will be just 1 each of these per each year: open, close, high, low.

the following might help give you some ideas
--------------------------------

Code:
``````# for charts with a period less than a day.
# get the chart agg time and convert to minutes. then calculate how many bars are in the trading day, on the chart.
#
def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60):
# 6.5 hours in a normal trading day, 390 minutes.
def daybars = chartmin / 390;

addlabel(1, "bars / day " + daybars, color.yellow);``````

--------------------------------

Code:
``````# count the trading days in a year
def newday = getday <> getday[1]
def newyear = getyear <> getyear[1]
# if a new year, then reset the count to 1.
def daycnt = if newyear then 1 else if newday then daycnt[1] + 1 else daycnt[1];

addchartbubble(1, low, "Y " + newyear + "\nD " + daycnt, color.yellow, no);``````

--------------------------------

displays a letter to ID the agg time period. has a list of minutes for each time period , up to month.

--------------------------------

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetAggregationPeriod

87k+ Posts
351 Online

## The Market Trading Game Changer

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?