Make t the aggregation period into an integer?

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);

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

https://usethinkscript.com/threads/...icator-for-thinkorswim.1129/page-4#post-69106
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
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
425 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top