TTM Waves ABC ATR AO MOM SQZ
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//All code picked from many indicators, if you recognize your code, pls comment so people can see your awesome work! I only edited and added them all together. Hope this indicator helps as many people as it can.

//@version=5
indicator("TTM Waves ABC ATR AO MOM SQZ")

showA = input.bool(true,"Show TTM Wave A")
showB = input.bool(false,"Show TTM Wave B")
showC = input.bool(false,"Show TTM Wave C")

// C
float ttmwcmacd = na
float ttmwcf = na
if showC
    [Cmacd,_,CSlowHist] = ta.macd(close,8,377,377)
    ttmwcmacd := Cmacd
    [_,_,CFastHist] = ta.macd(close,8,233,233)
    ttmwcf := CFastHist
plot(ttmwcmacd,style=plot.style_histogram,title="TTM wave C Macd",color=#296a22,linewidth=3)
plot(ttmwcf,style=plot.style_histogram,title="TTM wave C Fast",color=#f3701c,linewidth=3)

// B
float ttmwbs = na
float ttmwbf = na
if showB
    [_,_,BSlowHist] = ta.macd(close,8,144,144)
    ttmwbs := BSlowHist
    [_,_,BFastHist] = ta.macd(close,8,89,89)
    ttmwbf := BFastHist
plot(ttmwbs,style=plot.style_histogram,title="TTM wave B Slow",color=#296a22,linewidth=3)
plot(ttmwbf,style=plot.style_histogram,title="TTM wave B Fast",color=#f3701c,linewidth=3)

// A
float ttmwas = na
float ttmwaf = na
if showA 
    [_,_,ASlowHist] = ta.macd(close,8,55,55)
    ttmwas := ASlowHist
    [_,_,AFastHist] = ta.macd(close,8,34,34)
    ttmwaf := AFastHist
plot(ttmwas,style=plot.style_histogram,title="TTM wave A Slow",color=#296a22,linewidth=3)
plot(ttmwaf,style=plot.style_histogram,title="TTM wave A Fast",color=#f3701c,linewidth=3)

atr_length      = input.int(14, title = "ATR Length", minval = 0, group = "ATR Indicator Settings")

atr1_multiplier = input.float(1.5, title = "ATR Multiplier #1", minval = 0, group = "ATR Multiplier Settings")
show_atr2       = input.bool(false, title = "Show 2nd ATR line?",           group = "ATR Multiplier Settings")
atr2_multiplier = input.float(3,   title = "ATR Multiplier #2", minval = 0, group = "ATR Multiplier Settings")
//==============================================================================


//==============================================================================
// ATR #1 and ATR #2 Calculation
//==============================================================================
// Calculate basic ATR value with given smoothing parameters
atr  = ta.rma(ta.tr, atr_length)

// Multiply atr by the given atr1 multiplier to get atr1
atr1 = atr * atr1_multiplier

// Multiply atr by the given atr2 multiplier to get atr2
atr2 = atr * atr2_multiplier
//==============================================================================


//==============================================================================
// Plot ATR #1 and ATR #2
//==============================================================================
atr1_color = show_atr2 ? color.red : color.new(#000000, 0)

atr1_plot = plot(atr1,                  title = "ATR #1", color = atr1_color)
atr2_plot = plot(show_atr2 ? atr2 : na, title = "ATR #2", color = color.green)


length = input.int(20, "TTM Squeeze Length")

//BOLLINGER BANDS
BB_mult = input.float(2.0, "Bollinger Band STD Multiplier")
BB_basis = ta.sma(close, length)
dev = BB_mult * ta.stdev(close, length)
BB_upper = BB_basis + dev
BB_lower = BB_basis - dev

//KELTNER CHANNELS
KC_mult_high = input.float(1.0, "Keltner Channel #1")
KC_mult_mid = input.float(1.5, "Keltner Channel #2")
KC_mult_low = input.float(2.0, "Keltner Channel #3")
KC_basis = ta.sma(close, length)
devKC = ta.sma(ta.tr, length)
KC_upper_high = KC_basis + devKC * KC_mult_high
KC_lower_high = KC_basis - devKC * KC_mult_high
KC_upper_mid = KC_basis + devKC * KC_mult_mid
KC_lower_mid = KC_basis - devKC * KC_mult_mid
KC_upper_low = KC_basis + devKC * KC_mult_low
KC_lower_low = KC_basis - devKC * KC_mult_low

//SQUEEZE CONDITIONS
NoSqz = BB_lower < KC_lower_low or BB_upper > KC_upper_low //NO SQUEEZE: GREEN
LowSqz = BB_lower >= KC_lower_low or BB_upper <= KC_upper_low //LOW COMPRESSION: BLACK
MidSqz = BB_lower >= KC_lower_mid or BB_upper <= KC_upper_mid //MID COMPRESSION: RED
HighSqz = BB_lower >= KC_lower_high or BB_upper <= KC_upper_high //HIGH COMPRESSION: ORANGE

//MOMENTUM OSCILLATOR
mom = ta.linreg(close - math.avg(math.avg(ta.highest(high, length), ta.lowest(low, length)), ta.sma(close, length)), length, 0)

//MOMENTUM HISTOGRAM COLOR
iff_1 = mom > nz(mom[1]) ? color.new(color.aqua, 0) : color.new(#2962ff, 0)
iff_2 = mom < nz(mom[1]) ? color.new(color.red, 0) : color.new(color.yellow, 0)
mom_color = mom > 0 ? iff_1 : iff_2

//SQUEEZE DOTS COLOR
sq_color = HighSqz ? color.new(color.orange, 0) : MidSqz ? color.new(color.red, 0) : LowSqz ? color.new(color.black, 0) : color.new(color.green, 0)

//ALERTS
Detect_Sqz_Start = input.bool(true, "Alert Price Action Squeeze")
Detect_Sqz_Fire = input.bool(true, "Alert Squeeze Firing")

if Detect_Sqz_Start and NoSqz[1] and not NoSqz
    alert("Squeeze Started")
else if Detect_Sqz_Fire and NoSqz and not NoSqz[1]
    alert("Squeeze Fired")

//PLOTS
plot(mom, title='MOM', color=mom_color, style=plot.style_columns, linewidth=2)
plot(0, title='SQZ', color=sq_color, style=plot.style_circles, linewidth=3)

//@version=5
ao = ta.sma(hl2,5) - ta.sma(hl2,34)
diff = ao - ao[1]
aoColor = ao >= 0 ? (ao[1] < ao ? #26A69A : #B2DFDB) : (ao[1] < ao ? #FFCDD2 : #EF5350)
plot(ao, title="AO", style=plot.style_columns, color=aoColor, transp=0)

