On this page
Overview
In this tutorial I build a moving average clouds indicator for ThinkOrSwim. It plots a fast and a slow moving average, colors both lines green when the fast one is above the slow one and red when it's below, and fills the space between them with a matching cloud. The defaults are the 8 and 21-period exponential moving averages.
It's a beginner-friendly build that teaches three thinkScript skills: moving average inputs you change from the settings window, the AddCloud function, and line colors that follow the trend. If you're new to thinkScript, it's a good first indicator to write yourself.
Key Takeaways
- The moving average clouds indicator plots two moving averages and fills the space between them: green when the fast average is above the slow one, red when it is below.
- The defaults are an 8-period and a 21-period exponential moving average of the close. Each line can be simple, exponential, weighted, Wilders or Hull, chosen from the settings window.
- The cloud is one line of thinkScript,
AddCloud(fastMA, slowMA, Color.Green, Color.Red), which uses the first color while the first value is greater than the second. - Line colors that change with a condition need
AssignValueColor.SetDefaultColorworks for one fixed color but returns an error when you give it an if/else condition. - In the video I point out that the clouds show when a downtrend switches to an uptrend, and mention a 3 and 8 EMA pair for a closer read on momentum.
What Moving Average Clouds Show
Moving average clouds are two moving average lines with the space between them filled in. The color of the fill tells you which line is on top: green when the faster average is above the slower one, red when it's below. Both lines take the same color as the cloud, so the whole picture switches at once when the averages cross.
With the default 8 and 21-period exponential moving averages, the indicator draws an EMA cloud. Because the type of each line is an input, the same indicator can also draw a simple moving average cloud, a Hull cloud, or a mix, such as an exponential fast line with a simple slow line.
The cloud comes from the AddCloud function, a lesser-used function in ThinkOrSwim and one of the three skills this tutorial teaches.
How to Add the Indicator to ThinkOrSwim
The moving average clouds indicator is a free study you can import from the download or paste into a new study.
- Click the Studies icon on your chart, then click Create.
- Give the study a name, such as TI_MovingAvgClouds.
- Delete the starter code, paste in the code from the Code tab on this page, and click OK, then Apply.
- Double-click the study on your chart to change the lengths, the average types or the price.
The download has the same code as a .ts file. To import it instead, follow our guide on how to import a study into ThinkOrSwim.
The Inputs
The moving average clouds indicator has 5 inputs, and each one appears in the study's settings window. You never need to open the code to change the lines.
| Input | Default | What it controls |
|---|---|---|
fastMALength | 8 | Length of the fast moving average |
fastMAType | Exponential | Type of the fast average: Simple, Exponential, Weighted, Wilders or Hull |
slowMALength | 21 | Length of the slow moving average |
slowMAType | Exponential | Type of the slow average, with the same 5 choices |
price | close | The price both averages use. ThinkOrSwim gives you a dropdown, so you can pick the open or another price. |
I put price last so it appears at the bottom of the settings window. Both averages share it.
How the Code Works
The moving average clouds code is 10 lines plus comments, and I built it in the video in the 6 steps below. The finished lines come from the downloaded file.
Step 1: Start With One Hardcoded Average
I started with a plain 8-period exponential moving average, plotted so I could see it on the chart.
This step’s code is free with an account. Create one or sign in.
ExpAverage takes two inputs: the price, here the close, and the length, here 8. Both values are hardcoded, so the only way to change them is to edit the code.
Step 2: Pull Out the Price and the Length
Next I turned the two hardcoded values into inputs and plugged them into the average.
This step’s code is free with an account. Create one or sign in.
Nothing changes on the chart, but now you can double-click the study and change the line from the settings window. I switched the 8 to a 21 to show it. ThinkOrSwim also turned price into a dropdown of price types on its own, because I set it to close.
Step 3: Add the Average Type
This step’s code is free with an account. Create one or sign in.
AverageType works the same way. Setting the input to AverageType.Exponential gives you a dropdown with simple, exponential, weighted, Wilders and Hull. To make the line follow that dropdown, I swapped the exponential average function for MovingAverage, which takes 3 inputs: the type, the price and the length. I also renamed the plot from EMA8 to fastMA.
This step’s code is free with an account. Create one or sign in.
With that change the line is dynamic. In the video I switched it to a 50-period simple moving average, then to the open price, and the line redrew each time.
Step 4: Add the Slow Average
This step’s code is free with an account. Create one or sign in.
The slow line is a copy of the fast one with its own length and type inputs. Both lines share the price input. If you want separate prices, create a fast price input and a slow price input and plug one into each line.
Step 5: Color the Lines by Trend
This step’s code is free with an account. Create one or sign in.
ThinkOrSwim gave the fast line cyan and the slow line pink by default. Both lines use the same condition, so they turn green together when the fast average is above the slow one and red together when it's below. Matching colors keep the cloud clean.
Step 6: Draw the Cloud
This step’s code is free with an account. Create one or sign in.
The first two inputs are the two sets of values the cloud is drawn between. AddCloud compares the first to the second on every bar. When the first is greater, it uses the first color, green. When the first is less, it uses the second color, red.
SetDefaultColor vs AssignValueColor
SetDefaultColor and AssignValueColor both color a plot in thinkScript, and the clouds indicator needs the second one. I tried the first one in the video so you can see the error.
| SetDefaultColor | AssignValueColor | |
|---|---|---|
| Use it for | One fixed color | A color that changes with a condition |
| In the video | fastMA.SetDefaultColor(Color.Green) turned the fast line green | if fastMA > slowMA then Color.Green else Color.Red colored both lines by trend |
| With an if/else condition | Error: it can't access a dynamic value to initialize the color | Works |
The SetDefaultColor error is easy to miss. The editor doesn't highlight the line in red, the way it does for a missing semicolon. The message only shows in the error panel below the code.
How to Read the Clouds
The moving average clouds indicator shows you when you're in a downtrend and when that trend switches to an uptrend. A red cloud means the fast average is below the slow one. When the cloud turns green, the fast average has crossed above it.
For a closer read on momentum, I mention in the video that you can use a 3 and 8 EMA pair. Faster lines flip sooner, which helps you spot when momentum is building or switching and stay with it until it reverses. Our research on the 3x8 EMA pattern for catching reversals walks through that pair with examples.
A cloud tells you which average is on top. It doesn't tell you where to enter or where to put a stop. Decide where your stop goes before you trade a color change, and size the position so a stop-out costs a small, fixed share of your account.
Settings to Try
The moving average clouds indicator works with any two averages you pick. These are the pairs from the video.
| Fast line | Slow line | Where it comes up in the video |
|---|---|---|
| 8 EMA | 21 EMA | The defaults |
| 20 SMA | 50 SMA | To show the lines and clouds updating from the settings window |
| 3 EMA | 8 EMA | For a closer read on momentum |
To see how a pair has traded in the past, load the same lengths and types into our moving average crossover backtester. It defaults to the same 8 and 21 EMA pair and totals the profit and loss of every crossover on the chart.
Common Problems
The moving average clouds indicator is short, and each of these four problems traces back to one line of code.
- An error with SetDefaultColor. You gave it an if/else condition. Use
AssignValueColorinstead. - Only one line changes color. Add the same
assignValueColorline to the other plot. - The cloud colors are reversed. Check the order in
AddCloud. The fast average goes first, then the slow average, then green, then red. - Changing the average type does nothing. The plot still uses
ExpAverage. Switch it toMovingAveragewith the type input as the first value.
Moving average clouds on real charts
Drawn from real daily bars with the code on this page, through Oct 20, 2026. The defaults: the 8 and 21-period EMAs of the close. The cloud is green while the 8 is above the 21 and red while it is below.
SPY since April

SPY rose from $655.24 to $769.05 between Apr 1, 2026 and Oct 20, 2026, and its cloud changed color 9 times along the way: green through the long climbs, red in the pullbacks.
GOOGL: the most color changes

Of 30 well-known stocks, GOOGL's cloud changed color the most over the last 60 sessions: 6 times, while the stock moved +2.0% overall. Each change is the 8 and 21 crossing; when they cross back and forth, the cloud is describing the chop rather than calling a direction.
By the numbers
SPY daily, Jan 4, 2016 to Oct 20, 2026, 8 and 21-period EMAs. A run is how many days in a row the cloud kept one color (the median).
Full thinkScript code
Create a free account or sign in to copy all 18 lines and download the file.
Download
Download the Moving Average Clouds indicator for ThinkOrSwim. The download is a .zip with one study file, TI_MovingAvgCloudsSTUDY.ts, the same code as the Code tab on this page, plus a short text file that links to our import video. Import the .ts file as a study, then open its settings to change the lengths, average types and price. If you haven't imported a study before, here's how to import into your ThinkOrSwim platform.
Questions
What is a moving average clouds indicator?
A moving average clouds indicator plots two moving averages and fills the space between them with color. In our version the cloud and both lines are green when the fast average is above the slow one and red when it is below. The defaults are the 8 and 21-period exponential moving averages of the close.
How do I add moving average clouds to ThinkOrSwim?
Download the free study and import the .ts file, or click the Studies icon, click Create, name the study, and paste in the code from the Code tab. Click OK and Apply. Double-click the study on your chart to change the lengths, the two average types or the price.
How does the AddCloud function work in thinkScript?
AddCloud takes two sets of values and two colors, and shades the space between the values. In AddCloud(fastMA, slowMA, Color.Green, Color.Red), it compares fastMA to slowMA on every bar. When fastMA is greater, the cloud is green. When fastMA is less, it uses the second color, red.
Why does SetDefaultColor give an error with an if statement?
SetDefaultColor sets one fixed color, so it can't take a value that changes from bar to bar. With an if/else condition, the error panel says it can't access a dynamic value to initialize the color, and the line isn't highlighted in red. Use AssignValueColor for colors that depend on a condition.
Is the moving average clouds indicator the same as an EMA cloud?
With its default settings, yes: it shades between an 8-period and a 21-period exponential moving average. Each line's type is an input, so you can switch either one to simple, weighted, Wilders or Hull from the settings window and draw a different kind of moving average cloud with the same study.
What settings should I use for moving average clouds?
The study defaults to the 8 and 21-period EMAs. In the video I also showed the 20 and 50-period simple moving averages, and mentioned a 3 and 8 EMA pair for a closer read on momentum. Faster lines flip color sooner, and slower lines change less often.
Can I use a different price for each moving average?
Yes, with a small edit. The download uses one price input for both lines, set to the close. To split it, create a fast price input and a slow price input, then plug the fast one into the fast MovingAverage line and the slow one into the slow line. Each gets its own dropdown in the settings.
How do I test which moving average pair works best?
Load the same lengths and types into our moving average crossover backtester. It defaults to the same 8 and 21 EMA pair, places simulated trades each time the fast average crosses the slow one, and shows the running profit and loss under the chart, so you can compare pairs on the symbols you trade.
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
Multiple Time Frame Moving Averages
Reversion to 50-Day Moving Average
Moving Average Crossover Backtester
Moving Average Pullback Backtester
Stacked Moving Averages
Parabolic SAR