SuperTrend candles
SuperTrend as two lines that break at each flip, candles coloured by the trend, a marker on every flip, and a label with how long the trend has run.
//@xfscript 1
indicator("SuperTrend Candles")
let factor: float = input.float(3, "factor", "Factor", 0.5, 10, 0.1)
let atr_length: int = input.int(10, "atrLength", "ATR length", 1, 200, 1)
let up_color: color = input.color("#22C55E", "upColor", "Up trend")
let down_color: color = input.color("#EF4444", "downColor", "Down trend")
let trail: float = ta.supertrend(factor, atr_length)
let direction: float = ta.supertrend_dir(factor, atr_length)
let ready: bool = !is_nan(direction)
let up: bool = direction == -1
let tone: color = up ? up_color : down_color
let flipped: bool = ready && bar_index > 0 && direction != direction[1] && !is_nan(direction[1])
plot.line(up ? trail : nan, up_color, 2, "solid")
plot.line(ready && !up ? trail : nan, down_color, 2, "solid")
plot.candle_color(ready, tone, 0.85)
plot.marker(flipped && up, low, up_color, "triangle", "below", 10, 3)
plot.marker(flipped && !up, high, down_color, "triangle", "above", 10, 3)
let since: float = ta.barssince(flipped)
plot.label(str.concat(up ? "UP TREND " : "DOWN TREND ", format.fixed(nz(since, 0), 0), " BARS"), tone)