# Moving Average Clouds Indicator for ThinkorSwim

> Free moving average clouds indicator for ThinkorSwim: 8 and 21 EMA lines by default, 5 average types, green and red clouds drawn with one AddCloud line.

Page: https://tosindicators.com/indicators/moving-average-clouds  
Video: https://www.youtube.com/watch?v=yvTY-Bi9_OY  
Section: Indicators  
Skill: Beginner-Friendly  
Access: free  
Updated: 2026-10-16

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`. `SetDefaultColor` works 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](https://tosindicators.com/thinkscript/how-to-import-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.

```
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.

### Step 2: Pull Out the Price and the Length

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`.

### Step 3: Add the Average Type

```
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.

### Step 4: Add the Slow Average

```
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.

### Step 5: Color the Lines by Trend

```
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.

### Step 6: Draw the Cloud

```
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 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](https://tosindicators.com/research/momentum-reversal-pattern) 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](https://tosindicators.com/backtesters/moving-average-crossover). It defaults to the same 8 and 21 EMA pair and totals the profit and loss of every crossover on the chart.

## Related Moving Average Tools

The moving average clouds indicator is one of several free moving average tools on our site, and each answers a different question.

- **More than two averages.** Our [stacked moving averages indicator](https://tosindicators.com/indicators/stacked-moving-averages) plots the 8, 21 and 34 EMAs with the 50 and 200 SMAs and draws an arrow when they move into a stacked formation.

- **Averages from other time frames.** Our [multiple time frame moving averages indicator](https://tosindicators.com/indicators/multiple-moving-averages) puts daily, 1-hour, 30-minute and 15-minute averages on one intraday chart.

- **A history of the crossover.** The crossover backtester above trades the same cross that flips the cloud's color.

For more thinkScript tutorials, free and pro, browse our [Learn page](https://tosindicators.com/learn).

## 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 `AssignValueColor` instead.

- **Only one line changes color.** Add the same `assignValueColor` line 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 to `MovingAverage` with the type input as the first value.

## thinkScript code

```
#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);
```

## 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.

## Related

- [How to Build a Fair Value Gap Indicator in ThinkorSwim](https://tosindicators.com/indicators/fair-value-gap)
- [How to Build a Heiken Ashi Trend Dots Indicator in ThinkorSwim](https://tosindicators.com/indicators/heiken-ashi)
- [How to Build a Commodities Tracker in ThinkorSwim](https://tosindicators.com/indicators/commodities-tracker)
- [Trend Squeeze Indicator for ThinkorSwim](https://tosindicators.com/indicators/trend-squeeze)
- [Volume Intensity Indicator for ThinkorSwim](https://tosindicators.com/indicators/volume-intensity)
- [Parabolic SAR Indicator, Scans and Backtester for ThinkorSwim](https://tosindicators.com/indicators/parabolic-sar)

