Charts/Finance charts
Heikin-Ashi
<HeikinAshi /> · 10 examples
Candlesticks that each remember the one before, so a trend looks like a run of one colour.
Overview
A normal candlestick chart is honest to a fault. It tells you exactly where each period opened, closed, peaked and bottomed out, and the result, on a restless market, is a row of candles alternating red and green like a badly planned flower bed. You came to ask which way the price is going. You were told what it did, in great detail, every five minutes.
Heikin-Ashi is a Japanese term usually translated as "average bar", and that is the whole technique. Instead of drawing each period's raw open, high, low and close, you draw smoothed ones, where each candle is built partly from the one before. The noise cancels, the colour stays the same for as long as the trend does, and the pullbacks that would have been a red candle become a slightly shorter green one.
The price you pay is that the candles are no longer real. The close of a Heikin-Ashi candle is not where anything traded. That is the trade-off, and it settles how to use the chart: to read direction, and never to place an order.
Props
API
<HeikinAshi data={bars} x={|b: &Bar| b.time}
open={|b: &Bar| b.open} high={|b: &Bar| b.high} low={|b: &Bar| b.low}
close={|b: &Bar| b.close} volume={|b: &Bar| b.volume} />| Prop | Type | Default |
|---|---|---|
data | Vec<T>, Signal<Vec<T>>, or your own Dataset | required |
x | Fn(&T) -> f64: the start of each period, in milliseconds since the epoch | required |
open, high, low, close | Fn(&T) -> f64 | required |
volume | Fn(&T) -> f64 | none |
mode | CandleMode | CandlesVolume |
candle_style | CandleStyle | Candles |
up, down | colours | your theme's good and bad colours |
x_axis | AxisConfig | a time axis |
y_axis | AxisConfig | AxisConfig::new() |
legend, tooltip, class | as on <Candlestick> |
Each candle is averaged with the one before it:
| Part | Formula |
|---|---|
| close | (open + high + low + close) / 4 |
| open | (previous open + previous close) / 2; the first candle uses (open + close) / 2 |
| high | the largest of high, open and close |
| low | the smallest of low, open and close |
Run them
10 examples
Press Run to load an example into the live render at the top of the page. Open one to read its code.
How to read it
- 01Look at the colour run. Many same-coloured candles in a row is a trend. The length of the run is the persistence.
- 02Look at the wicks. A strong up candle has almost no lower wick, a strong down candle has almost no upper one. Wicks on both sides with a small body means the market could not decide.
- 03Compare body sizes. Shrinking bodies along a run usually mean the trend is losing force before the colour changes.
- 04Hover a candle to see its smoothed open, high, low and close (and volume if you gave it). Remember these are averages, not trades.
When to use it, and when not to
Reach for it when
- You want to see the direction of a trend without the day-to-day noise: long runs of the same colour mean a persistent move.
- You want a visual cue for indecision: small bodies with long wicks on both sides are where the trend tends to stall.
- You already have OHLC data at a fixed period and want a smoother view of the same bars, with no change to the time axis.
- You are holding a position and want to know whether the move is still intact before looking at exact prices elsewhere.
Skip it when
- You need real prices: entries, stops, fills or profit calculations. The smoothed open and close are averages, not trades. Use Candlestick.
- The market gaps a lot. The smoothed open ignores the gap, so a large overnight move can look like it did not happen.
- You want to react quickly. The smoothing delays every signal, and in a sharp reversal you will be a bar or two behind.
- You want to filter by price size rather than time. Time still dictates the bars here, for size-based moves use Renko.
The math behind it
The recurrence
Let be the real open, high, low and close of period , and write the smoothed values with a bar. The new close is the average of the four real prices. The new open is the midpoint of the previous smoothed candle's body, which is where the memory comes from. The first candle has no predecessor, so its open is the midpoint of the real open and close.
Why it smooths
Because is an average of earlier smoothed values, it is an exponentially weighted memory of the past: each earlier candle contributes half as much as the one after it. That memory is the reason the body of one candle sits near the middle of the last one, so a sudden small reversal rarely flips the colour.
The cost is lag. A smoothed candle trails the real price, and by an amount that depends on how fast the market moved. It also means the highs and lows are clipped to include the smoothed body, so the wicks are never inside it.
What the chart draws
The transformed rows go to the same candle painter as the plain candlestick chart, so mode (candles, OHLC bars, volume) and candle_style work in the same way, and the volume series, if given, is not smoothed. A candle is up when its smoothed close is above its smoothed open. The up and down colours default to the theme's good and bad colours. The x axis is a time axis by default and tooltips show all values at the hovered period. The values shown in the tooltip are the smoothed ones.
Real life usage
The candle that stopped flinching
Gustavo traded the front-month crude future for a small proprietary firm, and was good at it in the unglamorous way: small positions, stops respected, a spreadsheet for everything. His one weakness, which he shared with most people who stare at charts for a living, was flinching.
On a five-minute candlestick chart, crude oil produced a red candle about as often as a green one, even in a sharp rally. Gustavo would see a red candle in the middle of an up-move, feel his stomach lurch, and exit. Then he would watch the price continue upward for another forty minutes. The firm's risk report had a column for this. It was called "premature exits" and it was kind.
What he wanted was not another indicator on top of the chart. He wanted the chart he already trusted, with the noise reduced, so that a pullback inside a trend would look like a pullback and not like an alarm.
He rebuilt the screen in a small desktop app with zopra-charts, putting <HeikinAshi> next to a plain <Candlestick> on the same feed. Same data, same period, one smoothed and one raw. He kept the raw one for entries, because that is where the real prices are, and used the smoothed one only to decide whether to stay in.
On the first rally he used it, the smoothed chart showed eleven green candles in a row, with tiny lower wicks, while the raw one showed seven greens and four reds. He stayed in. The move ran for 34 more minutes and added about 1.8 dollars a barrel.
Over the quarter his premature exits fell from 23 to 9, and the time he held winning trades rose by about a third. The red candles still appeared on the raw chart, as before. He simply stopped taking them personally.
The smoothed chart has one flaw, which is that it makes everything look obvious in hindsight. Gustavo has asked that nobody tell him this.
Pitfalls
- The prices are not real. The close of a smoothed candle is an average of four prices and may sit where nothing traded. Never read an entry or a stop off this axis.
- It lags by construction. Because each open depends on the previous candle, the colour change arrives after the real turn. Fast V-shaped reversals look especially late.
- The first candle is special. With no previous candle, the open is the midpoint of the real open and close. It takes a few candles for the chart to settle, so read the first handful with care.
- Gaps disappear. The smoothed open is built from the previous smoothed body, so a gap between sessions is not visible as one.
- Smoothing is not forecasting. A long green run says what happened, and gives no promise that it continues.
From around the web