Munich's Momentum Wave V2
// 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("Munich\'s Momentum Wave V2", 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' )
lf = input.int(415, 'Mean Look Back Length', 1, 500, group = 'Lookback periods')
len2 = input.int(25, minval=1, group = 'Background')
std = input.float(6, minval=0.001, maxval=50, title="StdDev", group = 'Background')
//Variable Declerations
m = ta.mom(src, len1)
a = ta.alma(close, 9, .85, 6) - (ta.alma(close, 9, .85, 6) - m)
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, 9)
ma6_ = ta.ema(m, 100)
ma7_ = ta.ema(m, 200)
ma8_ = ta.ema(m, 250)

basis1 = math.avg(ma2_, ma4_)
basis2 = math.avg(ma2_, ma3_)
basis3 = math.avg(ma3_, ma6_)
basis4 = math.avg(ma6_, ma7_)
basis5 = math.avg(ma7_, ma8_)

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

m_a = math.avg(m, a)
pivh = ta.pivothigh(m_a, lb, rb)
pivl = ta.pivotlow(m_a, lb, rb)

bAVG = math.avg(basis1, m)
bAVG2 = math.avg(basis1, basis2, basis3, basis4, basis5)
origin_ = ta.sma(bAVG2, len2)
deviation = std * ta.stdev(bAVG2, len2)

fallin(basis) =>
    m <= basis and m <= a

growin(basis) =>
    m > basis 


    
    //Double Declared for fill function >>>

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

ma5_ = math.avg(highm1, lowm1)


//Munichs Moving Average Series         //Munichs Moving Average Series             //Munichs Moving Average Series             //Munichs Moving Average Series             //Munichs Moving Average Series         //Munichs Moving Average Series         //Munichs Moving Average Series
topband = origin_ + deviation
bottomband = origin_ - deviation
banddiff = topband - bottomband
//Plot Excecutions
bgcolor(basis1 > topband and a > topband and a > a[3] ? color.new(color.red, 85):(basis1 < bottomband and a < bottomband and a < a[3] ? color.new(color.green, 85):na), off)
plot(basis1, 'Munich\ Momentum 1', growin(basis1)   ? color.aqua:(fallin(basis1)  ? color.yellow:color.white) , 4, plot.style_line, offset = 0, editable = false)
plot(basis2, 'Munich\ Momentum 2', growin(basis2)   ? color.aqua:(fallin(basis2)   ? color.yellow:color.white) , 4, plot.style_line, offset = 0, editable = false)
plot(basis3, 'Munich\ Momentum 3', growin(basis3)   ? color.aqua:(fallin(basis3)   ? color.yellow:color.white) , 4, plot.style_line, offset = 0, editable = false)
plot(basis4, 'Munich\ Momentum 3', growin(basis4)   ? color.aqua:(fallin(basis4)   ? color.yellow:color.white) , 4, plot.style_line, offset = 0, editable = false)
plot(basis5, 'Munich\ Momentum 3', growin(basis5)   ? color.aqua:(fallin(basis5)   ? color.yellow:color.white) , 4, plot.style_line, offset = 0, editable = false)
plot(a, 'Alma', a > ma5_ and growin(basis5) ? color.green:( basis5 > a and fallin(a) ? color.red:color.white), 2, plot.style_line )


//Alert Conditions
inp1 = input.bool(true, 'Alerts?', confirm = true, group = 'Alerts', inline = '1')
inp2 = input.bool(false, 'Lean Short', group = 'Alerts', inline = '2')
inp3 = input.bool(true, 'Maybe Buy', group = 'Alerts', inline = '2')
inp4 = input.bool(false, 'Lean Long', group = 'Alerts', inline = '2')
inp5 = input.bool(true, 'Maybe Sell', group = 'Alerts', inline = '2')
inp6 = input.bool(false, 'All Yellow', group = 'Alerts', inline = '3')
inp7 = input.bool(false, 'All Aqua', group = 'Alerts', inline = '3')
C1 = ta.crossunder(basis1[1], basis5[1])
C2 = a <= basis1 and a <= basis2 and a <= basis3 and a <= basis4 and a <= basis5
C3 = basis1 > topband and a > topband and a > a[3]
C4 = basis1 < bottomband and a < bottomband and a < a[3] 
C5 = ta.crossover(basis1[1], basis5[1])
C6 = basis1[1] - basis5[1] 
C7 = a >= basis1 and a >= basis2 and a >= basis3 and a >= basis4 and a >= basis5

A1 = C1 and C2 and C6 <= -10 and inp1 and inp2
A2 = C1 and C2 and C4 and C6 <= -20 and inp1 and inp3
A3 = C5 and C7 and C6 >= 10 and inp1 and inp4
A4 = C5 and C7 and C6 >= 20 and C3 and inp1 and inp5
A5 = growin(basis5) and growin(basis1)[1] and growin(basis2)[1] and growin(basis3)[1] and growin(basis4)[1] and growin(basis5)[1] and growin(basis1)[2] and growin(basis2)[2] and growin(basis3)[2] and growin(basis4)[2] and growin(basis5)[2] and growin(basis1)[3] and growin(basis2)[3] and growin(basis3)[3] and growin(basis4)[3] and growin(basis5)[3] and inp7
A6 = fallin(basis5) and fallin(basis1)[1] and fallin(basis2)[1] and fallin(basis3)[1] and fallin(basis4)[1] and fallin(basis5)[1] and fallin(basis1)[2] and fallin(basis2)[2] and fallin(basis3)[2] and fallin(basis4)[2] and fallin(basis5)[2] and fallin(basis1)[3] and fallin(basis2)[3] and fallin(basis3)[3] and fallin(basis4)[3] and fallin(basis5)[3] and inp6
//HLine Strategy
plot(0, 'Munich/s Wave State', color = growin(basis1) and growin(basis2) and growin(basis3) and growin(basis4) and growin(basis5) ? color.aqua : fallin(basis1) and fallin(basis2) and fallin(basis3) and fallin(basis4) and fallin(basis5) ? color.yellow : color.white, linewidth = 2)
//Alerts
alertcondition(A5, 'MMW V2 Alert 5', 'ALL BULLS (Aqua)')
alertcondition(A6, 'MMW V2 Alert 6', 'ALL BEARS(Yellow)')
alertcondition(A1, 'MMW V2 Alert 1', 'Bears In Control (Lean Short)')
alertcondition(A2, 'MMW V2 Alert 2', 'Oversold! (Maybe Buy)')
alertcondition(A3, 'MMW V2 Alert 3', 'Bulls in Control (Lean Long)')
alertcondition(A4, 'MMW V2 Alert 4', 'Overbought! (Maybe Sell)')


