[_ParkF]HeikinAshi
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ParkF

//@version=5
indicator("[_ParkF]HeikinAshi", overlay=true)

// Input
ha_fill    = input.bool(true, 'Fill',                                     group='_____HeikinAshi')
Location   = input.float(1, 'Location', minval=1, step=0.1,               group='_____HeikinAshi')
bull_col   = input.color(color.new(#ffffff, 35), 'Bull', inline='CANDLE', group='_____HeikinAshi')
bear_col   = input.color(color.new(#9598a1, 35), 'Bear', inline='CANDLE', group='_____HeikinAshi')

// Get Heiken-Ashi
tickerid = syminfo.tickerid
tf       = timeframe.period
haOpen   = request.security(ticker.heikinashi(tickerid), tf, open  * Location)
haHigh   = request.security(ticker.heikinashi(tickerid), tf, high  * Location)
haLow    = request.security(ticker.heikinashi(tickerid), tf, low   * Location)
haClose  = request.security(ticker.heikinashi(tickerid), tf, close * Location)

// Color
trend_col = haClose > haOpen ? bull_col : bear_col

// Plot
plotcandle(haOpen, haHigh, haLow, haClose, title='Heikin-Ashi', color=trend_col, wickcolor=trend_col, bordercolor=trend_col, editable=false)
candleOpen  = plot(ha_fill ? haOpen  : na, title='OpenCandle' , color=haOpen < haClose ? bull_col : bear_col,                editable=false)
candleClose = plot(ha_fill ? haClose : na, title='CloseCandle', color=haOpen > haClose ? bull_col : bear_col,                editable=false)
fill(candleOpen, candleClose,                                   color=haOpen < haClose ? bull_col : bear_col,                editable=false)