# Cumulative Advance Decline Trading System for ThinkorSwim

> Free cumulative advance decline study for ThinkorSwim: 6 symbol inputs, a 50-bar average and CCI-confirmed arrows turn an A/D line into a trading system.

Page: https://tosindicators.com/indicators/advance-decline  
Video: https://www.youtube.com/watch?v=1cDID8l8_ZM  
Section: Indicators  
Skill: Beginner-Friendly  
Access: free  
Updated: 2026-10-16

In this tutorial I build a cumulative advance decline line for a group of 6 stocks in ThinkorSwim, then turn it into a simple trading system. On each bar, every symbol that closed above its previous close adds 1, every symbol that closed below it subtracts 1, and the study keeps a running total.

The video answers a viewer's question: how do you make the symbols inputs, so you can swap a stock from the settings window instead of editing the code? From there I add a 50-bar average and arrows confirmed by the CCI. It was Episode 2 of our How to thinkScript series, so it suits traders learning thinkScript who want a breadth line for their own stocks.

## Key Takeaways

- The Cumulative Advance Decline Trading System is a free ThinkorSwim lower study that tracks 6 symbols. On each bar, a symbol that closed above its previous close counts +1, one that closed below counts -1, and `TotalSum` keeps the running total.

- The 6 symbols are inputs, `symbol_1` to `symbol_6`, so you change them in the study settings. The download defaults to FB, AMZN, AAPL, NFLX, GOOG and MSFT.

- A second line, `advDecLineAvg`, is the 50-bar average of the cumulative line. On the daily chart in the video, that covers the past 50 days.

- A bullish arrow prints when the line crosses above its average while the CCI is at +100 or higher. A bearish arrow prints on a cross below the average with the CCI at -100 or lower.

- In the video, a bearish arrow on September 17 was followed by a drop in the 6-stock group soon after.

## What Is a Cumulative Advance Decline Line?

A cumulative advance decline line is a running total of advancing issues minus declining issues. The classic version counts every stock on an exchange such as the NYSE. Each day, the number of stocks that closed up minus the number that closed down is added to the previous total, so a rising line means more stocks have been going up than down.

Our study applies the same counting to a group of 6 symbols you choose. That gives you a breadth line for your own basket, such as the largest tech stocks or the leaders of one sector. The table shows how the two compare.

| Feature | Classic advance decline line | This study |
| --- | --- | --- |

| What it counts | Every advancing and declining stock on an exchange | The 6 symbols in your inputs |

| What each bar adds | Advancing issues minus declining issues | +1 per symbol that closed up, -1 per symbol that closed down |

| Can you change the list? | No | Yes, from the study settings |

| Signals | A line only | Arrows on crosses of the 50-bar average, confirmed by the CCI |

Market internals measure the breadth of the whole market. If you want those readings instead of a custom basket, our [Supply Demand Edge indicator](https://tosindicators.com/indicators/supply-demand-edge) compares price to ThinkorSwim's advance/decline spread ($ADSPD) and the NYSE TICK. Our [Cumulative TICK indicator](https://tosindicators.com/indicators/cumulative-tick) keeps a running total of the TICK through the day.

## What the Indicator Plots

The Cumulative Advance Decline Trading System plots 4 things in its own panel below the price chart. The `declare lower;` line at the top of the code puts it there, because a running count of +1s and -1s is on a different scale from price.

| Plot | What it shows | How it draws |
| --- | --- | --- |

| `advDecLine` | The running total of the 6 symbols' +1 and -1 scores | Line |

| `advDecLineAvg` | The 50-bar average of `advDecLine` | Line |

| `bullishCrossOverSignal` | The line crossed above its average and the CCI is at +100 or higher | Up arrow, weight 3, on the average line |

| `bearishCrossOverSignal` | The line crossed below its average and the CCI is at -100 or lower | Down arrow, weight 3, on the average line |

## How to Add It to ThinkorSwim

The Cumulative Advance Decline study is a custom study, so you either import the download or paste the code into a new study.

- Download the indicator, or copy the code from the Code tab on this page.

- In ThinkorSwim, click the Studies icon in the top right corner of the chart, then click **Create**.

- Give the study a name. I called mine anchored cumulative advance decline.

- Delete the placeholder code, paste in the full code, and click **OK**, then **Apply**.

- Open the study settings to set your 6 symbols and the start date.

If you haven't added a custom study before, see our guide on [how to import a study into ThinkorSwim](https://tosindicators.com/thinkscript/how-to-import-thinkorswim).

## The Inputs

The Cumulative Advance Decline study has 7 inputs: 6 symbols and a start date.

| Input | Default in the download | What it controls |
| --- | --- | --- |

| `symbol_1` | FB | The first symbol in the group |

| `symbol_2` | AMZN | The second symbol |

| `symbol_3` | AAPL | The third symbol |

| `symbol_4` | NFLX | The fourth symbol |

| `symbol_5` | GOOG | The fifth symbol |

| `symbol_6` | MSFT | The sixth symbol |

| `startDateYyyyMmDd` | 2020120 | The date the line starts, written as YYYYMMDD |

The symbol defaults are the 6 stocks from the viewer's starting code. FB was Facebook's ticker when I recorded the video. The company now trades as META, so enter META in `symbol_1` if you want to keep it in the group.

The start date default in the download has 7 digits, 2020120. `GetYYYYMMDD()` returns 8-digit dates, and every one of them is a larger number, so every bar passes the check and the line covers your whole chart.

Type a full 8-digit date, such as 20201201 for December 1, 2020, and bars before that day plot 0. Step 3 below explains what the line shows from that day on.

## How the Code Works

The Cumulative Advance Decline code has 5 parts: the symbol inputs, a +1/-1 test for each symbol, the running total, the 50-bar average and the arrows. The viewer's starting code already plotted the running total. Episode 1 of the series builds our [anchored VWAP indicator](https://tosindicators.com/indicators/anchored-vwap), and you'll find the rest of our [thinkScript tutorials](https://tosindicators.com/thinkscript) on one page.

### Step 1: Make the Symbols Inputs

The starting code had each ticker typed into the code itself, so changing Amazon to Microsoft meant editing every place it appeared. The `input` keyword fixes that. Anything defined with `input` shows up in the study settings window, where you can change it without opening the code.

```
input symbol_1 = "FB";
input symbol_2 = "AMZN";
input symbol_3 = "AAPL";
input symbol_4 = "NFLX";
input symbol_5 = "GOOG";
input symbol_6 = "MSFT";
```

Then I replaced each quoted ticker with its input and renamed the variables to match: `symbol1`, `symbol2` and so on. To test it, I changed the first symbol from Facebook to Twilio in the settings, clicked OK, and the line redrew using Twilio.

### Step 2: Score Each Symbol

Each symbol gets 4 lines. The first two read its close on the current bar and on the bar before. The last two are true/false tests: did it close higher, or did it close lower?

```
def symbol1 = close(symbol_1);
def symbol11 = close(symbol_1)[1];

def symbol1a = symbol1 > symbol11;
def symbol1b = symbol1 < symbol11;
```

ThinkorSwim treats true as 1 and false as 0. So `symbol1a - symbol1b` is +1 when the symbol closed up, -1 when it closed down, and 0 when it closed unchanged. The other 5 symbols repeat the same 4 lines with their own numbers.

### Step 3: Keep the Running Total

`TotalSum` adds a value up across the bars on the chart. Here it adds the 6 scores, so each bar moves the line by anywhere from -6 to +6. I renamed the plot from the viewer's variable name to `advDecLine`.

```
input startDateYyyyMmDd = 2020120;
def beyondStartDate = if GetYYYYMMDD() >= startDateYyyyMmDd then 1 else 0;
plot advDecLine =  if beyondStartDate then TotalSum((symbol1a - symbol1b)+(symbol2a-symbol2b)+(symbol3a-symbol3b)+(symbol4a-symbol4b)+(symbol5a-symbol5b)+(symbol6a-symbol6b)) else totalsum(0);
```

Bars before the start date plot 0. The date check sits outside `TotalSum`, which adds on every bar either way. From the start date on, the line shows the total counted from your chart's first bar. Common Problems below shows a fix.

### Step 4: Add a 50-Bar Average

A cumulative line on its own doesn't show whether the current reading is high or low for the group. To see what the line normally is, I compare it to its average over the past 50 bars. On the daily chart I used, that's 50 days.

```
plot advDecLineAvg = Average(advDecLine,50);
```

`Average` is a simple moving average. Clicking Apply adds this second line to the panel.

### Step 5: Add the Crossover Arrows

A cross through the average can mark a burst of momentum in the group, and the CCI confirms it. The bearish plot checks 3 things on one bar: the line is below its average, the line's previous value was at or above the average, and the CCI is at -100 or lower.

```
plot bearishCrossOverSignal = if advDecLine < advDecLineAvg and advDecLine[1] >= advDecLineAvg and CCI()  advDecLineAvg and advDecLine[1] = 100 then advDecLineAvg else double.nan;
```

When all 3 are true, the arrow sits on the average line.

Otherwise the plot returns `double.nan` and nothing draws. The bullish plot is a copy with every comparison reversed and the CCI at +100 or higher. Both use `plot` instead of `def` because they need to draw on the chart.

### Step 6: Turn the Plots Into Arrows

Clicking Apply right after adding the 2 plots changes nothing on the chart, because ThinkorSwim doesn't know to draw them as arrows yet. These 4 lines set the painting strategy and give the arrows a line weight of 3 so they're easy to see.

```
bearishCrossOverSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bullishCrossOverSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
bearishCrossOverSignal.SetLineWeight(3);
bullishCrossOverSignal.SetLineWeight(3);
```

## Why the CCI Confirms the Signal

The CCI, or Commodity Channel Index, measures how far price has moved from its average, scaled by how far it usually strays. Readings above +100 or below -100 sit outside its usual range. In the video, I read +100 or higher as confidence in a bullish breakout and -100 or lower as confidence in a bearish one.

`CCI()` with empty parentheses runs the built-in study, with its default settings, on the symbol your chart shows. So the cross comes from the group, and the confirmation comes from your chart. In the video, I read the arrows as long or short timing for the tickers in the group, so load it on one of your 6 stocks.

## Examples From the Video

The Cumulative Advance Decline example in the video uses the 6 default stocks on a daily chart. With the arrows on, I scrolled back through the group's signals:

- **The first bearish arrow.** The group fell sharply after it.

- **A recent bullish arrow.** It had triggered shortly before I recorded, so the outcome wasn't on the chart yet.

- **A bearish arrow on September 17.** The group dropped soon after.

On that chart I called it a pretty reliable signal. That's 3 arrows on one group of 6 stocks, so check the arrows on your own symbols and timeframe before you rely on them.

## How I Use the Arrows

The Cumulative Advance Decline arrows are a read on the group's momentum. In the video, I read them as the times to get long or short in the stocks that make up the group. The CCI half of each arrow comes from the chart you load the study on, so check that stock's own chart before you act on an arrow.

An arrow doesn't tell you where you're wrong. Decide where your stop goes before you enter, and size the position so a stop-out costs a small, fixed share of your account.

## Ways to Extend the System

The Cumulative Advance Decline study is a starting point. The average is one statistic applied to the line, and at the end of the video I suggest others you can add the same way: a standard deviation, the median, or linear regression techniques. None of them are in the download.

You can also change the 50 in `Average(advDecLine,50)` for a faster or slower average, or replace the 6 symbols with the stocks you trade.

## Common Problems and Fixes

Most Cumulative Advance Decline problems come from a symbol, the start date, or arrows that never print.

- **A symbol doesn't load.** Check each ticker in the settings. A ticker that has changed, like FB to META, needs the new symbol.

- **The start date does nothing.** The default, 2020120, is 7 digits. Enter 8 digits in YYYYMMDD format.

- **The line jumps at the start date.** Bars before the date plot 0, and from the start date on, the line shows the total counted from the first bar on your chart.

- **No arrows.** A cross only gets an arrow when the CCI is past +100 or -100 on the same bar, so crosses without a strong CCI reading are skipped. Scroll back further or try another timeframe.

To count only from your start date, move the date check inside the sum, the way our anchored VWAP indicator does. Replace the `plot advDecLine` line with the line below. This edit is my suggestion and isn't in the video or the download:

```
plot advDecLine = TotalSum(if beyondStartDate then (symbol1a - symbol1b)+(symbol2a-symbol2b)+(symbol3a-symbol3b)+(symbol4a-symbol4b)+(symbol5a-symbol5b)+(symbol6a-symbol6b) else 0);
```

If ThinkorSwim shows an error after an edit, our tutorial on [how to fix bugs in thinkScript code](https://tosindicators.com/thinkscript/fix-bugs) covers how to track it down. You'll find more free studies on our [indicators page](https://tosindicators.com/indicators).

## thinkScript code

```
#Written by TOS Indicators 2020
#Home of the Volatility Box
#Indicator: Anchored Cumulative Advance Decline
#References TTM_Squeeze source code in TOS and Edge Signals Source Code
#Full Course Link: tosindicators.com/squeeze-course/

#Update 12/6/20 - Fixed line #50 which contained a typo. Thanks to Karl N. and Sidd N. for catching the error.

declare lower;

input symbol_1 = "FB";
input symbol_2 = "AMZN";
input symbol_3 = "AAPL";
input symbol_4 = "NFLX";
input symbol_5 = "GOOG";
input symbol_6 = "MSFT";

#FB
def symbol1 = close(symbol_1);
def symbol11 = close(symbol_1)[1];

def symbol1a = symbol1 > symbol11;
def symbol1b = symbol1 < symbol11;

#AMZN
def symbol2 = close(symbol_2);
def symbol21 = close(symbol_2)[1];

def symbol2a = symbol2 > symbol21;
def symbol2b = symbol2 < symbol21;

#AAPL
def symbol3 = close(symbol_3);
def symbol31 = close(symbol_3)[1];

def symbol3a = symbol3 > symbol31;
def symbol3b = symbol3 < symbol31;

#NFLX
def symbol4 = close(symbol_4);
def symbol41 = close(symbol_4)[1];

def symbol4a = symbol4 > symbol41;
def symbol4b = symbol4 < symbol41;

#GOOG
def symbol5 = close(symbol_5);
def symbol51 = close(symbol_5)[1];

def symbol5a = symbol5 > symbol51;
def symbol5b = symbol5 < symbol51;

#MSFT
def symbol6 = close(symbol_6);
def symbol61 = close(symbol_6)[1];

def symbol6a = symbol6 > symbol61;
def symbol6b = symbol6 < symbol61;

input startDateYyyyMmDd = 2020120;
 def beyondStartDate = if GetYYYYMMDD() >= startDateYyyyMmDd then 1 else 0;
 plot advDecLine =  if beyondStartDate then TotalSum((symbol1a - symbol1b)+(symbol2a-symbol2b)+(symbol3a-symbol3b)+(symbol4a-symbol4b)+(symbol5a-symbol5b)+(symbol6a-symbol6b)) else totalsum(0);

plot advDecLineAvg = Average(advDecLine,50);

plot bearishCrossOverSignal = if advDecLine < advDecLineAvg and advDecLine[1] >= advDecLineAvg and CCI() <= -100 then advDecLineAvg else double.nan;

plot bullishCrossOverSignal = if advDecLine > advDecLineAvg and advDecLine[1] <= advDecLineAvg and CCI() >= 100 then advDecLineAvg else double.nan;

bearishCrossOverSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bullishCrossOverSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
bearishCrossOverSignal.SetLineWeight(3);
bullishCrossOverSignal.SetLineWeight(3);
```

## Questions

### What is a cumulative advance decline line?

A cumulative advance decline line is a running total of advancing issues minus declining issues. The classic version counts every stock on an exchange each day. Our ThinkorSwim study applies the same counting to 6 symbols you choose: on each bar, a symbol that closed up adds 1, one that closed down subtracts 1, and the result is added to the running total.

### How do I add the cumulative advance decline indicator to ThinkorSwim?

Download the study or copy the code from the Code tab. In ThinkorSwim, click the Studies icon, click Create, name the study, paste in the code, then click OK and Apply. The study opens in its own panel below the chart. Open its settings to enter your 6 symbols and an 8-digit start date.

### How do I change the stocks in the advance decline line?

Open the study settings and type new tickers into symbol_1 through symbol_6. They are inputs, so you never have to edit the code. In the video, I swapped Facebook for Twilio, clicked OK, and the line redrew with Twilio in the group. The download defaults are FB, AMZN, AAPL, NFLX, GOOG and MSFT.

### What do the arrows on the advance decline indicator mean?

An up arrow means the cumulative line crossed above its 50-bar average while the CCI was at +100 or higher. A down arrow means it crossed below the average while the CCI was at -100 or lower. Both arrows draw on the average line at weight 3. I read them as timing for longs or shorts in the stocks in the group.

### Why does the system use the CCI?

The CCI, or Commodity Channel Index, filters the crossovers. A cross through the average can mark a burst of momentum in the group, and the CCI confirms it. In the video, I treat +100 or higher as confidence in a bullish breakout and -100 or lower as confidence in a bearish one. The CCI reads the symbol on your chart, not the group.

### How do I set the start date for the cumulative advance decline line?

Enter the date in the startDateYyyyMmDd input as YYYYMMDD, so December 1, 2020 is 20201201. Bars before that date plot 0. The download's default, 2020120, has only 7 digits, so every bar passes the check and the line covers your whole chart until you enter a full 8-digit date.

### Why don't I see any arrows on the indicator?

An arrow needs two things on the same bar: the cumulative line crossing its 50-bar average, and the CCI at +100 or more for a bullish arrow, or -100 or less for a bearish one. Crosses without a strong CCI reading are skipped. Scroll back through more history or try another timeframe, and check that all 6 symbols load.

### How is this different from the NYSE advance decline line?

The NYSE advance decline line counts every advancing and declining stock on the exchange, so it measures the breadth of the whole market. This study counts only the 6 symbols you enter, and each one adds at most 1 per bar. It also adds a 50-bar average and CCI-confirmed arrows, which the classic line doesn't have.

## Related

- [What Market Internals are Telling Us About Tomorrow](https://tosindicators.com/research/market-internals-telling-us-tomorrow-thinkorswim)
- [2 Ways to Use NYSE $TICK to Spot Trend Days](https://tosindicators.com/research/nyse-tick-spot-trend-days-thinkorswim)
- [How to Build an Anchored VWAP Indicator in ThinkorSwim](https://tosindicators.com/indicators/anchored-vwap)
- [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)

