Momentum Ribbon
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheRiskChair
// @version=5
indicator("Momentum Ribbon", overlay=true)

// Get MA Lengths
var g_length = "MA Length"
maLength1    = input.int(title="MA Length #1", defval=21, minval=1, step=10, group=g_length)
maLength2    = input.int(title="MA Length #2", defval=25, minval=0, step=10, group=g_length)
maLength3    = input.int(title="MA Length #3", defval=30, minval=0, step=10, group=g_length)
maLength4    = input.int(title="MA Length #4", defval=35, minval=0, step=10, group=g_length)
maLength5    = input.int(title="MA Length #5", defval=40, minval=0, step=10, group=g_length)
maLength6    = input.int(title="MA Length #5", defval=45, minval=0, step=10, group=g_length)
maLength7    = input.int(title="MA Length #5", defval=50, minval=0, step=10, group=g_length)
maLength8    = input.int(title="MA Length #5", defval=55, minval=0, step=10, group=g_length)
maLength9    = input.int(title="MA Length #5", defval=100, minval=0, step=10, group=g_length)

// Get MA Types
var g_type   = "MA Type"
maType1      = input.string(title="MA Type #1", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType2      = input.string(title="MA Type #2", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType3      = input.string(title="MA Type #3", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType4      = input.string(title="MA Type #4", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType5      = input.string(title="MA Type #5", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType6      = input.string(title="MA Type #5", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType7      = input.string(title="MA Type #5", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType8      = input.string(title="MA Type #5", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
maType9      = input.string(title="MA Type #5", defval="EMA", options=["EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)
allMaType    = input.string(title="ALL MA TYPE", defval="Disabled", options=["Disabled", "EMA", "SMA", "HMA", "WMA", "DEMA", "VWMA", "VWAP"], group=g_type)

// Get selected Moving Average
getMA(_maType, _maLength) =>
    if _maLength == 0
        na
    else
        switch allMaType == "Disabled" ? _maType : allMaType
            "SMA" => ta.sma(close, _maLength)
            "HMA" => ta.hma(close, _maLength)
            "WMA" => ta.wma(close, _maLength)
            "VWMA" => ta.vwma(close, _maLength)
            "VWAP" => ta.vwap
            "DEMA" =>
                e1 = ta.ema(close, _maLength)
                e2 = ta.ema(e1, _maLength)
                2 * e1 - e2
            => ta.ema(close, _maLength)

// Get MAs
ma1 = getMA(maType1, maLength1)
ma2 = getMA(maType2, maLength2)
ma3 = getMA(maType3, maLength3)
ma4 = getMA(maType4, maLength4)
ma5 = getMA(maType5, maLength5)
ma6 = getMA(maType6, maLength6)
ma7 = getMA(maType7, maLength7)
ma8 = getMA(maType8, maLength8)
ma9 = getMA(maType9, maLength9)

// Draw MAs
a=plot(ma1, color=close >= ma1 ? color.new(#1dfa00, 0) : color.new(#fa0000, 0), linewidth=1, title="MA #1")
plot(maLength2 == 0 ? na : ma2, color=close >= ma2 ? color.new(#00ffff, 20) : color.new(#fad900, 20), linewidth=1, title="MA #2")
plot(maLength3 == 0 ? na : ma3, color=close >= ma3 ? color.new(#00e8dc, 20) : color.new(#fac800, 20), linewidth=2, title="MA #3")
plot(maLength4 == 0 ? na : ma4, color=close >= ma4 ? color.new(#00d9bc, 20) : color.new(#e6a800, 20), linewidth=2, title="MA #4")
plot(maLength5 == 0 ? na : ma5, color=close >= ma5 ? color.new(#00bf99, 20) : color.new(#c96f00, 20), linewidth=2, title="MA #5")
plot(maLength6 == 0 ? na : ma6, color=close >= ma6 ? color.new(#00b078, 20) : color.new(#a33f00, 20), linewidth=3, title="MA #6")
plot(maLength7 == 0 ? na : ma7, color=close >= ma7 ? color.new(#009e52, 20) : color.new(#8f2501, 20), linewidth=3, title="MA #7")
b=plot(maLength8 == 0 ? na : ma8, color=close >= ma8 ? color.new(#006e02, 20) : color.new(#750800, 20), linewidth=4, title="MA #8")
c=plot(maLength9 == 0 ? na : ma9, color=close >= ma9 ? color.new(#005401, 30) : color.new(#750101, 30), linewidth=5, title="MA #9")

clookback = 5

spreadchange = ma1 - ma9
spreaddiff   = spreadchange - spreadchange[clookback]
spreadPct    = (spreaddiff / spreadchange) * 100 

fillColor = ma1 > ma9 ? (color.from_gradient(ma6, ma9, ma1, color.new(#36ff4a,60), color.new(#3363ff,85))) : ma1 < ma9 ? color.from_gradient(ma6, ma1, ma9, color.new(#3363ff,90), color.new(#fc0000,40)) : na
fill(a, c, fillColor)

 
