# AdvancedSqueezeScanner
# Momentum Squeeze open coding by Moebius, based on John Carter
# Scan by WTF_Dude
# Added Squeeze Label with directional color
# Label is green when momentum is ascending, red when descending
declare lower;
input length = 20; #hint length: Length for average calculation
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(High, length) + Lowest(low, length)) /
2 + ExpAverage(close, length);
def Momo = Inertia(price - K / 2, length);
def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (AtrMult * ATR);
def Squeeze = SDup < ATRup;
def zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;
def momobullup = Momo > Momo[1] and Momo > 0;
def momobulldown = Momo > 0 and Momo < Momo[1];
def momobeardown = Momo > Momo[1] and Momo > 0;
def momobearup = Momo < 0 and Momo > Momo[1];
Plot BreakoutEitherDirection = squeeze[1] is true and squeeze is false;
plot BreakoutBull = squeeze[1] is true and squeeze is false and momobullup;
plot BreakoutBear = squeeze[1] is true and squeeze is false and momobulldown;
Plot BullTrendReversal = momobulldown is true and momobulldown[1] is false;
Plot BearTrendReversal = momobearup is true and momobearup[1] is false;
plot Squeeze_ChangetoBull = BearTrendReversal and squeeze is true;
plot Squeeze_ChangetoBear = BullTrendReversal and squeeze is true;
#End Code