# Automating Aggregation Selection for ThinkorSwim

#### MatthewA

##### 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 Thank You All @Pelonsax

Code:
``````declare upper;
def ChartTime = (GetAggregationPeriod()/60000);
def NAN= Double.NAN;

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 ;

#### 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:
Awesome snippet

Awesome snippet
Well thank you very Much!
If anyone has an indicator they are tired of switching please show me and I will apply it to that if you like @Pelonsax

Well thank you very Much!
If anyone has an indicator they are tired of switching please show me and I will apply it to that if you like @Pelonsax
You're the man!!!

Fibonacci Pivots with mid-pivots and Time Frame selection Custom 0

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