Trend Ribbon on Heiken Ashi
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yosimadsu

//@version=5
indicator(title="Trend Ribbon on Heiken Ashi", shorttitle="Trend Ribbon", overlay=true, timeframe="", timeframe_gaps=false)
lenF = input.int(5, minval=1, title="Fast Length")
lenS = input.int(8, minval=1, title="Slow Length ")
useHA = input.bool(true, "Use Heiken Ashi")

OPEN = open
CLOSE = useHA ? (open + close + high + low) / 4 : close

outf = ta.sma(CLOSE, lenF)
outs = ta.sma(CLOSE, lenS)

a = plot(outf, color=na, title="Fast MA")
b = plot(outs, color=na, title="Slow MA")

col = outf < outs ? color.new(color.red, 70) : color.new(color.green, 70)
fill(a, b, col, "Trend Ribbon")

CLOSE := (open + close + high + low) / 4
OPEN := na(OPEN[1]) ? (OPEN + CLOSE) / 2: (OPEN[1] + CLOSE[1]) / 2
HIGH = math.max(high, math.max(OPEN, CLOSE))
LOW = math.min(low, math.min(OPEN, CLOSE))

c = (OPEN + HIGH + LOW + CLOSE) / 4
o = (OPEN[1] + CLOSE[1]) / 2
h = math.max(HIGH, math.max(o, c))
l = math.min(LOW, math.min(o, c))

plotcandle(o, h, l, c, "Heikin Ashi", color = o < c ? color.new(color.aqua, 60) : color.new(color.fuchsia, 60), bordercolor=na)