Supertrend

Trend line at an ATR multiple that flips when price crosses it.

indicator("Supertrend", overlay=true)
atrPeriod = input.int(10, "ATR length", minval=1)
factor = input.float(3.0, "Factor", minval=0.01, step=0.1)
[st, dir] = ta.supertrend(factor, atrPeriod)
mid = plot((open + close) / 2, "Body middle", display=display.none)
up = plot(dir < 0 ? st : na, "Up trend", color=color.teal, linewidth=2)
down = plot(dir < 0 ? na : st, "Down trend", color=color.clay, linewidth=2)
fill(mid, up, color.new(color.teal, 90))
fill(mid, down, color.new(color.clay, 90))