User Selectable Moving Average Guppy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Credit: LucF from PineCoders for the Gradient Coloring function, see Color Gradient Framework tutorial
//@version=5
indicator(title='User Selectable Moving Average Guppy', shorttitle='User Selectable MA Guppy', overlay=true, timeframe="", timeframe_gaps=true)
lsmaoffset = input.int(title='LEAST SQUARES (LSMA) ONLY - LS Offset', defval=0, inline='3')
almaoffset = input.float(title='ALMA Offset', defval=0.85, step=0.01, inline='4')
almasigma = input.float(title='ALMA Sigma', defval=6, inline='4')
a1 = input.float(title='Tillson T3 Volume Factor', defval=0.7, inline='5', step=0.001)

f_ehma(_source, _length) =>
    _return = ta.ema(2 * ta.ema(_source, _length / 2) - ta.ema(_source, _length), math.round(math.sqrt(_length)))
    _return

f_tema(_source, _length) =>
    _out = 3 * (ta.ema(_source, _length) - ta.ema(ta.ema(_source, _length), _length)) + ta.ema(ta.ema(ta.ema(_source, _length), _length), _length)
    _out

f_t3(_source, _length, _a1) =>
    _output = (-_a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length), _length), _length)) + (3 * _a1 * _a1 + 3 * _a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length), _length)) + (-6 * _a1 * _a1 - 3 * _a1 - 3 * _a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length)) + (1 + 3 * _a1 + _a1 * _a1 * _a1 + 3 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(_source, _length), _length), _length))
    _output

MA(source, length, type) =>
     type == 'SMA' ? ta.sma(source, length) : 
     type == 'EMA' ? ta.ema(source, length) : 
     type == 'SMMA (RMA)' ? ta.rma(source, length) : 
     type == 'WMA' ? ta.wma(source, length) : 
     type == 'VWMA' ? ta.vwma(source, length) : 
     type == 'HMA' ? ta.hma(source, length) : 
     type == 'EHMA' ? f_ehma(source, length) : 
     type == 'TEMA' ? f_tema(source, length) : 
     type == 'ALMA' ? ta.alma(source, length, almaoffset, almasigma) : 
     type == 'Tillson T3' ? f_t3(source, length, a1) : 
     type == 'LSMA' ? ta.linreg(source, length, lsmaoffset) : na

//COLOR INPUTS
color ltfbullma = input.color(color.new(color.aqua, 50), 'Lower TF', inline='6')
color ltfbearma = input.color(color.new(color.orange, 50), 'Lower TF', inline='6')
color bullma = input.color(color.new(color.aqua, 75), 'HTF', inline='6')
color bearma = input.color(color.new(color.orange, 75), 'HTF', inline='6')

//GRADIENT
showlabels = input.bool(title='Label HTF Crosses?', defval=false, inline='49')
colorgrad = input.bool(defval=true, title='Fill HTF Gradient?', inline='49')
color bullfill = input.color(color.aqua, '', inline='49')
color bearfill = input.color(color.orange, '', inline='49')
gradmult = input.float(0.25, title='Gradient \'Intensity\' (Higher = more intense)', step=0.01, inline='52')
gradconst = input.int(1, title='Gradient Constant (Higher = less intense)', minval=-100, maxval=100, inline='53')
gradlimit = input.int(99, title='Gradient Transparency Limit', minval=0, maxval=100, inline='54')

// —————————————————————————————————————————
// ————— Advance/Decline Gradient (Credit: LucF from PineCoders)
// ————————————————————————————————————————— 
// ————— Function returning one of the bull/bear colors in a transparency proportional to the current qty of advances/declines 
//       relative to the historical max qty of adv/dec for this `_source`.

f_c_gradientAdvDec(_source, _center, _c_bear, _c_bull) =>
    // float _source: input signal.
    // float _center: centerline used to determine if signal is bull/bear.
    // color _c_bear: most bearish color.
    // color _c_bull: most bullish color.
    // Dependency: `f_colorNew()`
    var float _maxAdvDec = 0.
    var float _qtyAdvDec = 0.
    bool _xUp = ta.crossover(_source, _center)
    bool _xDn = ta.crossunder(_source, _center)
    float _chg = ta.change(_source)
    bool _up = _chg > 0
    bool _dn = _chg < 0
    bool _srcBull = _source > _center
    bool _srcBear = _source < _center
    _qtyAdvDec := _srcBull ? _xUp ? 1 : _up ? _qtyAdvDec + 1 : _dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _srcBear ? _xDn ? 1 : _dn ? _qtyAdvDec + 1 : _up ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _qtyAdvDec
    // Keep track of max qty of advances/declines.
    _maxAdvDec := math.max(_maxAdvDec, _qtyAdvDec)
    // Calculate transparency from the current qty of advances/declines relative to the historical max qty of adv/dec for this `_source`.
    float _transp = 100 - _qtyAdvDec * 100 / _maxAdvDec * gradmult + gradconst
    _transp2 = _transp > gradlimit ? gradlimit : _transp
    var color _return = na
    _return := _srcBull ? color.new(_c_bull, _transp2) : _srcBear ? color.new(_c_bear, _transp2) : _return
    _return

//KEY MA
show_MA22 = input.bool(true, 'MA №22', inline='MA #22', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22_type = input.string('HMA', '', inline='MA #22', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22_source = input.source(close, '', inline='MA #22', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22_length = input.int(55, '', inline='MA #22', minval=1, group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22 = MA(MA22_source, MA22_length, MA22_type)

show_MA23 = input.bool(true, 'MA №23', inline='MA #23', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23_type = input.string('HMA', '', inline='MA #23', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23_source = input.source(close, '', inline='MA #23', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23_length = input.int(200, '', inline='MA #23', minval=1, group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23 = MA(MA23_source, MA23_length, MA23_type)

//FAST    
show_MA1 = input.bool(true, 'MA №1', inline='MA #1', group='Multiple Moving Average Guppy Ribbon')
MA1_type = input.string('HMA', '', inline='MA #1', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA1_source = input.source(close, '', inline='MA #1', group='Multiple Moving Average Guppy Ribbon')
MA1_length = input.int(3, '', inline='MA #1', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA1 = MA(MA1_source, MA1_length, MA1_type)

show_MA2 = input.bool(true, 'MA №2', inline='MA #2', group='Multiple Moving Average Guppy Ribbon')
MA2_type = input.string('HMA', '', inline='MA #2', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA2_source = input.source(close, '', inline='MA #2', group='Multiple Moving Average Guppy Ribbon')
MA2_length = input.int(5, '', inline='MA #2', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA2 = MA(MA2_source, MA2_length, MA2_type)

show_MA3 = input.bool(true, 'MA №3', inline='MA #3', group='Multiple Moving Average Guppy Ribbon')
MA3_type = input.string('HMA', '', inline='MA #3', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA3_source = input.source(close, '', inline='MA #3', group='Multiple Moving Average Guppy Ribbon')
MA3_length = input.int(9, '', inline='MA #3', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA3 = MA(MA3_source, MA3_length, MA3_type)

show_MA4 = input.bool(true, 'MA №4', inline='MA #4', group='Multiple Moving Average Guppy Ribbon')
MA4_type = input.string('HMA', '', inline='MA #4', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA4_source = input.source(close, '', inline='MA #4', group='Multiple Moving Average Guppy Ribbon')
MA4_length = input.int(12, '', inline='MA #4', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA4 = MA(MA4_source, MA4_length, MA4_type)

show_MA5 = input.bool(true, 'MA №5', inline='MA #5', group='Multiple Moving Average Guppy Ribbon')
MA5_type = input.string('HMA', '', inline='MA #5', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA5_source = input.source(close, '', inline='MA #5', group='Multiple Moving Average Guppy Ribbon')
MA5_length = input.int(15, '', inline='MA #5', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA5 = MA(MA5_source, MA5_length, MA5_type)

show_MA6 = input.bool(true, 'MA №6', inline='MA #6', group='Multiple Moving Average Guppy Ribbon')
MA6_type = input.string('HMA', '', inline='MA #6', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA6_source = input.source(close, '', inline='MA #6', group='Multiple Moving Average Guppy Ribbon')
MA6_length = input.int(18, '', inline='MA #6', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA6 = MA(MA6_source, MA6_length, MA6_type)

show_MA7 = input.bool(true, 'MA №7', inline='MA #7', group='Multiple Moving Average Guppy Ribbon')
MA7_type = input.string('HMA', '', inline='MA #7', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA7_source = input.source(close, '', inline='MA #7', group='Multiple Moving Average Guppy Ribbon')
MA7_length = input.int(21, '', inline='MA #7', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA7 = MA(MA7_source, MA7_length, MA7_type)

//SLOW
show_MA8 = input.bool(true, 'MA №8', inline='MA #8', group='Multiple Moving Average Guppy Ribbon')
MA8_type = input.string('HMA', '', inline='MA #8', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA8_source = input.source(close, '', inline='MA #8', group='Multiple Moving Average Guppy Ribbon')
MA8_length = input.int(24, '', inline='MA #8', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA8 = MA(MA8_source, MA8_length, MA8_type)

show_MA9 = input.bool(true, 'MA №9', inline='MA #9', group='Multiple Moving Average Guppy Ribbon')
MA9_type = input.string('HMA', '', inline='MA #9', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA9_source = input.source(close, '', inline='MA #9', group='Multiple Moving Average Guppy Ribbon')
MA9_length = input.int(26, '', inline='MA #9', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA9 = MA(MA9_source, MA9_length, MA9_type)

show_MA10 = input.bool(true, 'MA №10', inline='MA #10', group='Multiple Moving Average Guppy Ribbon')
MA10_type = input.string('HMA', '', inline='MA #10', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA10_source = input.source(close, '', inline='MA #10', group='Multiple Moving Average Guppy Ribbon')
MA10_length = input.int(28, '', inline='MA #10', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA10 = MA(MA10_source, MA10_length, MA10_type)

show_MA11 = input.bool(true, 'MA №11', inline='MA #11', group='Multiple Moving Average Guppy Ribbon')
MA11_type = input.string('HMA', '', inline='MA #11', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA11_source = input.source(close, '', inline='MA #11', group='Multiple Moving Average Guppy Ribbon')
MA11_length = input.int(30, '', inline='MA #11', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA11 = MA(MA11_source, MA11_length, MA11_type)

show_MA12 = input.bool(true, 'MA №12', inline='MA #12', group='Multiple Moving Average Guppy Ribbon')
MA12_type = input.string('HMA', '', inline='MA #12', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA12_source = input.source(close, '', inline='MA #12', group='Multiple Moving Average Guppy Ribbon')
MA12_length = input.int(32, '', inline='MA #12', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA12 = MA(MA12_source, MA12_length, MA12_type)

show_MA13 = input.bool(true, 'MA №13', inline='MA #13', group='Multiple Moving Average Guppy Ribbon')
MA13_type = input.string('HMA', '', inline='MA #13', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA13_source = input.source(close, '', inline='MA #13', group='Multiple Moving Average Guppy Ribbon')
MA13_length = input.int(34, '', inline='MA #13', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA13 = MA(MA13_source, MA13_length, MA13_type)

show_MA14 = input.bool(true, 'MA №14', inline='MA #14', group='Multiple Moving Average Guppy Ribbon')
MA14_type = input.string('HMA', '', inline='MA #14', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA14_source = input.source(close, '', inline='MA #14', group='Multiple Moving Average Guppy Ribbon')
MA14_length = input.int(36, '', inline='MA #14', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA14 = MA(MA14_source, MA14_length, MA14_type)

show_MA15 = input.bool(true, 'MA №15', inline='MA #15', group='Multiple Moving Average Guppy Ribbon')
MA15_type = input.string('HMA', '', inline='MA #15', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA15_source = input.source(close, '', inline='MA #15', group='Multiple Moving Average Guppy Ribbon')
MA15_length = input.int(38, '', inline='MA #15', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA15 = MA(MA15_source, MA15_length, MA15_type)

show_MA16 = input.bool(true, 'MA №16', inline='MA #16', group='Multiple Moving Average Guppy Ribbon')
MA16_type = input.string('HMA', '', inline='MA #16', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA16_source = input.source(close, '', inline='MA #16', group='Multiple Moving Average Guppy Ribbon')
MA16_length = input.int(40, '', inline='MA #16', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA16 = MA(MA16_source, MA16_length, MA16_type)

show_MA17 = input.bool(true, 'MA №17', inline='MA #17', group='Multiple Moving Average Guppy Ribbon')
MA17_type = input.string('HMA', '', inline='MA #17', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA17_source = input.source(close, '', inline='MA #17', group='Multiple Moving Average Guppy Ribbon')
MA17_length = input.int(42, '', inline='MA #17', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA17 = MA(MA17_source, MA17_length, MA17_type)

show_MA18 = input.bool(true, 'MA №18', inline='MA #18', group='Multiple Moving Average Guppy Ribbon')
MA18_type = input.string('HMA', '', inline='MA #18', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA18_source = input.source(close, '', inline='MA #18', group='Multiple Moving Average Guppy Ribbon')
MA18_length = input.int(44, '', inline='MA #18', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA18 = MA(MA18_source, MA18_length, MA18_type)

show_MA19 = input.bool(true, 'MA №19', inline='MA #19', group='Multiple Moving Average Guppy Ribbon')
MA19_type = input.string('HMA', '', inline='MA #19', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA19_source = input.source(close, '', inline='MA #19', group='Multiple Moving Average Guppy Ribbon')
MA19_length = input.int(46, '', inline='MA #19', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA19 = MA(MA19_source, MA19_length, MA19_type)

show_MA20 = input.bool(true, 'MA №20', inline='MA #20', group='Multiple Moving Average Guppy Ribbon')
MA20_type = input.string('HMA', '', inline='MA #20', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA20_source = input.source(close, '', inline='MA #20', group='Multiple Moving Average Guppy Ribbon')
MA20_length = input.int(48, '', inline='MA #20', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA20 = MA(MA20_source, MA20_length, MA20_type)

show_MA21 = input.bool(true, 'MA №21', inline='MA #21', group='Multiple Moving Average Guppy Ribbon')
MA21_type = input.string('HMA', '', inline='MA #21', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA21_source = input.source(close, '', inline='MA #21', group='Multiple Moving Average Guppy Ribbon')
MA21_length = input.int(50, '', inline='MA #21', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA21 = MA(MA21_source, MA21_length, MA21_type)

//PLOTS
basecolorfast = MA23 > MA22 ? bearma : bullma
basecolorslow = MA23 > MA22 ? bearma : bullma
color c_1 = f_c_gradientAdvDec(MA22, MA23, bearfill, bullfill)

//Fast MA Plots
p1 = plot(show_MA1 ? MA1 : na, title='Fast MA 1', linewidth=1, color=MA1 > MA1[1] ? ltfbullma : ltfbearma)
p2 = plot(show_MA2 ? MA2 : na, title='Fast MA 2', linewidth=1, color=MA2 > MA2[1] ? ltfbullma : ltfbearma)
p3 = plot(show_MA3 ? MA3 : na, title='Fast MA 3', linewidth=1, color=MA3 > MA3[1] ? ltfbullma : ltfbearma)
p4 = plot(show_MA4 ? MA4 : na, title='Fast MA 4', linewidth=1, color=MA4 > MA4[1] ? ltfbullma : ltfbearma)
p5 = plot(show_MA5 ? MA5 : na, title='Fast MA 5', linewidth=1, color=MA5 > MA5[1] ? ltfbullma : ltfbearma)
p6 = plot(show_MA6 ? MA6 : na, title='Fast MA 6', linewidth=1, color=MA6 > MA6[1] ? ltfbullma : ltfbearma)
p7 = plot(show_MA7 ? MA7 : na, title='Fast MA 7', linewidth=1, color=MA7 > MA7[1] ? ltfbullma : ltfbearma)

//Slow MA Plots
p8 = plot(show_MA8 ? MA8 : na, title='Slow MA 8', linewidth=1, color=MA8 > MA8[1] ? ltfbullma : ltfbearma)
p9 = plot(show_MA9 ? MA9 : na, title='Slow MA 9', linewidth=1, color=MA9 > MA9[1] ? ltfbullma : ltfbearma)
p10 = plot(show_MA10 ? MA10 : na, title='Slow MA 10', linewidth=1, color=MA10 > MA10[1] ? ltfbullma : ltfbearma)
p11 = plot(show_MA11 ? MA11 : na, title='Slow MA 11', linewidth=1, color=MA11 > MA11[1] ? ltfbullma : ltfbearma)
p12 = plot(show_MA12 ? MA12 : na, title='Slow MA 12', linewidth=1, color=MA12 > MA12[1] ? ltfbullma : ltfbearma)
p13 = plot(show_MA13 ? MA13 : na, title='Slow MA 13', linewidth=1, color=MA13 > MA13[1] ? ltfbullma : ltfbearma)
p14 = plot(show_MA14 ? MA14 : na, title='Slow MA 14', linewidth=1, color=MA14 > MA14[1] ? ltfbullma : ltfbearma)
p15 = plot(show_MA15 ? MA15 : na, title='Slow MA 15', linewidth=1, color=MA15 > MA15[1] ? ltfbullma : ltfbearma)
p16 = plot(show_MA16 ? MA16 : na, title='Slow MA 16', linewidth=1, color=MA16 > MA16[1] ? ltfbullma : ltfbearma)
p17 = plot(show_MA17 ? MA17 : na, title='Slow MA 17', linewidth=1, color=MA17 > MA17[1] ? ltfbullma : ltfbearma)
p18 = plot(show_MA18 ? MA18 : na, title='Slow MA 18', linewidth=1, color=MA18 > MA18[1] ? ltfbullma : ltfbearma)
p19 = plot(show_MA19 ? MA19 : na, title='Slow MA 19', linewidth=1, color=MA19 > MA19[1] ? ltfbullma : ltfbearma)
p20 = plot(show_MA20 ? MA20 : na, title='Slow MA 20', linewidth=1, color=MA20 > MA20[1] ? ltfbullma : ltfbearma)
p21 = plot(show_MA21 ? MA21 : na, title='Slow MA 21', linewidth=1, color=MA21 > MA21[1] ? ltfbullma : ltfbearma)

//HTF KEY MA Plots
p22 = plot(show_MA22 ? MA22 : na, title='Slow MA 22', linewidth=2, color=basecolorfast)
p23 = plot(show_MA23 ? MA23 : na, title='Slow MA 23', linewidth=2, color=basecolorslow)
fill(p22, p23, colorgrad == true ? c_1 : color.new(color.white, 100), title='Adv/Dec MA fill')

//ALERTS
plotshape(showlabels and ta.crossover(MA22, MA23), title='Cross Long', style=shape.labelup, location=location.belowbar, text='LONG', textcolor=color.new(color.white, 0), color=color.new(color.teal, 0), size=size.small)
plotshape(showlabels and ta.crossunder(MA22, MA23), title='Cross Short', style=shape.labeldown, location=location.abovebar, text='SHORT', textcolor=color.new(color.white, 0), color=color.new(color.maroon, 0), size=size.small)
alertcondition(ta.crossover(MA22, MA23), 'HTF Bullish Cross', 'HTF Bullish Cross')
alertcondition(ta.crossunder(MA22, MA23), 'HTF Bearish Cross', 'HTF Bearish Cross')