VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / Indicators and signals

Heikin Ashi candles: how they are calculated and tested

A Heikin Ashi candle closes at (open + high + low + close) ÷ 4 and opens at the midpoint of the previous Heikin Ashi open and close, so it averages real prices to show trends more smoothly. You can test rules built on it if the signals come from Heikin Ashi but every fill, stop and target uses real prices.

By · Published · updated · Editorial policy

Contents
  1. What is a Heikin Ashi candle?
  2. How is a Heikin Ashi candle calculated?
  3. Heikin Ashi vs candlestick: what changes on the chart?
  4. Why do Heikin Ashi prices break fills and stops in a backtest?
  5. Which simple Heikin Ashi rules can you test?
  6. How do you test a Heikin Ashi strategy step by step?
  7. Does Heikin Ashi give you an edge by itself?
  8. Frequently asked questions
  9. References

What is a Heikin Ashi candle?

A Heikin Ashi candle is a smoothed candle: its close averages the bar's open, high, low and close, and its open is the midpoint of the previous Heikin Ashi open and close. It shows trends clearly, but its prices are calculated. A testable strategy takes signals from Heikin Ashi and fills at real prices.

The name is Japanese and roughly means "average bar". "Heiken Ashi" is a common alternative spelling of the same candle. A regular candlestick is a bar drawn from four real prices: the first trade (open), the highest and lowest trades (high and low) and the last trade (close). Heikin Ashi changes the candles themselves, while other technical indicators are drawn on top of ordinary prices.

Think of a car's speedometer. One type shows your exact speed at every moment, so the needle jumps. Another type shows your average speed over the last few seconds, so the needle moves smoothly but reacts late. A regular candle is the first speedometer. A Heikin Ashi candle is the second one.

How is a Heikin Ashi candle calculated?

Each Heikin Ashi candle is built from the current real bar and the previous Heikin Ashi candle, so every candle carries part of the history before it. The four values are:

Heikin Ashi valueHow it is calculatedWhat it represents
CloseAverage of the real bar's open, high, low and closeThe "middle" price of the current bar
OpenMidpoint of the previous Heikin Ashi open and the previous Heikin Ashi closeThe previous candle, carried forward
HighThe highest of the real high, the Heikin Ashi open and the Heikin Ashi closeNever lower than the real high
LowThe lowest of the real low, the Heikin Ashi open and the Heikin Ashi closeNever higher than the real low

The close is the only value with a short formula: HA close = (Open + High + Low + Close) ÷ 4. "HA close" is the Heikin Ashi close. Open, High, Low and Close are the four real prices of the same bar.

The first candle has no previous Heikin Ashi candle. Most platforms start its open at the midpoint of the real open and close. The starting value loses half its weight with every new bar. After ten bars it carries less than one part in a thousand of the result.

Hypothetical example

The previous Heikin Ashi candle has an open of 98 and a close of 100. The current real bar opens at 100, reaches a high of 104 and a low of 99, and closes at 103.

HA close = (100 + 104 + 99 + 103) ÷ 4 = 101.5. HA open = (98 + 100) ÷ 2 = 99. HA high = the highest of 104, 99 and 101.5 = 104. HA low = the lowest of 99, 99 and 101.5 = 99.

The Heikin Ashi candle is green, with a body from 99 to 101.5. The real candle is also green, but its body runs from 100 to 103. The real close is 1.5 points above the Heikin Ashi close.

Heikin Ashi vs candlestick: what changes on the chart?

A Heikin Ashi chart shows fewer colour changes and longer runs of one colour, because each candle is partly an average of the candles before it. The table shows what each part of the candle means on the two chart types.

Part of the candleRegular candlestickHeikin Ashi candle
OpenThe first real trade of the barA calculated midpoint of the previous candle
CloseThe last real trade of the barThe average of four real prices
ColourReal close compared with real openHeikin Ashi close compared with Heikin Ashi open
Gaps between barsVisibleMostly hidden, because the open ignores the real open
WicksThe real high and lowCan stretch past the real high or low to reach the calculated open
Colour changes in a trendFrequentFewer, with longer runs

Classic candlestick patterns such as an engulfing bar or a doji depend on real opens and closes. They do not carry over to Heikin Ashi candles. If you test pattern rules, test them on regular candles, as described in testing bullish and bearish candlestick patterns.

The same ten hypothetical bars drawn twice: as regular candles they change colour 5 times and show a gap up at bar 6, as Heikin Ashi candles they change colour only 2 times and the gap is hidden Same bars, fewer flips Ten hypothetical bars, drawn twice Regular Heikin Ashi gap 5 flips 2 flips Heikin Ashi smooths and hides gaps. So: check gaps on real candles.
The same ten bars as regular candles (top) and Heikin Ashi candles (bottom). The Heikin Ashi row has fewer colour changes and hides the gap.

Why do Heikin Ashi prices break fills and stops in a backtest?

A backtest that fills orders or checks stops at Heikin Ashi prices trades at prices the market may never have printed, and the error usually favours the strategy. In a rising bar that closes near its high, the Heikin Ashi close sits below the real close. A long entry "filled at the Heikin Ashi close" therefore looks cheaper than any price you could still have bought at once the signal was known. In a falling market the same thing happens in reverse for shorts. Because trend rules buy in rising markets and sell in falling ones, the error is not random. It adds a small gift to almost every trade.

Stops and targets have a second problem. The Heikin Ashi low is never higher than the real low, and the Heikin Ashi high is never lower than the real high. A backtest that checks a stop against the Heikin Ashi low can record a stop-out when the real market never reached the stop. A target checked against the Heikin Ashi high can count as filled when no real trade reached it.

Hypothetical example

The candle from the worked example turns green, and the rule buys. A backtest that fills at the Heikin Ashi close records an entry at 101.5. A realistic backtest decides at the bar close and buys at the next real open, say 103.2. The gap is 1.7 points on one trade. If one point is worth $50, the averaged-price backtest overstates this trade by $85 before any commission or slippage.

One rising hypothetical bar: the real candle opens at 100 and closes at 103, the Heikin Ashi candle opens at 99 and closes at 101.5, so the Heikin Ashi close is 1.5 points below the real close and is not a real close Same bar, two closes Rising bar from the worked example Real Heikin Ashi 1.5 Real close 103 HA close 101.5 Not a real close HA fills look cheaper than reality. So: fill at the next real open.
The hypothetical example above: the Heikin Ashi close is 1.5 points below the real close, so a fill at the Heikin Ashi close is a price that was not the real close.

Some charting platforms can run a strategy directly on a Heikin Ashi chart. Depending on the settings, the fills may then use the averaged prices. Check which prices your platform fills at before you trust the result.

Which simple Heikin Ashi rules can you test?

Most Heikin Ashi strategies are colour-change rules, and each one is clear enough to test without any judgment calls. Here are four common versions for the long side. The short side is the mirror image.

RuleEntryExitWhat it changes
1. Colour changeFirst green candle after a red oneFirst red candleEarliest entry, most trades
2. Confirmed changeSecond green candle in a rowSecond red candle in a rowFewer trades, later entry and exit
3. Strong candleGreen candle with no lower wick (Heikin Ashi low equals Heikin Ashi open)First red candleWaits for a candle with no lower wick
4. Trend filterRule 1, only when the real close is above a 50-bar moving averageFirst red candleSkips signals against the larger trend

It helps to know what the colour really measures. The Heikin Ashi open puts half its weight on the previous open and half on the previous close. That makes it an exponential moving average of past Heikin Ashi closes, roughly a three-bar one. A green candle therefore means "this bar's average price is above a very short average of earlier bars". A Heikin Ashi colour change is a short moving-average crossover in a different form. That tells you which baseline to compare it with.

How do you test a Heikin Ashi strategy step by step?

Build Heikin Ashi from real bars inside the test and judge the rule against simple baselines. A good result survives realistic fills and costs. A weak one only looks good on the smooth chart.

  1. Load real bar data. Use real open, high, low and close as the price series. Compute Heikin Ashi from it. Do not load Heikin Ashi bars as if they were prices.
  2. Decide at the close of the bar. Use only completed Heikin Ashi candles, because the current candle keeps changing until its bar closes.
  3. Fill on the next bar. Enter and exit at the next real open (next-bar execution).
  4. Add costs to every trade. Include commission and slippage per round trip. Slippage is how far your real fill lands from the price the backtest assumed. See trading costs in backtests.
  5. Check stops and targets on real highs and lows. Size positions from the real distance between the entry and the stop.
  6. Run two baselines. Test the same entry and exit timing on regular candles (green means real close above real open). Then test a short moving-average crossover on real closes.
  7. Count trades and compare the average trade with the cost. Colour rules flip often in sideways markets. The average trade should be several times the round-trip cost.
  8. Test on data the rule has not seen. Keep the number of variants small and check them out of sample, for example with walk-forward analysis and the strategy validation in AlphaPrime (Valynox).
CheckWorth more researchWeak rule
Moving fills from Heikin Ashi prices to the next real openResult shrinks a littleResult disappears
Compared with the moving-average baseline after costsClearly betterAbout the same or worse
Different bar sizes, for example 15, 30 and 60 minutesSimilar behaviourWorks on only one
Average trade compared with round-trip costSeveral times largerAbout equal

Does Heikin Ashi give you an edge by itself?

No. Heikin Ashi changes how prices are drawn, not what prices did, so any edge has to come from the rule and must show up in tests on real fills. Smoothing always costs time. In the speedometer comparison, the smooth needle shows you braked only after you have already slowed down. A Heikin Ashi chart often stays green for one or two bars after a top, and those bars are paid for in every exit.

Hypothetical lag: the real closing price peaks at bar 5 and then falls, but the Heikin Ashi colour stays green through bar 6 and turns red only at bar 7, a two-bar delay Colour turns two bars late Hypothetical closes and HA colours Real close Heikin Ashi two-bar delay Smoothing always costs time. So: count the lag in every exit.
Hypothetical example of lag: the real price turns at bar 5, but the Heikin Ashi colour turns only at bar 7.

The smooth chart also misleads the eye. Long green and red runs make past trends look easy to catch, while the many small losing flips in sideways periods are easy to miss when you scroll. Only a full test with costs counts those flips. Each of those colour flips appears as its own trade in AlphaPrime's performance report, next to the equity curve and drawdown it produced.

The last limit is how many versions you try. If you test dozens of variants of the colour rules, filters and bar sizes, the best one will look good partly by luck. Research on technical trading rules shows that the best of many rules has to be judged against the number of rules tried (Sullivan, Timmermann and White, 1999). Backtest overfitting grows with the number of variants (Bailey, Borwein, López de Prado and Zhu, 2014).

What this means if you use AlphaPrime: you can write a Heikin Ashi idea as an explicit entry and exit rule with strategy generation. AlphaPrime's backtesting evaluates each candidate on real historical bar data with fees, slippage and next-bar execution, the same setup this article recommends for any rule built on smoothed prices.

Frequently asked questions

Is Heiken Ashi the same as Heikin Ashi?

Yes. "Heiken Ashi" is a common alternative spelling of Heikin Ashi, and both names describe the same averaged candle. Platforms use the same basic calculation: an averaged close, an open taken from the previous candle, and highs and lows that include the real extremes; only the starting value of the first candle can differ.

Is Heikin Ashi better than regular candlesticks for trading?

Neither chart type is better in general. Heikin Ashi makes trends easier to see and reduces colour noise, but it reacts later and hides real opens, closes and gaps. Regular candles show what actually traded, which is what fills and stops depend on.

Can I backtest a strategy on a Heikin Ashi chart?

Yes, as long as the backtest uses Heikin Ashi only for signals and real prices for every order. If fills, stops or targets use Heikin Ashi values, the result usually looks better than anything you could have traded. Decide at the bar close and fill at the next real open with costs included.

Do Heikin Ashi candles repaint?

A completed Heikin Ashi candle does not change, but the current one changes until its bar closes, so signals should use completed candles only. Because each open depends on the previous candle, the first few candles can differ slightly when a chart starts at a different date. That difference halves with each bar and soon becomes too small to matter.

References

  • Sullivan, R., Timmermann, A., & White, H. (1999). Data-Snooping, Technical Trading Rule Performance, and the Bootstrap. The Journal of Finance, 54(5), 1647–1691.
  • Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.