Classic Candlestick on Range Chart
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © GM_Trades

//@version=5
indicator(title = "Classic Candlestick on Range Chart", shorttitle = "Candlestick Overlay", overlay = true)

useHa = input.bool(defval = false,  title = "Use Heikin-Ashi Candlesticks")

f_HeikinAshi() =>
    float _closeRSI = close
    float _openRSI  = open
    float _highRSI_raw  = high
    float _lowRSI_raw   = low

    float _highRSI  = math.max( _highRSI_raw, _lowRSI_raw )
    float _lowRSI   = math.min( _highRSI_raw, _lowRSI_raw )

    float _close    = ( _openRSI + _highRSI + _lowRSI + _closeRSI ) / 4
    var float _open = na
    _open  := na( _open[ 1 ] ) ? ( _openRSI + _closeRSI ) / 2 :
              ( ( _open[1] * 1 ) + _close[1] ) / ( 1 + 1 )
    float _high     = math.max( _highRSI, math.max( _open, _close ) )
    float _low      = math.min( _lowRSI,  math.min( _open, _close ) )

    [ _open, _high, _low, _close ]

[ _open, _high, _low, _close ] = f_HeikinAshi()

open_value = useHa ?  _open : open
close_value = useHa ? _close : close
high_value = useHa ? _high : high
low_value = useHa ? _low : low

isBull = close_value > open_value
plotcandle(isBull ? open_value : na, isBull ? high_value : na, isBull ? low_value : na, isBull ? close_value : na, title='Bull Candle', color = color.new(#26a69a,0), wickcolor=color.new(#26a69a,0), bordercolor = color.new(#26a69a,30))
plotcandle(isBull ? na : open_value, isBull ? na : high_value, isBull ? na : low_value, isBull ? na : close_value, title='Bear Candle', color = color.new(#d32f2f,0), wickcolor=color.new(#d32f2f,0), bordercolor = color.new(#d32f2f,30))

