TTM Squeeze Format, Scan, Watchlist, Label For ThinkOrSwim

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:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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
 
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:
@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!
 
@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!
hmm i dont even have my code saved, havent used squeezes in a long time. Copy paste the code you want it in and ill throw it in there when I get a chance
 
@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!
The code below now includes an option to color the price bars like the histogram's colors.
Ruby:
declare lower;

input pricecolor = yes;
input usealerts = yes;
input price  = CLOSE;
input length = 20;
input nK     = 1.5;
input nBB    = 2.0;
input alertLine = 1.0;

plot Histogram    = reference TTM_Squeeze().Histogram;
plot VolComp      = reference TTM_Squeeze().Volcomp;
plot SqueezeAlert = reference TTM_Squeeze().SqueezeAlert;

SqueezeAlert.Hide();
VolComp.AssignValueColor(if SqueezeAlert != 1
                         then Color.WHITE   
                         else Color.gray);
VolComp.SetPaintingStrategy(PaintingStrategy.POINTS);
VolComp.SetLineWeight(2);
Histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Histogram.SetLineWeight(2);
Histogram.AssignValueColor(if Histogram > Histogram[1] and Histogram > 0
                           then Color.CYAN
                           else if Histogram > 0 and Histogram < Histogram[1]
                           then Color.blue
                           else if Histogram < 0 and Histogram < Histogram[1]
                           then Color.RED
                           else Color.YELLOW);

assignpricecolor(if pricecolor then if Histogram > Histogram[1] and Histogram > 0
                           then Color.CYAN
                           else if Histogram > 0 and Histogram < Histogram[1]
                           then Color.blue
                           else if Histogram < 0 and Histogram < Histogram[1]
                           then Color.RED
                           else Color.YELLOW
                           else color.current);

Alert(usealerts and SqueezeAlert == 0 and SqueezeAlert[1] == 1, "Fired", Alert.BAR, Sound.Chimes);

input showlabels = yes;
AddLabel(showlabels, (if !SqueezeAlert then "Squeeze & "
                     else "") +
                     if Histogram > Histogram[1] and Histogram > 0
                     then "Positive and Up"
                     else if Histogram > 0 and Histogram < Histogram[1]
                     then "Positive and Down"
                     else if Histogram < 0 and Histogram < Histogram[1]
                     then "Negative and Down"
                     else "Negative and Up",
                     if Histogram > Histogram[1] and Histogram > 0
                     then Color.CYAN
                     else if Histogram > 0 and Histogram < Histogram[1]
                     then Color.GRAY
                     else if Histogram < 0 and Histogram < Histogram[1]
                     then Color.RED
                     else Color.YELLOW);


input showbubble           = yes;
input bubblemover_sideways = -1;
input bubblemover_updown   = 0;
def x  = bubblemover_sideways;
def x1 = x + 1;
AddChartBubble(showbubble and
               IsNaN(close[x]) and !IsNaN(close[x1]),
               VolComp[x1] + bubblemover_updown,
               (if !SqueezeAlert[x1] then "Squeeze\n" else "") +
               (if Histogram[x1] > Histogram[x1 + 1] and Histogram[x1] > 0
               then "Positive and Up"
               else if Histogram[x1] > 0 and Histogram[x1] < Histogram[x1 + 1]
               then "Positive and Down"
               else if Histogram[x1] < 0 and Histogram[x1] < Histogram[x1 + 1]
               then "Negative and Down"
               else "Negative and Up"),
               if Histogram[x1] > Histogram[x1 + 1] and Histogram[x1] > 0
               then Color.CYAN
               else if Histogram[x1] > 0 and Histogram[x1] < Histogram[x1 + 1]
               then Color.GRAY
               else if Histogram[x1] < 0 and Histogram[x1] < Histogram[x1 + 1]
               then Color.RED
               else Color.YELLOW);
 
Is there a way to scan for tight BB squeezes?
@DudeDastic I moved your post here because there are 11 pages of scanning, watchlisting, and labeling squeezes. If you can't find what you need here. There are dozens of other threads. Just put squeeze in the search box. Have fun!
 
Is there any way to scan TTM Squeeze for momentum indicator from the last bar for either direction? NO matter up or down direction. It could be going from negative to positive or positive to negative. Need to use this in a strategy. Thanks

This is a similar request to the Batman in this thread.
 
Last edited:
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.

Here is what each signal and labels represent:
  • Bright Red: The stock is in Buy zone
  • Dark Red: Market compression is currently in this time period. The number reveals the amount of dots on your TTM Squeeze indicator.
  • Dark Green: The squeeze has fired. The number notes how many dots (up to 5) and whether the squeeze signaled Long or Short.
  • Black: No squeeze on this time frame

YexBBcI.png


thinkScript Code

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
#   - change background colors to aid content scanning
#   - add "B" to time frames which are in the Buy Zone - between 8 & 21 EMA
#   - change "0" to " " <space> so that the content doesn't show when row is highlighted

#ToS Share Code: https://tos.mx/IPrEhH

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);

Shareable Link

https://tos.mx/uXplYi

Credits:
I see the link to upload it, but how do I find the watchlist once it is imported?
 
1st time posting on the forum. Question: where can I learn about the TTM Squeeze indicator? What does B46 vs 5L means? Any link/resource to read more on this? Thanks

.....should have start from the top....
  • Bright Red: The stock is in Buy zone
  • Dark Red: Market compression is currently in this time period. The number reveals the amount of dots on your TTM Squeeze indicator.
  • Dark Green: The squeeze has fired. The number notes how many dots (up to 5) and whether the squeeze signaled Long or Short.
  • Black: No squeeze on this time frame
Ok, so B46 vs B32 how is interpreted (bright red) + white font? Which one will see more action?
Dark RED - see, 9,8,7,3, 2, 10, 11, 17? How I work with these?
A 5L vs a 3L what is the meaning?

Finally, how do I check to see the time setting (min, h, day, week)?

Thanks...looking for answers through the posts but just in case if you can help me understand that is great!
 
Last edited:
@Hoinar @lovelygirl
  • A white B bright red background: The stock is in Buy zone. A squeeze lasts longer than 5 bars, might result in a greater expansion.
  • A dark red. The market is still contracting. The number represents the number of dots.
  • Green background w/ a L = Long. S=short
Interpretation is a personal choice, study how the indicator lines up w/ your other studies and your strategy. Review how it reacts on different timeframes, and with different equities.
 
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.
How can I scan for when when histogram is higher or lower from the last bar, Thanks
 
Anyone have a Indicator that turns the TTM squeeze Light Blue Blue Red and yellow bars into a Line? with over sold and over bought areas? This would be great TTM squeeze Really tracks the pattern of a stock well. Thank you
 
Anyone have a Indicator that turns the TTM squeeze Light Blue Blue Red and yellow bars into a Line? with over sold and over bought areas? This would be great TTM squeeze Really tracks the pattern of a stock well. Thank you

i assumed you wanted ttm squeeze histogram data, normalized to a new scale, 0 to 100.

it asks for over bought and over sold levels. defaults of 70, 30.
if the normalized ttm levels are above over bought, or below over sold, then a cloud is drawn.
line and clouds are cyan.


Ruby:
# ttm_normalized
# halcyonguy
# 21-12-18

declare lower;
#-----------------------------------------
#   find highest high
#-----------------------------------------
script hi_level {
input level = 0;
def barsBack = 1000;

#def high1 = if barnumber() == 1 then high else if high > high1[1] then high else high1[1];
def high1 = if barnumber() == 1 then level else if level > high1[1] then level else high1[1];

def high2 = if !IsNaN(close) and IsNaN(close[-1]) then high1 else high2[1];
def highline = if isNaN(close[-barsBack]) then high2[-barsBack] else Double.NaN;
plot zh = highline;
}


#-----------------------------------------
#  find lowest low
#-----------------------------------------
script lo_level {
input level = 0;
def barsBack = 1000;

#def low1 = if barnumber() == 1 then low else if low < low1[1] then low else low1[1];
def low1 = if barnumber() == 1 then level else if level < low1[1] then level else low1[1];

def low2 = if !IsNaN(close) and IsNaN(close[-1]) then low1 else low2[1];
def lowline = if isNaN(close[-barsBack]) then low2[-barsBack] else Double.NaN;
plot zl = lowline;
}


#-----------------------------------------
#  normalize
#-----------------------------------------
# start with a copy of code from post #1 https://usethinkscript.com/threads/how-to-plot-a-study-as-a-normalized-index-that-has-0-100-values-e-g-like-moneyflowindex.4289/
# plot a study as a normalized index that has 0-100% values   lmk99

script normalizePlot {
input hi = 0;
input lo = 0;
input data = close;
input RngMin = 0;
input RngMax = 100;

def en = if (hi == 0 or lo == 0 ) then 0 else 1;
# if en , then calc stuff
plot nr = if !en then double.nan else ((( RngMax - RngMin ) * ( data - lo )) / ( hi - lo )) + RngMin;
}


#-----------------------------------------
# main section
#-----------------------------------------
def bn = barnumber();
def na = double.nan;
# find the highest and lowest levels of original data

# read ttm data , instead of close

# -------------------------------
# TTM_Squeeze()
# ttm squeeze , default data
#input price = CLOSE;
#input length = 20;
#input nK = 1.5;
#input nBB = 2.0;
#input alertLine = 1.0;

#plot Histogram = Double.NaN;
#plot VolComp = Double.NaN;
#plot SqueezeAlert = Double.NaN;

def ttm_histo = TTM_Squeeze().Histogram;

# -------------------------------

def data = ttm_histo;

input new_rng_min = 0;
input new_rng_max = 100;

input over_Bought = 70;
input over_Sold = 30;

def hi;
def lo;
def nz;
if bn == 1 then {
  # call sub scripts to find highest and lowest prices on chart
#  hi = hi_level();
#  lo = lo_level();
  hi = hi_level(data);
  lo = lo_level(data);

  # rescale the close
  # normalizePlot( data hi, data lo, price (default is close), new Rng Min (default 0), new Rng Max (default 100) )
#  nz = normalizePlot( hi, lo, close);
#  nz = normalizePlot( hi, lo, data);
  nz = normalizePlot( hi, lo, data, new_rng_min, new_rng_max );

} else {
  hi = hi[1];
  lo = lo[1];
#  nz = normalizePlot( hi, lo, close);
  nz = normalizePlot( hi, lo, data, new_rng_min, new_rng_max );
}

#-----------------------
# plot normalized line
plot nz2 = nz;

# plot the highest and lowest levels of original data
input plot_highest_lowest_lines = no;
plot zhi = if plot_highest_lowest_lines then new_rng_max else na;
plot zlo = if plot_highest_lowest_lines then new_rng_min else na;
zhi.setdefaultcolor(color.gray);
zlo.setdefaultcolor(color.gray);

input show_label_original_data = yes;
addlabel(show_label_original_data, "Original data, Highest: " + hi + " , Lowest: " + lo, color.yellow);

input show_over_lines = yes;
plot z3 = if show_over_lines then over_Bought else na;
plot z4 = if show_over_lines then over_sold else na;
z3.setdefaultcolor(color.dark_gray);
z4.setdefaultcolor(color.dark_gray);

def bought_top = if nz > over_Bought then nz else na;
addcloud( bought_top, over_Bought, color.cyan, color.cyan);

def sold_bot = if nz < over_sold then nz else na;
addcloud( over_Sold , sold_bot, color.cyan, color.cyan);
#

normalized ttm and the normal ttm squeeze study
yQrVtDS.jpg

normalize code i started with
https://usethinkscript.com/threads/alternate-normalization-study-not-complex-for-thinkorswim.9067/

ttm squeeze study
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/T-U/TTM-Squeeze
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
165 Online
Create Post

Similar threads

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.
Back
Top