On this page
Overview
In this tutorial I build a Heiken Ashi indicator for ThinkOrSwim from scratch. It plots one dot per bar in a lower panel: green when the Heiken Ashi trend is confirmed bullish, red when it is confirmed bearish, and yellow for anything in between.
The indicator gives you the trend read of Heiken Ashi candles and leaves your regular candles on the price chart. The finished study is 10 lines of thinkScript with no inputs, so it makes a good first build if you want to learn some thinkScript. If you would rather skip the build, it is a free download.
Key Takeaways
- The Heiken Ashi Trend indicator is a free ThinkOrSwim lower study that plots one dot per bar along the zero line: green, red or yellow.
- A green dot needs 2 bars in a row where the Heiken Ashi close is at or above the Heiken Ashi open. A red dot needs 2 bars in a row where the close is below the open. Every other bar is yellow.
- The Heiken Ashi close is ohlc4, the average of the bar's open, high, low and close. The Heiken Ashi open is the average of the previous Heiken Ashi open and close.
- The study is 10 lines of thinkScript with no inputs, and it works on any symbol and any timeframe.
- Heiken Ashi lags raw price by design. In the video I suggest using the dots as a trend filter, paired with a separate trigger such as Edge Signals or a moving average crossover.
What Is Heiken Ashi?
Heiken Ashi is a way of drawing candles from averaged prices. The name means "average bar" in Japanese, and you will also see it spelled Heikin-Ashi. A regular candle shows the raw open, high, low and close of its own bar. A Heiken Ashi candle averages those values and blends in the previous Heiken Ashi candle.
On a regular ThinkOrSwim chart the candles often alternate green, red, green, red, which makes an uptrend hard to tell from a downtrend. Because Heiken Ashi averages the data, trends show up as long runs of one color. In a real uptrend you might see 8, 10 or even 15 green Heiken Ashi candles in a row, and when the trend flips, the colors flip with it.

The Heiken Ashi Formula
The Heiken Ashi formula has 4 parts, built from the current bar's prices and the previous Heiken Ashi candle. The table shows each part and whether our indicator needs it.
| Component | Formula | Used by the indicator |
|---|---|---|
| Heiken Ashi close | (open + high + low + close) / 4 of the current bar | Yes, as ohlc4 |
| Heiken Ashi open | (previous Heiken Ashi open + previous Heiken Ashi close) / 2 | Yes |
| Heiken Ashi high | The highest of the bar's high, the Heiken Ashi open and the Heiken Ashi close | No |
| Heiken Ashi low | The lowest of the bar's low, the Heiken Ashi open and the Heiken Ashi close | No |
The Heiken Ashi open is recursive: each bar's open depends on the bar before it, so every new candle opens at the midpoint of the previous candle's body. That chain of averages creates the smoothing. A candle's color depends only on its close and open. The high and low only set the wicks, so the indicator skips them.
Why Use Heiken Ashi, and What It Costs You
Heiken Ashi gives a trader 3 practical benefits over regular candlesticks:
- Trend identification. Long runs of one color make the direction plain.
- Fewer false signals. Minor pullbacks inside a trend usually don't flip the candle color. A single red bar in an uptrend is less likely to shake you out of a position.
- Cleaner reversals. When the color does change, it tends to mean something beyond noise.
The cost is lag. Heiken Ashi trails raw price action, so it won't catch the exact top or bottom, and that's by design. A lot of traders use Heiken Ashi on a higher timeframe for directional bias, then use regular candlesticks on a lower timeframe, such as a 2-minute or 5-minute chart, for the actual execution.
The Heiken Ashi open and close are calculated averages, so they often differ from prices that traded. That's one more reason to keep regular candles in front of you when you place orders, which a lower-panel indicator lets you do.
Reading Heiken Ashi Candles
Heiken Ashi candle shapes carry trend information too. Strong uptrend candles tend to have no lower wick, strong downtrend candles tend to have no upper wick, and small bodies with wicks on both sides show indecision while the trend changes hands.

What the Heiken Ashi Trend Indicator Shows
The Heiken Ashi Trend indicator shows a row of dots along the zero line of a lower panel, one dot per bar. The color tells you the state of the Heiken Ashi trend on that bar.
| Dot color | Condition in the code | What it tells you |
|---|---|---|
| Green | Heiken Ashi close at or above the Heiken Ashi open on this bar and the previous bar | Confirmed bullish trend |
| Red | Heiken Ashi close below the Heiken Ashi open on this bar and the previous bar | Confirmed bearish trend |
| Yellow | Anything else: the last 2 bars point in different directions | Transition, trend not confirmed yet |
A confirmed color needs 2 bars, so every flip in Heiken Ashi direction shows at least one yellow dot. The first bar in the new direction prints yellow, and the dot turns green or red on the second bar if the new direction holds.
In the video, the green dots line up with the uptrends and the red dots with the downtrends, while the regular candles above them bounce between red and green. The dots give a cleaner read on what the trend is doing.

How to Add the Heiken Ashi Indicator to ThinkOrSwim
The Heiken Ashi indicator is a single .ts study. Import the free download, or type the code in yourself as I do in the video.
Import the Download
The download is a .zip that holds TI_HeikenAshiTrendSTUDY.ts and a PDF guide to importing.
- Download the .zip from this page and unzip it.
- In ThinkOrSwim, click the Studies icon (the beaker) on the chart toolbar and select the Studies tab.
- Click Import in the lower left corner, select the .ts file and click Open.
- Search for the study by name and add it to your chart.
Our guide on how to import a study into ThinkOrSwim shows the same steps in a video.
Build It Yourself
- Click the Studies icon, then Create. The code editor panel opens.
- Give the study a name. In the video I call it TI_HeikinAshiDots.
- Type or paste the code from the Code tab into the editor and click OK.
- Apply the study to any chart.
How the Heiken Ashi Code Works
The Heiken Ashi Trend code builds the candle math first, then the trend test, then the dots, in the order I write it in the video. If you're new to turning chart rules into code, our tutorial on turning candlestick patterns into code uses the same building blocks.
Step 1: Put the Study in a Lower Panel
This step’s code is free with an account. Create one or sign in.
declare lower tells ThinkOrSwim to draw the study in its own panel under the price chart, so it doesn't take over the upper panel.
Step 2: The Heiken Ashi Close
This step’s code is free with an account. Create one or sign in.
ohlc4 is ThinkOrSwim's built-in shorthand for the average of the bar's open, high, low and close, which is the Heiken Ashi close.
Step 3: The Heiken Ashi Open
This step’s code is free with an account. Create one or sign in.
The [1] after a variable means its value on the previous bar. The line adds the previous bar's Heiken Ashi open and close and divides by 2. Because heikenAshiOpen refers to its own past value, this is the recursive part of the indicator, and it's what gives Heiken Ashi its smoothing.
Step 4: Up or Down on Each Bar
This step’s code is free with an account. Create one or sign in.
Each line returns 1 for true or 0 for false. A bar counts as up when the Heiken Ashi close is greater than or equal to the Heiken Ashi open, and as down when the close is below the open. A bar where the two are equal counts as up.
Step 5: Two Bars of Confirmation
Instead of reacting to every bar, the signal waits for 2 bars in a row in the same direction.
This step’s code is free with an account. Create one or sign in.
Two up bars give 1, two down bars give -1, and anything else gives 0, the neutral state.
That extra bar of confirmation cuts out a lot of the back-and-forth noise you'd get if the dots followed every Heiken Ashi candle.
Step 6: Plot the Dots
This step’s code is free with an account. Create one or sign in.
The !IsNan check makes sure the bar has data. If it does, the plot sits at 0, where all the dots line up. If not, Double.NaN skips the bar.
PaintingStrategy.POINTS draws dots instead of a line. SetLineWeight takes values from 1 to 5, and I use 5, the largest.
Step 7: Color the Dots
This step’s code is free with an account. Create one or sign in.
AssignValueColor picks a color for each bar from the signal: green for 1, red for -1, and yellow for everything else.
Heiken Ashi Candles vs. the Trend Dots
Heiken Ashi math shows up in 2 places: as candles that replace your regular ones, or as the Trend dots in a lower panel. The table shows how both compare with regular candlesticks.
| Regular candlesticks | Heiken Ashi candles | Heiken Ashi Trend dots | |
|---|---|---|---|
| Where it plots | Price panel | Price panel, in place of regular candles | Lower panel, under your regular candles |
| Prices shown | Raw open, high, low, close | Averaged values | No prices, one dot per bar |
| Color changes | Often, bar to bar | Less often, long runs | Only after 2 bars agree, with yellow in between |
| Lag | None | Some, by design | Heiken Ashi lag plus 1 confirmation bar |
At the end of the video I mention a separate smoothed Heiken Ashi tutorial, which builds an overlay that replaces your candlesticks with smoothed Heiken Ashi candles.
How I Use the Heiken Ashi Dots
The Heiken Ashi dots work as a trend filter. The simplest approach is to trade only in the direction of the trend: long trades when the dots are green or turning from yellow to green, and short trades when they are red or turning from yellow to red.
When the dots move from a trend color into yellow, that can be your sign to pull back, lighten up, or get out of the trade.
The dots give you direction, and you still need a trigger for timing. Pair them with something like our members-only Edge Signals indicator or a moving average crossover. A trend filter and a trigger together give a more complete picture. Our free Moving Average Clouds indicator is another trend tool you can run alongside the dots.
Decide where your stop goes before you enter, using the regular candles, and size the trade so a stop-out costs a small, fixed share of your account. Two green dots can turn yellow on the next bar.
Ways to Customize the Heiken Ashi Indicator
Customizing the Heiken Ashi Trend study means editing the code, since it has no inputs. Each edit below is my own suggestion and is not in the video or the download.
Ask for 3 Bars of Confirmation
The 3-bar version needs one more bar in the same direction before a dot turns green or red. Replace the heikenAshiTrendSignal line with this version, which also checks the bar 2 bars back:
This step’s code is free with an account. Create one or sign in.
You get fewer color changes and at least 2 yellow dots at each flip, at the cost of one more bar of lag.
Add Alerts When the Trend Confirms
To get an alert the first time the dots turn green or red, add these two lines at the bottom of the study:
This step’s code is free with an account. Create one or sign in.
Each alert is triggered on the bar where the signal changes to a confirmed color.
For a wider look at spotting turns in the trend, read our research on how to recognize when a trend reverses, and browse more free studies on the indicators page.
Heiken Ashi Trend dots on real charts
Drawn from real daily bars with the code on this page, through Oct 20, 2026. One dot per bar: green after 2 bullish Heiken Ashi bars in a row, red after 2 bearish ones, yellow in between. The regular candles stay on the chart.
SPY since May

Out of 119 sessions since May 1, 2026, SPY's dot was green 54 times, red 36 times and yellow 29 times. A yellow dot means the last two Heiken Ashi bars disagreed: the indicator only calls a trend once two bars in a row agree.
UNH: the longest green run in 2026

Of 44 well-known names, UNH had the longest green run that started in 2026: 23 sessions from Apr 1, 2026, the run ended May 5, 2026. It closed +35.3% from the first green dot to the last.
By the numbers
Daily bars for 648 stocks and ETFs through Oct 20, 2026: most stocks from July 2024, the 14 ETFs from 2016. The typical run is the median length of green runs that ended.
Full thinkScript code
Create a free account or sign in to copy all 18 lines and download the file.
Download
Download the Heiken Ashi Trend indicator for ThinkOrSwim. The download is a .zip with 2 files: TI_HeikenAshiTrendSTUDY.ts, the indicator from the video and the same code as the Code tab, and a PDF guide to importing ThinkOrSwim indicators. In ThinkOrSwim, click the Studies icon, select the Studies tab, click Import and choose the .ts file. If you haven't added a custom study before, here's how to import an indicator into your ThinkOrSwim platform.
Questions
What is Heiken Ashi?
Heiken Ashi, also spelled Heikin-Ashi, is a way of drawing candles from averaged prices. The name means "average bar" in Japanese. Each Heiken Ashi close averages the bar's open, high, low and close, and each open averages the previous Heiken Ashi open and close. The result is long runs of one color during trends.
How is a Heiken Ashi candle calculated?
The close is (open + high + low + close) / 4 of the current bar. The open is the previous Heiken Ashi open plus the previous Heiken Ashi close, divided by 2. The high is the highest of the bar's high, the Heiken Ashi open and the Heiken Ashi close, and the low is the lowest of the bar's low and those same two values.
How do I add the Heiken Ashi indicator to ThinkOrSwim?
Download the .zip from this page and unzip it. In ThinkOrSwim, click the Studies icon, select the Studies tab, click Import in the lower left, choose TI_HeikenAshiTrendSTUDY.ts and click Open. Then add the study to any chart. You can also click Create in the Studies window and paste in the code from the Code tab.
What do the green, red and yellow dots mean?
A green dot means the Heiken Ashi close was at or above the Heiken Ashi open on this bar and the previous bar, a confirmed bullish trend. A red dot means the close was below the open on both bars, a confirmed bearish trend. A yellow dot means the last 2 bars disagree, so the trend is not confirmed either way.
Why does the Heiken Ashi indicator wait for 2 bars?
One bar of Heiken Ashi color can still flip back on the next bar. Requiring 2 bars in a row in the same direction cuts out a lot of that back-and-forth noise. The trade-off is that every change of direction shows at least one yellow dot before the new color appears.
Does Heiken Ashi lag price?
Yes. Heiken Ashi averages price, so it trails raw price action and won't catch the exact top or bottom. That is by design. A lot of traders use Heiken Ashi on a higher timeframe for directional bias and regular candlesticks on a lower timeframe, such as a 2-minute or 5-minute chart, for execution.
What timeframe works with the Heiken Ashi Trend indicator?
The indicator has no timeframe setting. It reads whatever chart you apply it to, and in the video it runs on any symbol and any timeframe. A common approach is Heiken Ashi on a higher timeframe for bias and a lower timeframe for entries. Each dot carries the lag of Heiken Ashi plus one confirmation bar.
Is the Heiken Ashi indicator an entry signal?
No, it works as a trend filter. Take longs when the dots are green or turning from yellow to green, and shorts when they are red or turning from yellow to red. For the entry itself, pair it with a trigger such as Edge Signals or a moving average crossover, and decide your stop before you enter.
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
Simple Breakout Tool
Moving Average Clouds
Parabolic SAR