#Squeeze Play Strategy For ThinkOrSwim
#@Gavstah 10/2021
#@InvestingtoGive added Lower Level 11/4/2021
#Hint: SqueezePlay - stacked EMAs (8,21,34,55,89), Upward momentum on TTM_Squeeze, in a squeeze, and price over the 21 EMA
declare lower;
input price = close;
# define the EMAs
def ema8 = ExpAverage(price, 8);
def ema21 = ExpAverage(price, 21);
def ema34 = ExpAverage(price, 34);
def ema55 = ExpAverage(price, 55);
def ema89 = ExpAverage(price, 89);
# define the EMAs
def EMA8_ = ExpAverage(price, 8);
def EMA21_ = ExpAverage(price, 21);
def EMA34_ = ExpAverage (price, 34);
def EMA55_ = ExpAverage (price, 55);
def EMA89_ = ExpAverage (price, 89);
# is the price in the buy zone?
def buyZone = price < ema8 and price > ema21;
def sellZone = price > ema8 and price < ema21;
# now, let's see what we have
# 1) is momentum > 0 and on an upward trend on then TTM_Squeeze() histogram?
def bullMomentum = TTM_Squeeze().Histogram > 0 && TTM_Squeeze().Histogram > TTM_Squeeze().Histogram[1];
def bearMomentum = TTM_Squeeze().Histogram < 0 && TTM_Squeeze().Histogram < TTM_Squeeze().Histogram[1];
# 2) Has the price closed over the 21 EMA?
def bullcloseOver21 = price > EMA21_;
def bearcloseOver21 = price < EMA21_;
# 3) Are EMAs stacked in acsending order ("The Royal Setup")?
def bullstackedEMAS = EMA8_ > EMA21_ and EMA21_ > EMA34_ and ema34 > EMA55_ and EMA55_ > ema89;
def bearstackedEMAS = EMA8_ < EMA21_ and EMA21_ < EMA34_ and ema34 < EMA55_ and EMA55_ < ema89;
# 4) are we in a TTM_squeeze (true if squeezealert has not fired)?
def squeeze = !TTM_Squeeze().SqueezeAlert;
# do we have a squeeze play?
def bullsqueezePlay = squeeze && bullstackedEMAS && bullMomentum && bullcloseOver21;
def bearsqueezePlay = squeeze && bearstackedEMAS && bearMomentum && bearcloseOver21;
# Plot for Squeeze Play
plot Dots_Play_Color = if ( isnaN(close),double.NaN, 6);
Dots_Play_Color.SetPaintingStrategy(PaintingStrategy.POINTS);
Dots_Play_Color.AssignValueColor( if (bullsqueezeplay) then Color.GREEN else if (bearsqueezeplay) then Color.RED else Color.Yellow);
Dots_Play_Color.SetLineWeight(5);
# Plot for TTM Squeeze
plot Dots_Squeeze_Color = if ( isnaN(close),double.NaN, 4);
Dots_Squeeze_Color.SetPaintingStrategy(PaintingStrategy.POINTS);
Dots_Squeeze_Color.AssignValueColor( if (squeeze) then Color.GREEN else Color.Yellow);
Dots_Squeeze_Color.SetLineWeight(5);
# Plot for Stacked EMAs
plot Dots_EMAS_Color = if ( isnaN(close),double.NaN, 3);
Dots_EMAS_Color.SetPaintingStrategy(PaintingStrategy.POINTS);
Dots_EMAS_Color.AssignValueColor( if (bullstackedEMAS) then Color.GREEN else if (bearstackedEMAS) then Color.RED else Color.Yellow);
Dots_EMAS_Color.SetLineWeight(5);
# Plot for Momentum (MO)
plot Dots_MO_Color = if ( isnaN(close),double.NaN, 2);
Dots_MO_Color.SetPaintingStrategy(PaintingStrategy.POINTS);
Dots_MO_Color.AssignValueColor( if (bullMomentum) then Color.GREEN else if (bearMomentum) then Color.RED else Color.Yellow);
Dots_MO_Color.SetLineWeight(5);
# Plot for Cross Over/Under 21
plot Dots_Cross_Color = if ( isnaN(close),double.NaN, 1);
Dots_Cross_Color.SetPaintingStrategy(PaintingStrategy.POINTS);
Dots_Cross_Color.AssignValueColor( if (bullcloseOver21) then Color.GREEN else if (bearcloseOver21) then Color.RED else Color.Yellow);
Dots_Cross_Color.SetLineWeight(5);