MA Trend Bar [vnhilton]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vnhilton

//@version=5
indicator("MA Trend Bar [vnhilton]", "MA Trend Bar", false, timeframe="", timeframe_gaps=true)

//Moving Average Configuration
src = input(close, title="Source")

shortLen = input.int(9, "Short MA Length", 1)
longLen = input.int(21, "Long MA Length", 2)

maType = input.string("EMA", "MA Type", ["ALMA", "EMA", "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"])

//Moving Average Selection
ma(src, len, type) =>
    switch type
        "EMA" => ta.ema(src, len)
        "HMA" => ta.hma(src, len)
        "RMA" => ta.rma(src, len)
        "SMA" => ta.sma(src, len)
        "VWMA" => ta.vwma(src, len)
        "WMA" => ta.wma(src, len)

//Moving Average Assignments
shortMA = ma(src, shortLen, maType)
longMA = ma(src, longLen, maType)

//Trend Color Based On Short Term Moving Average Relative to Longer Term Moving Average
trendColor = shortMA >= longMA ? color.rgb(0, 165, 49, 0) : color.rgb(255, 109, 90, 0)

plot(1, "MA Trend Bar", trendColor, 10, plot.style_line, histbase=0)