# Advanced Squeeze Scanner v2.0
# Momentum Squeeze basis coding by Moebius, based on John Carter
# Scanner by WTF_Dude. Mods on 9.9.20
# Edited 9.22.20
declare lower;
input length = 20; #hint length: Length for average calculation
input price = close;
input SDmult = 2.0;
input ATR_mult = 1.5;
input ATR_length = 20;
input Move_Threshold = 0; #best to set to 0 if using ATR options
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), ATR_length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (Atr_Mult * 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 > Move_Threshold and Momo>0;
def momobulldown = Momo > 0 and Momo < Momo[1];
def momobeardown = Momo < Momo[1] and absvalue(Momo)>Move_Threshold and momo<0;
def momobearup = Momo < 0 and Momo > Momo[1];
def change = absvalue(close - close[1]);
# Squeeze breaks out in EITHER direction
Plot Breakout = squeeze[1] is true and squeeze is false;
# Breakout of squeeze to the upside
plot BreakoutBull = squeeze[1] is true and squeeze is false and momobullup;
# Breakout of squeeze to the downside
plot BreakoutBear = squeeze[1] is true and squeeze is false and momobulldown;
# Breakout of squeeze to the upside with move larger than ATR
plot BreakoutBullATRplus = squeeze[1] is true and squeeze is false and momobullup and change>ATR;
# Breakout of squeeze to the downside with move larger than ATR
plot BreakoutBearATRplus = squeeze[1] is true and squeeze is false and momobeardown and change>ATR;
# Bull trend reverses and turns down while the color changes to dark blue
Plot BullTrendReversal = momobulldown is true and momobulldown[1] is false;
# Bear trend reverses and turns up while the color changes to yellow
Plot BearTrendReversal= momobearup is true and momobearup[1] is false;
# Zero line turns red and becomes a squeeze
plot EnteringSqueeze = Squeeze[1] is false and Squeeze is true;