Seth's MW
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CheatCode1

//@version=5
indicator("Seth\'s Momentum Wave", overlay = false)

// Input value groupings

src = input.source(close, 'Momentum Source', group = 'Momentum Values')
len1 = input.int(21, 'Momentum Length', 1, 500, group = 'Momentum Values')
lb = input.int(50, 'Lookback Left', 1, 500, group = 'Lookback periods')
rb = input.int(7, 'Lookback Right', 1, 500, group = 'Lookback periods')
off = input.int(0, ' Offset length', -100, 100, group = 'Background Color' )
lf = input.int(415, 'Mean Look Back Length', 1, 500, group = 'Lookback periods')

//Variable Declerations

m = ta.mom(src, len1)
m_col1 = ta.rising(m, 2)
m_col2 = ta.falling(m, 2)

ma2_ = ta.ema(m, 21)
ma3_ = ta.ema(m, 55)
ma4_ = ta.ema(m, 200)


fall1 = ta.falling(m, 2) ? true:false
grow1 = ta.rising(m, 2) ? true:false

basis1 = math.avg(ma2_, ma3_)

b1A = ta.falling(m, 2)
b1_col = ta.rising(m, 2) ? color.green : b1A ? color.red:color.white

m_std = ta.stdev(m, len1)

pivh = ta.pivothigh(basis1, lb, rb)
pivl = ta.pivotlow(basis1, lb, rb)

val1 = ta.valuewhen(pivh, m, 1 )
val0 = ta.valuewhen(pivh, m, 0 )
valn1 = ta.valuewhen(pivl, m, 1)
valn0 = ta.valuewhen(pivl, m, 0)

bAVG = math.avg(basis1, m)
    
    //Double Declared for fill function >>>

highm1 = ta.highest(bAVG, lf)
lowm1 = ta.lowest(bAVG, lf)

ma5_ = math.avg(highm1, lowm1)

highm = plot(highm1, '', #73E600, 1, plot.style_line, display = display.none, editable = false)
lowm = plot(lowm1, '', #E66763, 1, plot.style_line, display = display.none, editable = false)

b2_col = basis1 >= ma5_ ? color.new(color.green, 95):(basis1 <= ma5_ ? color.new(color.red, 95):color.new(color.white, 100))

//Seths Moving Average Series         //Seths Moving Average Series             //Seths Moving Average Series             //Seths Moving Average Series             //Seths Moving Average Series         //Seths Moving Average Series         //Seths Moving Average Series

maCol(maX, maL, m, src, len1) =>
    m == ta.mom(src, len1)
    diff_ = ta.change(maX)
    macol = diff_ >= 0 and maX > maL and maX <= m ? color.new(#6AE635, 25): (diff_ < 0 and maX > maL and maX >= m ? color.new(#A80E00, 25): (diff_ <= 0 and maX < maL and maX >= m ? color.new(#E15C58, 25): (diff_ >= 0 and maX < maL and m >= maX ? color.new(color.green, 0) : color.new(color.white, 100))))
    macol

maL = ta.ema(m, 100)
  
    //Double Declared for fill Function

ma2 = plot(ma2_, 'MA2', maCol(ma2_, maL, m, src, len1), 2, plot.style_line, editable = false)
ma3 = plot(ma3_, 'MA3', maCol(ma3_, maL, m, src, len1), 2, plot.style_line, editable = false)

//Plot Excecutions

plot(maL, 'maL', maL >= m ? color.red: maL <= m ? color.green:na, 4, plot.style_line, editable = false) 
plot(basis1, 'Seth\ Momentum', m >= basis1 and not fall1 ? color.aqua:(m < basis1 and not grow1 ? color.yellow:color.white) , 4, plot.style_circles, offset = -3)
fill(ma2, ma3, color.new(color.yellow, 88), '')
bgcolor(b2_col, off, false, title = 'Background Color')
plot(ma5_, 'Mean Length', basis1 >= m ? color.red: color.green, 2)