Scanner for TTM Squeeze fired

D

Dom173

New member
Man, I threw this together hoping it would make things EASIER, not more complicated lol.
Joseph, this is a scanner, not an indicator. There is already an indicator to use in TOS if you want (TTM_Squeeze)

Check out the image below to see how you would load this up. All you would change is the Plot dropdown. You can pick trend change, breakout to the upside, downside, etc. HOPEFULLY, this should clear everything up haha

For some reason, its not letting me upload the image itself so just check the link....
thanks for your help here. Is it possible to tweak this to alert when a chart is entering a squeeze? This way I have time to watch and react. Then maybe an arrow or on chart indicator to confirm a breakout of the squeeze. Hope that makes sense. thanks again
 
M

mailbagman2000

New member
Here ya go. Paste this into the thinkscript editor for study scan. Won't need to add any conditions. I coded it in

Code:
# Momentum Squeeze
# Mobius
# Added Squeeze Label with directional color
# Label is green when momentum is ascending, red when descending

declare lower;

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

   def K = (Highest(High, lengthe) + Lowest(low, lengthe)) /
               2 + ExpAverage(close, lengthe);
  def Momo = Inertia(price - K / 2, lengthe);

def SD = StDev(close, lengthe);
def Avg = Average(close, lengthe);
def ATR = Average(TrueRange(high, close, low), lengthe);
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;

Plot breakout = squeeze[1] is true and squeeze is false;
works exactly as you said to do. Thanks, got a lot of good idea for covered calling writing
 
D

Diamondlil

New member
Hi @wtf_dude not sure if I'm posting this in the right place, hoping you can help ...
Looking for code for a study (to then put in a scan) where TTM Squeeze histogram goes positive while still in a squeeze.
Thanks if you can help!
 
wtf_dude

wtf_dude

Active member
Just throw these 2 lines in the code and it will give you 2 additional dropdown functions for that:

plot SqueezeChangetoBull = beartrendchange and squeeze is true;
plot SqueezeChangetoBear = bulltrendchange and squeeze is true;
 
P

Parker427

New member
I need this too! So I go to Scan, Add filter, study, custom and add this coding or? Also it says that the "buxltrendchange" part for both lines don't work. "No such variable" or something like that
 
D

Diamondlil

New member
@wtf_dude sorry, I'm a newbie. Trying to figure this out. Where exactly would I put those 2 lines of code into? Tried putting into the TTM Squeeze script but it won't let me.
 
wtf_dude

wtf_dude

Active member
@wtf_dude sorry, I'm a newbie. Trying to figure this out. Where exactly would I put those 2 lines of code into? Tried putting into the TTM Squeeze script but it won't let me.
Oh no, you have to put it with the code I posted earlier. Just create a new study, call it something like AdvancedSqueezeScanner and paste all of this and then use it on the scan tab. Should be go to go.

Code:
# 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
 
D

Diamondlil

New member
:) Wow! thank you! Hopefully I can get that going. Appreciate it!
 
P

Parker427

New member
Oh no, you have to put it with the code I posted earlier. Just create a new study, call it something like AdvancedSqueezeScanner and paste all of this and then use it on the scan tab. Should be go to go.

Code:
# 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
This code also doesn't work, TOS. says "
No such variable: Momo at 13:28
No such variable: Momo at 13:40
No such variable: Momo at 14:18
No such variable: Momo at 14:31"
 
wtf_dude

wtf_dude

Active member
This code also doesn't work, TOS. says "
No such variable: Momo at 13:28
No such variable: Momo at 13:40
No such variable: Momo at 14:18
No such variable: Momo at 14:31"
You had to have copied it wrong. Works fine on my end. Momo is defined on line 16.
 
P

Parker427

New member
You had to have copied it wrong. Works fine on my end. Momo is defined on line 16.
I just copied and pasted it like 10 times. Now TOS says "Exactly one plot expected" and won't let me pass the "OK" button.
 
wtf_dude

wtf_dude

Active member
I just copied and pasted it like 10 times. Now TOS says "Exactly one plot expected" and won't let me pass the "OK" button.
oh dude no, you need to paste this to as a new study on the CHART tab. Then when you go to scan tab it will appear as a choice. You can't paste it on the scan tab because the formatting is different and adding from the chart area allows the option of dropdown menus
 
P

Parker427

New member
oh dude no, you need to paste this to as a new study on the CHART tab. Then when you go to scan tab it will appear as a choice. You can't paste it on the scan tab because the formatting is different and adding from the chart area allows the option of dropdown menus
Ohh okay. It works. Where do I find it on the scan tab?
 
wtf_dude

wtf_dude

Active member
Ohh okay. It works. Where do I find it on the scan tab?
Select add condition, then Study, then you'll add it by whatever name you saved it as, then select whatever you want from the dropdown menu next to Plot, then select "is true" in the middle column, and click OK.
 
P

Parker427

New member
Thank you so much!! When you put “is true” then “1 bar ago”, it shows squeezes that already fired. Is it possible to get in before the squeeze fires? Maybe a bar or two before. Therefore, we buy, bar or two later, it fires to the upside.
 
D

Diamondlil

New member
@wtf_dude what adjustment would I need to make for bullish moves only? Thank you.
 
D

Diamondlil

New member
Sorry but need help here. I think I'm missing something. I want to scan for only "buy alerts" with this indicator. Do I need to edit the condition input when setting up the scan? Kindly provide step by step if possible. Appreciate that very much! Thank you!

* Also, comment appears in indicator code: "invalid statement: 2 at 1:1" How do I correct this? Thank you again! *
I think it is referring to this:

2
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
 
Last edited:
Top