TTM Squeeze Format, Scan, Watchlist, Label For ThinkOrSwim

Mac Trader

New member
The following scan code can be used to identify symbols with the first or second Cyan histogram bar... Simply remove or add the comment "#" to/from the appropriate plot line... The code can be further modified to suit your needs...

Ruby:
def hist = reference TTM_Squeeze.Histogram;

# First Cyan Histogram Bar
plot scan = if hist > 0 and hist[1] < 0 and hist[2] < hist[1] then 1 else Double.NaN;

# Second Cyan Histogram Bar
#plot scan = if hist > 0 and hist[1] > 0 and hist[2] < 0 then 1 else Double.NaN;
How would you adjust this code if you wanted to see the histogram before the first Cyan histogram? I will be running it with the following code:
def inSqueeze = TTM_Squeeze().SqueezeAlert == 0;
def result = sum(insqueeze,5) == 5;
 

Slippage

Well-known member
The concept is to wait for there to be a gap between the histogram bar and MA line...

1PETVU4.png
That's a cool idea. I've never seen anyone do that.
 

rad14733

Well-known member
VIP
That's a cool idea. I've never seen anyone do that.

That, to me, is one early entry indication... I code most of my histograms with a MA for that reason... The cyan MA color change in the example above tells me when that has happened... Once I find the proper MA length for whatever statistical data the histogram is a measure of it generally works well across all symbols...
 

Doc8315

New member
@BenTen How do I change the background colors for the code you gave in the initial post? Specifically, I would like to change the red background to yellow when the Squeeze is building. Thanks
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
AssignBackgroundColor(if sqzNoBuy then CreateColor(170, 6, 0) else if sqzBuy then color.red else if sumIsFired then CreateColor(28, 105, 3) else color.black);
@Doc8315
In the last line of the code change red to yellow.
 

winrmr21

New member
VIP
Does anyone know how to program a scan using the TTM Squeeze indicator that will indicate that a squeeze has change blue to red?
 

rad14733

Well-known member
VIP
Does anyone know how to program a scan using the TTM Squeeze indicator that will indicate that a squeeze has change blue to red?

I'm fairly certain it has been posted somewhere but here you go...

Ruby:
def hist = reference TTM_Squeeze.Histogram;

# First Red Histogram Bar
plot scan = if hist < 0 and hist[1] > 0 then 1 else Double.NaN;
 

Batman

Member
How would you code for a scan that shows stocks when their TTM Squeeze indicator (I'm referring to the one that comes with ThinkorSwim) is showing upwards momentum? In other words, I am trying to get alerted to a condition where the TTM Squeeze indicator's histogram is currently below the zero line but is approaching it to cross over from below. I would treat the crossover of the zero line as my entry signal, and I'm simply wanting a little room to analyze the stock as its TTM Squeeze indicator approaches that zero line, if that makes sense.

My stab at it would be that I am looking for a stock whose TTM Squeeze indicator histogram has a value less than or equal to -50 one bar ago and is now above that value. But that is a very basic code. I'm sure a much better option is possible!
 

Slippage

Well-known member
How would you code for a scan that shows stocks when their TTM Squeeze indicator (I'm referring to the one that comes with ThinkorSwim) is showing upwards momentum? In other words, I am trying to get alerted to a condition where the TTM Squeeze indicator's histogram is currently below the zero line but is approaching it to cross over from below. I would treat the crossover of the zero line as my entry signal, and I'm simply wanting a little room to analyze the stock as its TTM Squeeze indicator approaches that zero line, if that makes sense.

My stab at it would be that I am looking for a stock whose TTM Squeeze indicator histogram has a value less than or equal to -50 one bar ago and is now above that value. But that is a very basic code. I'm sure a much better option is possible!

You'd want two rules. Histogram is less than zero. Histogram is greater than -50. So add the study filter twice, once for each of those two rules. And then you can experiment with changing -50 to see if it's better as -30 or -70 or whatever other value is the sweet spot for your needs.
 

winrmr21

New member
VIP
Hey what’s up guys I need help Does anyone know how to program a scan using the TTM Squeeze pro indicator that will indicate that a squeeze has 3 dot squeeze that just fire ?
 

SleepyZ

Well-known member
VIP
Lifetime
Hey what’s up guys I need help Does anyone know how to program a scan using the TTM Squeezepro indicator that will indicate that a squeeze has 3 dot squeeze that just fire ?

This is set to have a minimum of 3 dots (you can change at the input dots) and maxdots of 3, ie; exactly 3 dots, and then a fire bar. You can increase the maxdots at the input screen if you decide more is okay.

I have not tested it in the scanner, but since the picture shows it works on a chart, it should work in the scanner. The curser in the picture is at the only squeeze of 3 dots followed by a fire (non_squeeze) dot

Capture.jpg
Ruby:
input dots    = 3;
input maxdots = 3;
def squeeze_dots = reference TTM_Squeeze().SqueezeAlert;

def dot_count    = if squeeze_dots[1] == 1 and squeeze_dots == 0
                   then 1
                   else if dot_count[1] >= 1 and squeeze_dots == 0
                   then dot_count[1] + 1
                   else 0;
plot fire        = if Between(dot_count[1], dots, maxdots) and squeeze_dots == 1 then 1 else Double.NaN;
fire.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 

commoncents

New member
That would be something like the following... But this would catch every instance when downtrend momentum starts to reverse upward...

Edited: Hadn't tested the previous code... Doh...!!!

Ruby:
def hist = reference TTM_Squeeze.Histogram;
plot scan = if hist < 0 and hist > hist[1] and hist[1] < hist[2] then 1 else Double.NaN;

iug7Jta.png


The more comparisons you make, the stronger the downtrend was before the reversal, like this code shows... It compares the current bar to the previous four bars...

Ruby:
def hist = reference TTM_Squeeze.Histogram;
plot scan = if hist < 0 and hist > hist[1] and hist[1] < hist[2] and hist[2] < hist[3] and hist[3] < hist[4] then 1 else Double.NaN;

qbvN6op.png
Hi @rad14733,

I'd appreciate your assistance on a few things...

How do you differentiate between TTM_Squeeze and TTM_SqueezePro in code? I have the later from JC and want to make sure it's being coded for Pro.

1) Is this correct as a scan that looks for a red to yellow histogram with momentum increasing on each yellow candle?
Ruby:
def hist = reference TTM_Squeeze.Histogram;

plot scan = if hist < 0 and hist > hist[1] and hist[1] > hist[2] and hist[2] > hist[3] and hist[3] > hist[4] then 1 else Double.NaN;


2) Also I would like a scan that finds:
5dots in a squeeze (any compression) and just fired...the below code is my attempt and as far as I got, if you can help me complete it, I would very much appreciate it.

Ruby:
def inSqueeze = TTM_Squeeze().SqueezeAlert == 0;

plot result = sum(insqueeze,5) == 5;

Thanks!
 
Last edited:

eliwilner

New member
Hi guys I'm new to this site and I actually use the TTM Squeeze pro along with adding the code into my watch list. I've been trading for almost a year and I use TOS. I've learned a lot but still have a lot to learn! This is the code to my squeeze I've added to my watchlist that I found on the internet (thank you) BUT my question is can someone edit my code to allow the gold/orange color to show up on stronger/tighter squeezes? You know more similar to the TTM Squeeze pro. By seeing a gold dot in your watchlist if you are a squeeze trader I feel like it would really grab your attention. Also this squeeze watchlist code even offers the output of the letter "B" in the box for buy which is really cool but would it be possible to edit the code slightly to make it give slightly less "B" signals? Basically it would be nice if the code would only produce Bs if its like guaranteed to take off you know? Of course nothing is 100% accurate.

Code:
# Squeeze watchlist column
#   Red Background   - Squeeze is building in the time period - number indicates how many dots
#      w/ white "B"  - Squeeze is building, stock is within "buy zone"
#   Green Background - Squeeze has fired - number indicates how many dots (up to 5 dots)
#                      and whether Squeeze fired L(ong) or S(hort)
#   Black Background - No Squeeze in play

# Original code by Eric Purdy of Simpler Trading 2017
# Modified code by Rich Stratmann to put in background colors and shorten column values
# Updates by dmccuskey
#   - modify colors and content to indicate whether a stock is in the "buy zone" - between 8 & 21 EMA
#   - add small "fudge factor" to relax buy zone a bit

def sqz = !TTM_Squeeze().SqueezeAlert;
def direction = TTM_Squeeze()>TTM_Squeeze()[1];
def count = if sqz and !sqz[1] then 1 else count[1]+1;
def isFired = if !sqz and sqz[1] then 1 else 0;
def firedCount = if isFired then 1 else firedCount[1]+1;
def firedDirection = if isFired then direction else firedDirection[1];

def sumIsFired = sum(isFired,5);
def isFiredDir = sumIsFired && firedDirection;

# look for close buy zone
def ema8 = reference movAvgExponential(length=8);
def ema21 = reference movAvgExponential(length=21);
def currPrice = close();
def highVal = Max(ema8, ema21);
def lowVal = Min(ema8, ema21);
def inBuyZone = currPrice >= lowVal && currPrice <= highVal;

def sqzBuy = sqz && inBuyZone;
def sqzNoBuy = sqz && !inBuyZone;

addLabel(yes, Concat(if sqzBuy then "B " else "", if sqz then "" + count else if sumIsFired then “” + firedCount + if firedDirection then ” L” else ” S” else “ ”), if sqzBuy then color.white else color.black);

AssignBackgroundColor(if sqzNoBuy then  CreateColor(170, 6, 0) else if sqzBuy then color.red else if sumIsFired then CreateColor(28, 105, 3) else color.black);
HI Man. Can you share the ready aim fire code you found? I was also curious about this... Thanks
 
Last edited by a moderator:

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
Last edited:
This community has produced many excellent scripts for the classic squeeze indicator. A historical outcomes summary could accompany any of these thinkscripts. I thought a video demonstration of something similar might help, and it shows something similar is possible to code. I am not saying we need to replicate it to match the video, but perhaps focus on a few things that I think most squeeze enthusiasts might like such as: avg time (number of bars) price spends in squeeze, how often direction of momentum before the end of the squeeze predicts the outcome, typical % move from end of squeeze, etc. Link to example video
 

Mattyb740

Member
Hey good afternoon everyone ! I was wondering what everyone uses on their ttm squeeze parameters? Right now I’m on default, and would like the parameters due to me putting the study on my phone right now, would like to hear more experienced thinkscript users opinions!
Thanks,
Matt
 
Last edited:

noexpert

New member
@wtf_dude - you're brilliant. Could you help with a request?

Looking for TTM_Squeeze script, keeping everything in tact in the original source code, with the only change being to paint the price bars as per the histogram colors. If you have time on your hands and wouldn't mind giving it a whirl, I'd be grateful. I'm sure it's an 'assignPriceColor' tag, but I couldn't be sure and I rather a pro handle it.

Thanks if possible!
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top