• Get $40 off VIP by signing up for a free account! Sign Up

Automating Aggregation Selection for ThinkorSwim


Active member
Hey sometimes we get sick of adjusting the default chart aggregations and the lengths of the bars that we want a period to count as...
So I give you guys this Chart Label!

It only shows rounding up to the next largest time aggregation in a label but in just a few minutes you can make it switch the selected aggregation automatically for you :D Thank You All @Pelonsax

declare upper;
def ChartTime = (GetAggregationPeriod()/60000);
def NAN= Double.NAN;
addLabel(1, ChartTime + "Minutes");

def AggregationTableValue = if ChartTime>0 && ChartTime<=1 then 1 else if ChartTime>=1 && ChartTime<2 then 2 else if ChartTime>=2 && ChartTime<3 then 3 else if chartTime>= 4 && ChartTime<5 then 5 else if chartTime>= 5 && ChartTime<10 then 10 else if ChartTime>=10 && ChartTime<15 then 15 else if ChartTime>=15 && ChartTime<20 then 20 else if ChartTime>=20 && ChartTime<30 then 30 else if ChartTime>=30 && ChartTime<60 then 60 else if ChartTime>=60 && ChartTime<120 then 120 else if ChartTime>=120 && ChartTime<240 then 240 else if ChartTime>=240 && ChartTime<1440 then 1440 else if ChartTime>=1440 && ChartTime<2880 then 2880 else if ChartTime>=2880 && ChartTime<4320 then 4320 else if ChartTime>=4320 && ChartTime<5760 then 5760 else if ChartTime>=5760 && ChartTime< 10080 then 10080 else if ChartTime>= 10080 then 43200 else NAN ;
addLabel(1, AggregationTableValue + "MinimumMinutes");

#### Now all you have to do is use the minute value from AggregationTableValue to change what you assign for a multiTime Aggregation or what you might choose to assign for a period length like

#MACDshortlenght= {default 12, }...
#switch(ShorterLength) {
#Case 12:
#period =12;     This is an exaggeration and you probably don't want this as your MACD but you can plug in any lengths you like here...
Last edited by a moderator:

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

Thread starter Similar threads Forum Replies Date
horserider Fibonacci Pivots with mid-pivots and Time Frame selection Custom 0

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
209 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.