Heikin-Ashi Candle Color
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("Heiken-Ashi Color", overlay = true)
candel_bool = input.bool(true, "Enable Heiken-Ashi Candle Color")

ha_close = candel_bool == true ? (open + high + low + close) / 4 : close
ha_open  = float(na) 
ha_open := candel_bool == true ? na(ha_open[1]) ? (open + close) / 2 : (nz(ha_open[1]) + nz(ha_close[1])) / 2 : open
ha_high  = candel_bool == true ? math.max(high, math.max(ha_open, ha_close)) : high
ha_low   = candel_bool == true ? math.min(low,  math.min(ha_open, ha_close)) : low
ha_color = candel_bool == true ? ha_close > ha_open ? color.new(#26a69a, 0) : color.new(#ef5350, 0) : close >= open ? color.new(#26a69a, 0) : color.new(#ef5350, 0) 

barcolor(ha_color)