Line Break Heikin Ashi
// 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("Line Break Heikin Ashi", "LBHA", overlay = true)

green = input.color(color.new(#26a69a, 0), "Bullish Candle Color")
red   = input.color(color.new(#ef5350, 0), "Bearish Candle Color")

ha_close(float Open = open, float High = high, float Low = low, float Close = close, bool enable = true) =>
    ha_close = (Open + High + Low + Close) / 4
    out = enable == true ? ha_close : Close
 
ha_open(float Open = open, float High = high, float Low = low, float Close = close, bool enable = true) =>
    ha_open  = float(na)
    ha_close = ha_close(Open, High, Low, Close)
    ha_open := na(ha_open[1]) ? (Open + Close) / 2 : (nz(ha_open[1]) + nz(ha_close[1])) / 2 
    out = enable == true ? ha_open : Open

ha_high(float Open = open, float High = high, float Low = low, float Close = close, bool enable = true) =>
    ha_close = ha_close(Open, High, Low, Close)
    ha_open  = ha_open(Open, High, Low, Close)
    ha_high  = math.max(High, math.max(ha_open, ha_close))
    out = enable == true ? ha_high : High

ha_low(float Open = open, float High = high, float Low = low, float Close = close, bool enable = true) =>
    ha_close = ha_close(Open, High, Low, Close)
    ha_open  = ha_open(Open, High, Low, Close)
    ha_low = math.min(Low,  math.min(ha_open, ha_close))
    out = enable == true ? ha_low : Low

Open  = ha_open(close[1], ta.highest(close, 1), ta.lowest(close, 1), close)
High  = ha_high(close[1], ta.highest(close, 1), ta.lowest(close, 1), close)
Low   = ha_low(close[1], ta.highest(close, 1), ta.lowest(close, 1), close)
Close = ha_close(close[1], ta.highest(close, 1), ta.lowest(close, 1), close)

ha_score = Open < Close ? green : red

plotcandle(Open, High, Low, Close, "Test", ha_score, ha_score, true, bordercolor = ha_score)
