Our free moving average clouds indicator for ThinkorSwim shades the space between two averages: green when the fast one is on top, red when it is below.
Download IndicatorIn 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.
AddCloud(fastMA, slowMA, Color.Green, Color.Red), which uses the first color while the first value is greater than the second.AssignValueColor. SetDefaultColor works for one fixed color but returns an error when you give it an if/else condition.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.
The moving average clouds indicator is a free study you can import from the download or paste into a new study.
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 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.
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.
I started with a plain 8-period exponential moving average, plotted so I could see it on the chart.
plot EMA8 = ExpAverage(close, 8);
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.
Next I turned the two hardcoded values into inputs and plugged them into the average.
input fastMALength = 8;
input price = close;
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.
input fastMAType = AverageType.Exponential;
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.
plot fastMA = MovingAverage(fastMAType, price, fastMALength);
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.
input slowMALength = 21;
input slowMAType = AverageType.Exponential;
plot slowMA = MovingAverage(slowMAType, price, slowMALength);
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.
fastMA.assignValueColor(if fastMA > slowMA then Color.Green else Color.Red);
slowMA.assignValueColor(if fastMA > slowMA then Color.Green else Color.Red);
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.
AddCloud(fastMA, slowMA, Color.Green, Color.Red);
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 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.
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 3×8 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.
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.
The moving average clouds indicator is one of several free moving average tools on our site, and each answers a different question.
For more thinkScript tutorials, free and pro, browse our Learn page.
The moving average clouds indicator is short, and each of these four problems traces back to one line of code.
AssignValueColor instead.assignValueColor line to the other plot.AddCloud. The fast average goes first, then the slow average, then green, then red.ExpAverage. Switch it to MovingAverage with the type input as the first value.#Written by TOS Indicators 2023
#Home of the Volatility Box
#Indicator: Moving Average Clouds
#Full Tutorial Link: tosindicators.com/indicators/moving-average-clouds
input fastMALength = 8;
input fastMAType = AverageType.Exponential;
input slowMALength = 21;
input slowMAType = AverageType.Exponential;
input price = close;
plot fastMA = MovingAverage(fastMAType, price, fastMALength);
plot slowMA = MovingAverage(slowMAType, price, slowMALength);
fastMA.assignValueColor(if fastMA > slowMA then Color.Green else Color.Red);
slowMA.assignValueColor(if fastMA > slowMA then Color.Green else Color.Red);
AddCloud(fastMA, slowMA, Color.Green, Color.Red);Want the .ts file and the one-click import? Both come with a free account.
Join 40,000+ traders using institutional-grade tools for ThinkOrSwim.
Get the Bundle