Skip to main contentSkip to content
Squeeze Setups A live squeeze scanner built around the Slingshot Squeeze, with 22 years of backtest results behind it. See it, $99/month →
TOS Indicators
  • Tools

    Categories

    • Indicators
    • Backtesters
    • Scans
    • Dashboards
    • thinkScript
    • Member Resources
    Browse Full Library

    Featured Tutorials

    Fair Value Gap Indicator
    Fair Value Gap Indicator
    Indicators

    Download our free Fair Value Gap indicator for ThinkorSwim. It shades every...

    Learn more →
    False Breakout Scanner for ThinkorSwim (Free Scan Pair)
    False Breakout Scanner for ThinkorSwim (Free Scan Pair)
    Scans

    A two-scan pair that flags failed breakouts and failed breakdowns with volume...

    Learn more →
    Heiken Ashi Trend Indicator
    Heiken Ashi Trend Indicator
    Indicators

    Download our Custom Heiken Ashi indicator for ThinkOrSwim. Full ThinkScript code, formula...

    Learn more →

    Popular Posts

    Unusual Volume Pro Scans
    Unusual Volume Pro Scans
    Scans

    4 additional scans to find unusual volume overlapping with key...

    Learn more →
    High Short Interest Near 52 Week Highs (thinkScript)
    High Short Interest Near 52 Week Highs (thinkScript)
    Scans

    Build a simple scan in which to find stocks that...

    Learn more →
    Upcoming Earnings with High Short Interest
    Upcoming Earnings with High Short Interest
    Scans

    Build a scan to find stocks that are likely to...

    Learn more →
  • Courses
    Squeeze Course
    Squeeze Course
    19 Modules

    Scan, backtest, and trade the TTM Squeeze setup with precision.

    View Course →
    Earnings Course
    Earnings Course
    3 Modules

    Master earnings plays with free indicators and proven strategies for ThinkOrSwim.

    View Course →
    V-Shaped Reversals
    V-Shaped Reversals
    7 Modules

    Identify and trade powerful V-shaped reversal patterns with confidence and precision.

    View Course →
    Fibonacci Trading
    Fibonacci Trading
    4 Modules

    Learn to trade Fibonacci retracements and extensions in ThinkOrSwim effectively.

    View Course →
  • Products
    Futures Volatility Box Premium
    Futures Volatility Box

    Volatility models for 10 major futures markets, including the micros.

    Explore Futures VB →
    Stock Volatility Box Premium
    Stock Volatility Box

    Volatility levels for 600+ stocks and ETFs, with a live scanner.

    Explore Stock VB →
    Opening Range Breakouts Premium
    Opening Range Breakouts

    Scans 600+ stocks every 2 seconds for opening range breaks, with a backtester.

    Explore ORB Setups →
My Account
All Indicators
Beginner-Friendly 13 mins ThinkOrSwim

Moving Average Clouds Indicator for ThinkorSwim

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 Indicator
How to install in ThinkOrSwim →
Table of Contents
  • Key Takeaways
  • What Moving Average Clouds Show
  • How to Add the Indicator to ThinkorSwim
  • The Inputs
  • How the Code Works
  • SetDefaultColor vs AssignValueColor
  • How to Read the Clouds
  • Settings to Try
  • Related Moving Average Tools
  • Common Problems

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.

  1. Click the Studies icon on your chart, then click Create.
  2. Give the study a name, such as TI_MovingAvgClouds.
  3. Delete the starter code, paste in the code from the Code tab on this page, and click OK, then Apply.
  4. 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.

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

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.

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

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.
Moving Average Clouds Indicator.ts
#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.

Create Free Account Login
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.
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.
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.
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.
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.
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.
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.
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.

Here are some resources that you may find useful:

  • How to import an indicator into ThinkOrSwim (video tutorial)
  • Moving Average Crossover Backtester
  • Multiple Time Frame Moving Averages indicator
  • Stacked Moving Averages indicator
  • 3×8 EMA pattern to catch reversals
  • More free ThinkOrSwim indicators
Featured Tools:
Stock Volatility Box

Stock Volatility Box

Spot reversal zones across 600 stocks & ETFs.

  • Hourly & daily models
  • Powerful Live Scanner
  • Built for day traders
Futures Volatility Box

Futures Volatility Box

Pinpoint reversal zones in 10 major futures markets.

  • 5 models (incl. Scalper)
  • ThinkOrSwim & TradingView
  • SPX traders
ORB Setups

ORB Setups

Find the best Opening Range Breakout setups.

  • Powerful real-time scanner
  • Instant backtests
  • 2+ years data

Get Free Access

Create a free account for downloads and new tutorial alerts.

Create Free Account

Related tutorials and research

How to Build a Fair Value Gap Indicator in ThinkorSwim

How to Build a Fair Value Gap Indicator in ThinkorSwim

Indicators · Beginner-Friendly
How to Build a Heiken Ashi Trend Dots Indicator in ThinkorSwim

How to Build a Heiken Ashi Trend Dots Indicator in ThinkorSwim

Indicators · Beginner-Friendly
How to Build a Commodities Tracker in ThinkorSwim

How to Build a Commodities Tracker in ThinkorSwim

Indicators · Beginner
Trend Squeeze Indicator for ThinkorSwim

Trend Squeeze Indicator for ThinkorSwim

Indicators · Beginner
Volume Intensity Indicator for ThinkorSwim

Volume Intensity Indicator for ThinkorSwim

Indicators · Beginner-Friendly
Parabolic SAR Indicator, Scans and Backtester for ThinkorSwim

Parabolic SAR Indicator, Scans and Backtester for ThinkorSwim

Indicators · Intermediate

Ready to Trade With an Edge?

Join 40,000+ traders using institutional-grade tools for ThinkOrSwim.

Get the Bundle
TOS Indicators

Premium thinkorswim indicators, scans, and trading tools to help you trade smarter.

ThinkOrSwim Tools

  • Indicators
  • Scans
  • Backtesters
  • Dashboards
  • thinkScript
  • Browse All

Courses

  • Squeeze Course
  • Earnings Course
  • V-Shaped Reversals
  • Fibonacci Trading

Products

  • Futures Volatility Box
  • Stock Volatility Box
  • ORB Setups
  • Shop All

Guides

  • TTM Squeeze
  • Automated Trading
  • Volatility Trading
  • Opening Range Breakouts
  • Trade Reports
  • Contact Us

© 2026 TOS Indicators. All rights reserved.

Privacy Policy Terms of Service Disclaimer Accessibility

The information contained on this website is solely for educational purposes, and does not constitute investment advice. The risk of trading in securities markets can be substantial. You must review and agree to our Terms of Service prior to using this site.

U.S. Government Required Disclaimer - Commodity Futures Trading Commission. Futures and options trading has large potential rewards, but also large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. Don't trade with money you can't afford to lose. This website is neither a solicitation nor an offer to Buy/Sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this website. The past performance of any trading system or methodology is not necessarily indicative of future results.

Individual results may vary, and testimonials are not claimed to represent typical results. All testimonials are by real people, and may not reflect the typical purchaser's experience, and are not intended to represent or guarantee that anyone will achieve the same or similar results.

TOS Indicator's Traders and employees will NEVER manage or offer to manage a customer or individual's options, stocks, currencies, futures, or any financial markets or securities account. If someone claiming to represent or be associated with TOS Indicator solicits you for money or offers to manage your trading account, do not provide any personal information and contact us immediately.

CFTC RULE 4.41 - HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY, SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.