TRIX With Moving Average - Didi's Needles setup
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hgrams

//@version=5
indicator("TRIX With Moving Average - Didi", "TRIX MA DIDI", format = format.price, timeframe = "",timeframe_gaps = true)

// Inputs
trixLen = input.int(9, title="TRIX Length", minval=1)
maLen = input.int(4, title="Moving Average", minval=1)
useEma = input.bool(false, title="Use Ema ?")
useFill = input.bool(true, title = "Fill ?")

// Inputs Colors
colTrix = input.color(color.new(#5b9bf5, 0), "TRIX Color", group = "Colors Settings", inline = "Color Settings")
colMa = input.color(color.new(#ffee58, 0), "MA Color", group = "Colors Settings", inline = "Color Settings")

// Calculations
trix = 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(close), trixLen), trixLen), trixLen))

ema = ta.ema(trix, maLen)
sma = ta.sma(trix, maLen)

ma = useEma ? ema : sma

// PLOTS
hline(0, color=#000000, title="Zero Line", display = display.none)

p1 = plot(trix, color = colTrix, title="TRIX")
p2 = plot(ma, "MA Trix", color = colMa)
plotshape(ta.cross(ma, trix) ? trix : na, title = "TRIX Cross MA", style = shape.cross, color = color.new(color.white, 10), location = location.absolute)

color fillColor = na
if useFill
    if ma
        fillColor := switch
            trix > ma => color.new(colTrix, 70)
            ma > trix => color.new(colMa, 70)

fill(p1, p2, color.new(fillColor, 70))
