TTM Squeeze Format, Scan, Watchlist, Label For ThinkOrSwim

mosog

New member
I'm trying to scan for stocks/options that checks the past 4 TTM Histogram bars to make sure the following conditions are true:
1) TTM_Squeeze().Histogram 3 and 4 are below 0 and histogram 3 is closer to 0 than 4 (so histogram [3] > histogram [4])
2) histogram 1 is greater than histogram 2 and both of them are above 0 line
3) plot if 1 and 2 are true.

I had the code more joined together before but thinkorswim complained that it was too complex (not sure why seems pretty simple conditions). I rewrote it like this which I'm sure is not the best way, could someone look at it and make sure I did it right and perhaps fix whatever I did wrong.

Here is my snipped of code

def negToPos = TTM_Squeeze().Histogram [4] is less than 0 and TTM_Squeeze().Histogram [3] is less than 0;
def bullStart = TTM_Squeeze().Histogram [2] and TTM_Squeeze().Histogram [1] is greater than 0;

def bullRun = TTM_Squeeze().Histogram [1] > TTM_Squeeze().Histogram [2] and TTM_Squeeze().Histogram [3] > TTM_Squeeze().Histogram [4];


plot signal = negToPos and bullStart and bullRun;
 

halcyonguy

Well-known member
VIP
Lifetime
I'm trying to scan for stocks/options that checks the past 4 TTM Histogram bars to make sure the following conditions are true:
1) TTM_Squeeze().Histogram 3 and 4 are below 0 and histogram 3 is closer to 0 than 4 (so histogram [3] > histogram [4])
2) histogram 1 is greater than histogram 2 and both of them are above 0 line
3) plot if 1 and 2 are true.

I had the code more joined together before but thinkorswim complained that it was too complex (not sure why seems pretty simple conditions). I rewrote it like this which I'm sure is not the best way, could someone look at it and make sure I did it right and perhaps fix whatever I did wrong.

Here is my snipped of code

def negToPos = TTM_Squeeze().Histogram [4] is less than 0 and TTM_Squeeze().Histogram [3] is less than 0;
def bullStart = TTM_Squeeze().Histogram [2] and TTM_Squeeze().Histogram [1] is greater than 0;

def bullRun = TTM_Squeeze().Histogram [1] > TTM_Squeeze().Histogram [2] and TTM_Squeeze().Histogram [3] > TTM_Squeeze().Histogram [4];


plot signal = negToPos and bullStart and bullRun;
bullstart isn't right,
a logic(and) comparison , compared ( > ) to a number

i don't know why you have bullrun formula.

it is more efficient to read external data once and put it in a variable.

here are your 3 rules
Code:
def ttmh = TTM_Squeeze().Histogram;
# rule 1
def one = ( ttmh[3] > ttmh[4] and ttmh[3] < 0 );
# rule 2
def two = ( ttmh[1] > ttmh[2] and ttmh[2] > 0 );
# rule 3
plot three = if ( one and two) then 1 else 0;
 

mosog

New member
bullstart isn't right,
a logic(and) comparison , compared ( > ) to a number

i don't know why you have bullrun formula.

it is more efficient to read external data once and put it in a variable.

here are your 3 rules
Code:
def ttmh = TTM_Squeeze().Histogram;
# rule 1
def one = ( ttmh[3] > ttmh[4] and ttmh[3] < 0 );
# rule 2
def two = ( ttmh[1] > ttmh[2] and ttmh[2] > 0 );
# rule 3
plot three = if ( one and two) then 1 else 0;

Excellent, thank you for the solution. I'm still learning thinkscript.
 

commoncents

New member
For those of you who enjoy using the TTM Squeeze & Momentum indicator, this should be a handy addition to your ThinkorSwim chart setup. The script will add the status of the TTM Squeeze for stocks on your watchlist via a new column. You can select whichever timeframe you would like to scan for TTM squeeze.

Stocks usually break out of consolidations and by having the TTM Squeeze on your watchlist it helps to alert when they do.
Is it possible to modify the background color for when it just fired (first green dot 1L and 1S) to be cyan ?
 
Last edited by a moderator:

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
Is it possible to modify the background color for when it just fired (first green dot 1L and 1S) to be cyan ?
It is not clear what you are asking for.
Sounds like something you may have to post a picture of what you are trying to accomplish with a more detailed explanation of what the conditions would look like that would signal the background color change.
Unsure of how to upload screenshots to the forum, Here are directions.
 
Last edited:

gravityflyer

New member
Hi all,

Does anyone have ThinkOrSwim's source code for the built-in TTM Squeeze indicator? I'm trying to view the script but it says "Source code isn't available." Any help would be greatly appreciated!

Thanks!
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
Hi all,

Does anyone have ThinkOrSwim's source code for the built-in TTM Squeeze indicator? I'm trying to view the script but it says "Source code isn't available." Any help would be greatly appreciated!

Thanks!
The ToS TTM Squeeze source code is copy-protected. We do not post proprietary scripts on this forum.

Here is a list of all the public domain squeeze scripts available on the forum:
https://usethinkscript.com/threads/john-carters-squeeze-pro-replica-questions.8705/#post-80562
 

ibenjamin305

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);
Did anybody ever figure out a code for what this person was asking for because I am looking for about the same thing too?
 

tommylala

New member
How does everyone use this indicator? Do you get in a trade when the red dot is on? Do you wait for a few red dots and then get in on a trade? Or do you wait until the squeeze fire?

What I noticed is that, I would need to wait until a few red dots then I would enter a trade. Because if you wait for the squeeze to fire, the move is already gone.

What is your strategy?
 

novadolla

New member
VIP
How do i modify this code to scan for stocks that showing dark bluse?

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

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