Heikin Ashi
All plugins

Plugin libraryChart types

Plugin

Heikin Ashi

Heikin Ashi candles for a strategy: HA open, high, low and close, the candle color, the run of same colored candles and a no opposite wick flag.

IndicatorNo networkDesktop onlyv1.0.0

About

Heikin Ashi smooths candles by averaging. This plugin computes the classic definition (Dan Valcu, Technical Analysis of Stocks & Commodities, 2004) bar by bar: HA close = (open + high + low + close) / 4; HA open = (previous HA open + previous HA close) / 2; HA high = max(high, HA open, HA close); HA low = min(low, HA open, HA close).

The first bar has no previous HA candle, so its HA open is seeded with (open + close) / 2 of that bar, the classic seed. Each later HA open halves the distance to the seed, so after ten bars the seed's share is below 0.1%. The seed is the first bar the indicator sees, so a run that starts on a different day shows slightly different first values.

The chart can already draw Heikin Ashi candles (Chart options); this plugin hands the same kind of values to a strategy. It has no parameters: pass {}.

Use it in a strategy

pythonha = ctx.plugin_indicator("heikin_ashi", "heikin_ashi", {})
if ha is not None and ha.value is not None:
    # Three rising candles in a row, the last without a lower wick.
    if ha.color == 1 and ha.run >= 3 and ha.no_opposite_wick:
        ctx.signal("LONG")
    elif ha.color == -1:
        ctx.signal("EXIT")

The indicator library has this as heikin_ashi: ctx.ind("heikin_ashi") reads the same candles, direction (the color here), run and no_opposite_wick, and the chart, Blocks, Rust and the Rust core have it too. This template stays as an example of a plugin indicator.

What it provides

valueValueThe HA close, the same as ha_close. None before the first bar.
ha_openValueThe HA open: the midpoint of the previous HA candle's body.
ha_highValueThe HA high: the highest of the bar's high, the HA open and the HA close.
ha_lowValueThe HA low: the lowest of the bar's low, the HA open and the HA close.
ha_closeValueThe HA close: the average of the bar's open, high, low and close.
colorValue1 when the HA close is above the HA open (rising), -1 when below (falling), 0 when they are equal.
runValueHow many candles in a row have this color, this one included. A candle with color 0 has a run of 0 and ends the run before it.
no_opposite_wickValueTrue for a rising candle without a lower wick or a falling candle without an upper wick, often read as a strong candle. False otherwise.

When values are known

Each value is final at the close of its bar and never changes when later bars arrive.

Limits

  • HA prices are averages, not prices that traded. Orders still fill at the real bid and ask, so a backtest that enters at the HA close would not match its fills.
  • The first values depend on the seed bar, the first bar the indicator sees: a run that starts on another day shows slightly different HA values for its first few bars.
  • A plugin indicator is not drawn on the chart and is not available in Blocks, Pine, Rust or C#; it runs on the run's own instrument only.
OrionQuant