Docs

ITMScript

Compute a Heikin-Ashi open

Compute the Heikin-Ashi open, which depends on the bar before it, with scan, and draw it with the close, high and low.

Compute the Heikin-Ashi open, which is the average of the open and close of the bar before it, with scan.

itm
//@itmscript 2
study("Heikin-Ashi open", overlay=true)
upColor = input.color(color.green, "Up body")
downColor = input.color(color.red, "Down body")
haClose = ohlc4
smooth(acc, x) => (nz(acc, x) + x) / 2
haOpen = scan(haClose[1], na, smooth)
haHigh = math.max(high, math.max(haOpen, haClose))
haLow = math.min(low, math.min(haOpen, haClose))
plot(haOpen, "HA open", color=haClose > haOpen ? upColor : downColor, width=2, style=line)
plot(haClose, "HA close", color=color.gray, width=1, style=line)
plot(haHigh, "HA high", color=color.gray, width=1, style=circles)
plot(haLow, "HA low", color=color.gray, width=1, style=circles)

What you see

Four lines are drawn over the candles. The HA open is thick. It is green when the Heikin-Ashi close is above it and red when the close is below it. The HA close is a thin grey line. The HA high and low are grey dots.

scan carries a value from one bar to the next. The function smooth receives the carried value as acc and the new input as x, and returns the next carried value. The first bar has no previous close, so the HA open starts on the second bar. Carried state shows the other uses of scan.

Change these inputs

  • Up body. The colour of the HA open while the HA close is above it.
  • Down body. The colour of the HA open while the HA close is not above it.