TTM Squeeze Format, Scan, Watchlist, Label For ThinkOrSwim

wtf_dude

Active 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!
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
 

SleepyZ

Well-known member
VIP
Lifetime
@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);
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
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!
 

Diamondlil

New member
@wtf_dude

I use the Advance Squeeze Alert (breakout bull) all the time, paired with other indicators. I have observed that when there are 2 to 3 advanced squeeze alerts in sequence, say within 5-10 candles, it is a pretty strong bullish signal.
Just wondering how I can set up a scan to show me charts where there are at least 2 or 3 advance squeeze alerts that have appeared within the last 5-10 candles. Can you advise please?
Thanks in advance.
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@wtf_dude

I use the Advance Squeeze Alert (breakout bull) all the time, paired with other indicators. I have observed that when there are 2 to 3 advanced squeeze alerts in sequence, say within 5-10 candles, it is a pretty strong bullish signal.
Just wondering how I can set up a scan to show me charts where there are at least 2 or 3 advance squeeze alerts that have appeared within the last 5-10 candles. Can you advise please?
Thanks in advance.
https://usethinkscript.com/threads/tos-ttm-squeeze-scan-watchlist-labels.2751/page-10#post-76308

Here is a Great Hack For Searching Those Huge Threads for your answer.
 

dsohi11

New member
VIP
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:

BIGMONEY

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.

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?
 

lovelygirl

New member
@BenTen when it is in bright red, for example "B4" on daily, does that mean it's a bull signal that you should buy long, or that it is ready to squeeze any day now?
 

Hoinar

New member
VIP
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:

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@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.
 

dsohi11

New member
VIP
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
 

dmillz

Member
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
 

halcyonguy

Well-known member
VIP
Lifetime
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
 

ProfessorJedi

New member
Hey all,

I'm trying to figure out how to re-create watchlist, specifically how to get the histogram color from the TTM Squeeze indicator to show up in the watchlist box. The other box is showing the color or Stacked EMA indicator. I think if I can get some help how to make the histogram color work, I might be able to figure out the Stacked EMA indicator.

Thanks in advance for any help!

Cheers,

Mike

squeeze.png
 

ehollowaty

New member
I think this guy's video will get you what you need (?):

Code:
input price = CLOSE;
input length = 20;
input nK = 1.5;
input nBB = 2.0;
input alertLine = 1.0;
def squeezeHistogram = TTM_Squeeze(price, length, nK, nBB, alertLine).Histogram;
plot hist = if squeezeHistogram>= 0 then
if squeezeHistogram> squeezeHistogram[1] then 2 else 1
else if squeezeHistogram < squeezeHistogram[1] then -2 else -1; assignBackgroundColor(if squeezeHistogram >= 0 then
if squeezeHistogram > squeezeHistogram[1] then color.CYAN else color.BLUE
else if squeezeHistogram < squeezeHistogram[1] then color.RED else color.YELLOW); hist.assignvaluecolor(if squeezeHistogram >= 0 then
if squeezeHistogram > squeezeHistogram[1] then color.CYAN else color.BLUE
else if squeezeHistogram < squeezeHistogram[1] then color.RED else color.YELLOW);
mod edit: added the above source code discussed in the below text
 
Last edited by a moderator:

TraderTheJoker

New member
When I put this in thinkscript editor in scan it says there is an error. I based on comments above if someone can help just trying to scan histogram increasing from previous bar above 0. If someone can help appreciate it kindly thank you.

def hist = reference TTM_Squeeze.Histogram;
plot scan = if hist > 0 and hist > hist[1]
 

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