# TTM Squeeze

D

#### dvorakm

##### New member
2019 Donor
VIP
Does anyone know how to program a scan using the TTM Squeeze indicator that will indicate that:

a squeeze has fired LONG within 15 bars with NO loss of momentum?

Thanks,
Mike D.

#### BenTen

Staff
VIP
There were a few TTM indicators shared on here. Please use the search feature and see if you can find the one you’re looking for.

L

#### Liquidity

##### New member
VIP
Would there be any way to incorporate arrows based on which way the momentum bars fire after the squeeze ? I currently use the code from mobius but am not able to post it here at the moment.

Last edited:

#### BenTen

Staff
VIP
@Liquidity The source code for the original TTM_Squeeze indicator in ToS isn't available so I couldn't modify it to include the arrows for you.

P

#### Pensar

##### Active member
VIP
@Liquidity I found Mobius' Momentum Squeeze and modified the code. I'm not certain what you consider "up" or "down", so I plotted the arrows to signal "up" if the squeeze fires when the momentum is greater than 0, and to signal "down" if the squeeze fires when momentum is less than 0. If you want it to signal differently, post the changes you want.

Code:
``````# Squeeze Momentum Arrow Signals
# Uses Momentum Squeeze code by Mobius
# Edited by Pensar 07/23/2020
# Removed the original plots and label, and plotted arrows on price to indicate
# momentum direction after the squeeze fires

declare upper;

input length = 20; #hint length: Length for average calculation
input SDmult = 2.0;
input ATRmult = 1.5;

def c = close;
def h = high;
def l = low;
def K = (Highest(h, length) + Lowest(l, length))/2 + ExpAverage(c, length);
def Momo = if isNaN(close) then double.nan else Inertia(c - K / 2, length);
def SD = StDev(c, length);
def Avg = Average(c, length);
def ATR = Average(TrueRange(h, c, l), length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (AtrMult * ATR);
def Squeeze = if isNaN(c) then double.nan else if SDup < ATRup then 0 else Double.NaN;
def zero = if IsNaN(c) or !IsNaN(Squeeze) then Double.NaN else 0;

plot arrow_up = if IsNaN(c) or !IsNaN(Squeeze) or !IsNaN(zero[1]) then Double.NaN
else if Momo > 0 then low else Double.NaN;
arrow_up.setpaintingstrategy(paintingstrategy.arrow_up);
arrow_up.setdefaultcolor(color.cyan);
arrow_up.setlineweight(3);

plot arrow_dn = if IsNaN(c) or !IsNaN(Squeeze) or !IsNaN(zero[1]) then Double.NaN
else if Momo < 0 then high else Double.NaN;
arrow_dn.setpaintingstrategy(paintingstrategy.arrow_down);
arrow_dn.setdefaultcolor(color.magenta);
arrow_dn.setlineweight(3);

# end code``````

P

#### Pensar

##### Active member
VIP
Here's Mobius' Momentum Squeeze code. It is identical to JC's TTM_Squeeze code on TOS that has the locked source code.

Code:
``````# Momentum Squeeze
# Mobius
# 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 SDmult = 2.0;
input ATRmult = 1.5;

def c = close;
def h = high;
def l = low;
def K = (Highest(h, length) + Lowest(l, length)) /
2 + ExpAverage(c, length);
plot Momo = if isNaN(close)
then double.nan
else Inertia(c - K / 2, length);
Momo.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.setLineWeight(3);
Momo.assignValueColor(if Momo > Momo[1] and Momo > 0
then Color.Cyan
else if Momo > 0 and Momo < Momo[1]
then Color.Blue
else if Momo < 0 and Momo < Momo[1]
then Color.Red
else Color.Yellow);

def SD = StDev(c, length);
def Avg = Average(c, length);
def ATR = Average(TrueRange(h, c, l), length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (AtrMult * ATR);
plot Squeeze = if isNaN(c)
then double.nan
else if SDup < ATRup
then 0
else Double.NaN;
Squeeze.SetPaintingStrategy(PaintingStrategy.Points);
Squeeze.SetLineWeight(1);
Squeeze.SetDefaultColor(Color.Red);
plot zero = if IsNaN(c) or !IsNaN(Squeeze) then Double.NaN else 0;
zero.SetPaintingStrategy(PaintingStrategy.Points);
zero.SetLineWeight(1);
zero.SetDefaultColor(Color.Green);
then Color.Green
else Color.Red);
# End Code - Momentum Squeeze``````

L

#### Liquidity

##### New member
VIP
@Liquidity I found Mobius' Momentum Squeeze and modified the code. I'm not certain what you consider "up" or "down", so I plotted the arrows to signal "up" if the squeeze fires when the momentum is greater than 0, and to signal "down" if the squeeze fires when momentum is less than 0. If you want it to signal differently, post the changes you want.

Code:
``````# Squeeze Momentum Arrow Signals
# Uses Momentum Squeeze code by Mobius
# Edited by Pensar 07/23/2020
# Removed the original plots and label, and plotted arrows on price to indicate
# momentum direction after the squeeze fires

declare upper;

input length = 20; #hint length: Length for average calculation
input SDmult = 2.0;
input ATRmult = 1.5;

def c = close;
def h = high;
def l = low;
def K = (Highest(h, length) + Lowest(l, length))/2 + ExpAverage(c, length);
def Momo = if isNaN(close) then double.nan else Inertia(c - K / 2, length);
def SD = StDev(c, length);
def Avg = Average(c, length);
def ATR = Average(TrueRange(h, c, l), length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (AtrMult * ATR);
def Squeeze = if isNaN(c) then double.nan else if SDup < ATRup then 0 else Double.NaN;
def zero = if IsNaN(c) or !IsNaN(Squeeze) then Double.NaN else 0;

plot arrow_up = if IsNaN(c) or !IsNaN(Squeeze) or !IsNaN(zero[1]) then Double.NaN
else if Momo > 0 then low else Double.NaN;
arrow_up.setpaintingstrategy(paintingstrategy.arrow_up);
arrow_up.setdefaultcolor(color.cyan);
arrow_up.setlineweight(3);

plot arrow_dn = if IsNaN(c) or !IsNaN(Squeeze) or !IsNaN(zero[1]) then Double.NaN
else if Momo < 0 then high else Double.NaN;
arrow_dn.setpaintingstrategy(paintingstrategy.arrow_down);
arrow_dn.setdefaultcolor(color.magenta);
arrow_dn.setlineweight(3);

# end code``````

exactly what I needed. thank you very much

C

#### C4men

##### Member
Hoping I am in the correct thread...

Is there a simple way to paint an arrow on the chart when:
• Previous candle was in a squeeze
• Current candle the squeeze has "fired" (dot turned green)
• Current candle histogram has turned to that light blue color
I could add other conditions later, of course, but just those 3 things would be immensely helpful.

P

#### Pensar

##### Active member
VIP
@C4men - Here are your 3 conditions, an arrow will plot on the chart when the conditions are true.

Code:
``````def S = reference TTM_Squeeze().SqueezeAlert;
def H = reference TTM_Squeeze().Histogram;

plot Arrow = !S[1] and S and H > 0 and H > H[1];
Arrow.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
Arrow.SetLineWeight(3);
Arrow.SetDefaultColor(color.cyan);``````

J

##### New member
VIP
do the arrows above repaint?

P

#### Pensar

##### Active member
VIP
@jeremyadorna No, the arrows in the above code will not repaint.

C

#### C4men

##### Member
Thank you @Pensar very much. I'm going to go play around with this.

I.. have... a... plan... lol

C

#### C4men

##### Member
Thank you @Pensar very much. I'm going to go play around with this.

I.. have... a... plan... lol
@Pensar in the code above, does the [1] represent 1 bar ago?

#### BenTen

Staff
VIP
@C4men It means the previous bar and not the current bar.

#### vro3

##### Member
This is dumb, but i need help from someone here.

For some reason, I swear my squeeze indicator is reversed.

but, when i go to edit the indicator, it says alert red. normal green.

can anyone help me figure out if im crazy or not?

monday night. looks like \$NAIL is on a daily squeeze. the middle ball is red.

Last edited by a moderator:

#### BenTen

Staff
VIP
@vro3 Post a screenshot of your ToS. Here is my chart of \$NAIL on the Daily timeframe.

#### vro3

##### Member
so - mine looks like that - but, in the edit studies - i have the two colors reverse. ill get you a screenshot in a bit!

am i crazy? is this normal? shouldn't alert be red?

Last edited by a moderator: