On this page
Overview
In this tutorial I show you how to use an aggregation period in thinkScript to plot a daily time frame indicator on an intraday ThinkOrSwim chart. The example is the 50-day simple moving average on a 5-minute chart of Coca-Cola (KO), so you can watch price react to a daily level without flipping between charts.
The whole change is one parameter added to the closing price. It's a short, beginner-friendly lesson for day traders who already mark daily levels and want them on the chart they trade from. The same idea is behind our multi-time frame indicators.
Key Takeaways
- An aggregation period in thinkScript sets which time frame's candles a price or volume value comes from, such as 5 minutes, 1 hour, 1 day or 1 week.
- Adding
period = AggregationPeriod.DAYtocloseturns a 50-period SMA into the daily 50 SMA on any intraday chart:SimpleMovingAvg(close(period = AggregationPeriod.DAY), 50). - In the video, KO's daily candle on February 14 wicked down to the 50-day SMA almost to the penny. On the 5-minute chart, the same level showed the touch at about 8:10 a.m. Pacific.
- The method works on any study that takes a closing price or volume as a parameter. ATR reads high, close and low inside its formula, so each of the 3 needs the daily period.
- On the daily chart, the new cyan line sits right on top of the built-in 50 SMA. That overlap is a quick check that the code works before you switch to a 5-minute chart.
What Is an Aggregation Period in ThinkOrSwim?
An aggregation period in ThinkOrSwim is the time frame of the candles a study reads its price or volume from. That covers the open, high, low and close of each bar. By default, a study uses the chart's own aggregation period, so a 50-period SMA on a 5-minute chart averages the last 50 five-minute closes.
thinkScript lets you override that for any price value. You name the period you want, and the study reads that time frame's candles no matter what chart it sits on. These are some of the most commonly used periods, with the constant you type for each:
| Time frame | thinkScript constant |
|---|---|
| 5 minutes | AggregationPeriod.FIVE_MIN |
| 15 minutes | AggregationPeriod.FIFTEEN_MIN |
| 30 minutes | AggregationPeriod.THIRTY_MIN |
| 1 hour | AggregationPeriod.HOUR |
| Daily | AggregationPeriod.DAY |
| Weekly | AggregationPeriod.WEEK |
| Monthly | AggregationPeriod.MONTH |
The full list is in ThinkOrSwim's thinkScript reference: search for AggregationPeriod, which is what I show on screen in the video. Capital letters don't matter here. Our own downloads mix styles, such as AggregationPeriod.Day and AggregationPeriod.FIFTEEN_MIN, and they compile.
Why Plot a Daily Level on an Intraday Chart?
A daily level on an intraday chart shows you where a reaction might start while you watch the bars you trade. Coca-Cola's daily chart in the video had stacked moving averages: the 8, 21 and 34-period EMAs on top, the 50-period SMA as a yellow dashed line and the 200-period SMA as a white dashed line.

On February 14, KO tested the 50-day SMA. The daily candle only wicked into it, and the wick lined up with the 50 SMA almost to the penny before price reacted. Hindsight makes that look obvious. The question I ask in the video is this: can you see a moment like that setting up intraday and trade the reaction?
For that, the daily level has to be on the 5-minute chart. Otherwise you're flipping back and forth between a daily chart and a 5-minute chart, and the 5-minute chart's own 50 SMA is a different line altogether.
How to Write the Daily 50 SMA Study
The daily 50 SMA study is one line of thinkScript. Build it on a daily chart first, so you can compare it with the built-in 50 SMA:
- Open a daily chart, click the Studies icon, then Create.
- Name the study. Mine was a sample called TI Intraday SMA 50 Example.
- Type the normal 50 SMA line, then add the period parameter to
close(both versions are below). - Click OK, then Apply, and check that a cyan line now sits on top of the chart's 50 SMA.
- Switch the chart to 5 minutes. The cyan line keeps showing the daily 50 SMA.
Step 1: The Normal 50 SMA
This is the standard way to define a simple moving average in thinkScript:
This step’s code is free with an account. Create one or sign in.
SimpleMovingAvg is ThinkOrSwim's simple moving average function. It takes the price to average and the length: here the close and 50 bars. On a 5-minute chart, that means 50 five-minute closes, about 250 minutes of trading. That's not the level we want.
Step 2: Point the Close at the Daily Chart
The close can take a parameter of its own, and that parameter is the aggregation period:
This step’s code is free with an account. Create one or sign in.
close(period = AggregationPeriod.DAY) tells ThinkOrSwim to use daily closes no matter what chart the study is on. The length stays at 50, so the line is now the 50-day SMA. Click OK and the code compiles. To use a weekly 50 SMA instead, change DAY to WEEK.
Checking the Line on the Daily and 5-Minute Charts
The daily 50 SMA study plots a cyan line, since cyan is the default color for a new plot. On the daily chart, that line lands right on top of the yellow dashed 50 SMA, which tells you the code works. On the 5-minute chart, it shows the daily 50 SMA's value for each day. The table shows what each version plots:
| Chart | SimpleMovingAvg(close, 50) | SimpleMovingAvg(close(period = AggregationPeriod.DAY), 50) |
|---|---|---|
| Daily | 50-day SMA | 50-day SMA (the same line) |
| 5-minute | Average of the last 50 five-minute closes | 50-day SMA, at that day's value |
What Happened on KO's 5-Minute Chart
KO's 5-minute chart on February 14 is the example in the video. The cyan line was the daily 50 SMA, and the 50 SMA breach came at about 8:10 a.m. Pacific. Price bounced into the line, a small base formed, our Edge Signals indicator printed oversold signals, and then price bounced up from there.
It doesn't always look this clean. My point in the video is that levels like this tend to see reactions when price reaches them. Those reactions could come from algos or institutions. Seeing the level on the intraday chart lets you watch for that reaction as it happens.
Example 2: A Daily ATR in a Label
The Average True Range is a study you can't fix with one parameter. This example isn't in the video: it's from my written version of this lesson.
ATR doesn't take a price input, because it reads the high, close and low inside its formula. Here's ThinkOrSwim's ATR source code:
This step’s code is free with an account. Create one or sign in.
To read daily candles, each of the 3 prices inside TrueRange gets the daily period. Then an AddLabel line prints the value:
This step’s code is free with an account. Create one or sign in.

Now the label shows the 14-period ATR from daily candles on any intraday chart. If labels are new to you, our AddLabel tutorial covers the 3 parameters. For ATR on its own, see our Average True Range scans.
Which Studies Work With an Aggregation Period?
Any study that takes a closing price or volume as a parameter can read another time frame. You point that price at the period you want. I use the simple moving average in the video, but the same change works for an exponential moving average or a weekly line. These 2 lines are my own examples of each:
This step’s code is free with an account. Create one or sign in.
In the video I mention our Market Pulse indicator as another study you could plot from the daily chart. Our free Reversion to 50 Day SMA indicator uses this exact call with a symbol added: close(symbol = "SPY", period = AggregationPeriod.Day).
Some built-in studies have no price input at all. The built-in DMI is one, so our MTF DMI indicator rebuilds DI+, DI- and ADX from each time frame's highs and lows, the same way the ATR example above rebuilds True Range.
Limits and Common Errors
ThinkOrSwim can read time frames equal to or larger than the chart's own, never smaller. In our Multiple Time Frame Moving Averages tutorial, a 15-minute EMA on a 30-minute chart made every line disappear, with the error "the secondary period cannot be less than the primary". That indicator uses if/else blocks on GetAggregationPeriod() to plot only the lines a chart can show.
- The line disappears on a weekly chart. A daily study on a weekly chart asks for a smaller time frame than the chart's. Use it on daily and intraday charts.
- The line still changes when you switch charts. The period parameter is missing or in the wrong place. It goes inside the parentheses right after
close:close(period = AggregationPeriod.DAY). - The ATR label doesn't match the daily ATR. All 3 prices need the period. Leave one out and the formula mixes daily and intraday candles.
- The code won't run in a scan. Scans are stricter. In our Smarter MACD tutorial, the higher time frame code gave the scan error "secondary period is not allowed". The workaround there drops the period parameter and lets the scan's own aggregation setting pick the time frame.
How I Use Daily Levels Intraday
The daily 50 SMA on a 5-minute chart is a level to watch, not an entry by itself. I look for price moving into the level, then use an overbought or oversold indicator to confirm the move into it and the move away from it. Our list of 5 oversold indicators for ThinkOrSwim has options for that step.
When a setup forms at the level, decide where the stop goes before you enter, and size the position so a stop-out costs a small, fixed share of your account. A level that held once can break the next time.
Our multi-time frame indicators are built on the same aggregation period idea. The MTF Squeeze indicator checks 18 time frames for a squeeze from one chart, and members get the MTF Triple Squeeze and MTF Squeeze Histogram in the Squeeze Course. More lessons like this one are on the thinkScript tutorials page.
The daily line on an intraday chart
Drawn from real daily bars with the code on this page, through Oct 20, 2026. The line is SimpleMovingAvg(close(period = AggregationPeriod.DAY), 50): the 50-day average of daily closes, drawn on 30-minute bars. For each past day it is that day's daily value, so it steps once per session and stays flat inside the day.
TSLA, Oct 15, 2026: a test of the daily 50 SMA

TSLA had closed above its 50-day average the day before. On Oct 15, 2026 it traded down to 355.23 around 10:00 ET, at or under the line at 358.76, and closed the day at $362.49. On a daily chart that is one candle with a wick; on the 30-minute chart you can see when the test happened and how price behaved there.
Full thinkScript code
Create a free account or sign in to copy all 8 lines and download the file.
Download
Download Aggregation Periods - How to Plot Larger Time Frame Indicators on Smaller Time Frames for ThinkOrSwim.
Video: Aggregation Periods - How to Plot Larger Time Frame Indicators on Smaller Time Frames, built line by line
7 minutes on YouTube.
Watch on YouTube
Questions
What is an aggregation period in thinkScript?
An aggregation period is the time frame of the candles a study reads its price or volume from, such as 5 minutes, 1 hour, daily or weekly. By default a study uses the chart's own period. Adding period = AggregationPeriod.DAY to a price like close makes the study read daily candles on any chart.
How do I plot a daily moving average on an intraday chart in ThinkOrSwim?
Create a new study and write plot SMA50 = SimpleMovingAvg(close(period = AggregationPeriod.DAY), 50);. The period parameter makes the close come from daily candles, so the line is the 50-day SMA even on a 5-minute chart. Change the 50 or swap SimpleMovingAvg for ExpAverage to plot a different daily average.
Why does my 50 SMA change when I switch to a 5-minute chart?
A normal SimpleMovingAvg(close, 50) uses the chart's own candles. On a daily chart that's 50 days, and on a 5-minute chart it's the last 50 five-minute closes. Add period = AggregationPeriod.DAY inside the parentheses after close to keep the daily 50 SMA on every intraday chart.
What aggregation periods can I use in ThinkOrSwim?
Common ones are AggregationPeriod.FIVE_MIN, FIFTEEN_MIN, THIRTY_MIN, HOUR, DAY, WEEK and MONTH. The full list is in ThinkOrSwim's thinkScript reference under AggregationPeriod. A study can only read periods equal to or larger than the chart it sits on, so a daily study works on daily and intraday charts.
What does "secondary period cannot be less than the primary" mean?
It means the study asks for a time frame smaller than the chart's. The chart's period is the primary and the one in your code is the secondary. A 15-minute EMA on a 30-minute chart triggers it. Use the study on a chart of the same or a smaller time frame, or plot that line only on charts that can show it.
How do I plot a weekly moving average on a daily chart?
Use the same code with the weekly constant: plot SMA50W = SimpleMovingAvg(close(period = AggregationPeriod.WEEK), 50);. On a daily chart the line shows the 50-week SMA. In the video I point out that a weekly 50 SMA works the same way as the daily one.
Can I use an aggregation period with ATR?
Yes, but ATR has no price input to change. Copy its source code and add period = AggregationPeriod.DAY to each of the high, close and low inside TrueRange. Then print it with AddLabel(yes, ATR, Color.YELLOW); to see the daily 14-period ATR on an intraday chart.
How do I check that my aggregation period code is working?
Apply the study on a daily chart that already shows the built-in 50 SMA. If the code is right, the new cyan line sits right on top of it. Then switch to a 5-minute chart. The cyan line should hold each day's 50-day SMA value instead of tracking the 5-minute candles.
Get each new indicator by email
One email on Sundays with the week's new tool and its code. A free account also unlocks every .txt download.
No credit card. Unsubscribe anytime.
Fair Value Gap
False Breakout Scanner
Heiken Ashi Trend



Stock Volatility Box
Futures Volatility Box
ORB Setups
Squeeze Setups
Maximize Your Chart Space With This Simple Trick
Custom Toolbars - Instantly 10x Your Productivity
How to Track Percent Change From Open
Add Label Function
How to Import a thinkScript Study into ThinkOrSwim
How to Fix Bugs in thinkScript Code