TTM Squeeze Watchlist Column for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
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



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: http://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


Credits:
 
Last edited:
B

BC1106

New member
2019 Donor
Warehouse
Code:
def squeeze = if(reference BollingerBands()."upperband" - KeltnerChannels()."Upper_Band")<0 then 1 else 0;

def insqueeze = if squeeze then insqueeze[1] + 1 else 0;

def fired = if !squeeze then fired[1]+1 else 0;

def direction = if (fired == 1 , if( TTM_Squeeze() > TTM_Squeeze()[1] , 1 , 0 ),  direction[1]);

plot result = if insqueeze > 0 then insqueeze else if fired >0 and fired <8 then fired else 0;

AddLabel(yes, Concat(if insqueeze>0 then "Squeeze: " else if fired >0 and fired <8 then Concat("FIRED: ", if direction then "? " else "? ") else "", result), if insqueeze>0 then color.white else color.black);

AssignBackgroundColor( if insqueeze>0 then color.red else if fired>0 and fired <8 then color.green else color.black);

def squeeze = if(reference BollingerBands()."upperband" - KeltnerChannels()."Upper_Band")<0 then 1 else 0;

def insqueeze = if squeeze then insqueeze[1] + 1 else 0;

def fired = if !squeeze then fired[1]+1 else 0;

def direction = if (fired == 1 , if( TTM_Squeeze() > TTM_Squeeze()[1] , 1 , 0 ),  direction[1]);

plot result = if insqueeze > 0 then insqueeze else if fired >0 and fired <8 then fired else 0;

AddLabel(yes, Concat(if insqueeze>0 then "Squeeze: " else if fired >0 and fired <8 then Concat("FIRED: ", if direction then "? " else "? ") else "", result), if insqueeze>0 then color.white else color.black);

AssignBackgroundColor( if insqueeze>0 then color.red else if fired>0 and fired <8 then color.green else color.black);
This is the code i use for my watchlist column, very similar to yours in fact it may be the exact same, but Im not 100% sure since i know nothing about coding. But visually its slightly different and you can customize to whatever timeframe you want, it just wont say if it fired long or short.
 
T

tomsk

Well-known member
VIP
Saw some discussions on squeeze watchlists on some other threads, thought I'd ahre what I have.
Here's a version from my files

Code:
# TTM Squeeze Watchlist
# TSL
# 11.13.2019

input price = close;
input length = 20;
input nK = 1.5;
input nBB = 2.0;
input alertLine = 1.0;

def squeezeDots = TTM_Squeeze(price, length, nK, nBB, alertLine).SqueezeAlert;
def alertCount = if squeezeDots[1] == 0 and squeezeDots == 1 then 1 
                 else if squeezeDots == 1 then alertCount[1] + 1 
                 else 0;
plot data = alertCount;
data.SetDefaultColor(Color.BLACK);

def squeezeHistogram = TTM_Squeeze(price, length, nK, nBB, alertLine).Histogram;
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);
 
Rojo Grande

Rojo Grande

Member
Hello Ben,
In the original TTM squeeze, it's possible to change the length from the default of 20 to your liking. Can adjustable length be added to this study?

Thank you.
 
Rojo Grande

Rojo Grande

Member
Hi Horserider, I was looking for that and cannot find it (I am referring to the code in post #1 above) not to tomsk in post #3. I did however find another TTM squeeze alert that I was able to find and change the length, so no need to alter anything on my account. Again, thanks to all who contribute to the best site I know.
 
E

ext99k

New member
Dead link for the TOS hosted shared file -- please reupload? Thanks a lot!
 
BenTen

BenTen

Administrative
Staff
VIP
@ext99k ThinkorSwim shareable links are not working right now.
 
BenTen

BenTen

Administrative
Staff
VIP
@ext99k Links are temporarily down. But you can import it by clicking on the Setup option (top right hand-corner of your platform) > Open Shared Item... > Paste the shareable link.
 
S

sbtyme

New member
@BenTen - Thanks for this. I'm new to Think Script. I've uploaded the indicator to my watch list, no problem but I don't see how to determine/switch which time frame I want the indicator reflect for the squeeze (ex- 5 min or 30 min or.....).
Thanks in advance.
 
S

StocksNOptions432

New member
this is perfect, is there any way this can be upgraded to use the sqz pro version?
 
BenTen

BenTen

Administrative
Staff
VIP
@StocksNOptions432 I would recommend reaching out to the provider of the squeeze pro version and get their support. We don't have access to the script.
 
S

StocksNOptions432

New member
@StocksNOptions432 I would recommend reaching out to the provider of the squeeze pro version and get their support. We don't have access to the script.
sure, thank you Ben
 
T

TIGER202020

New member
Ben, thank you for the script and load it for my watchlist. But What's the time frame for the TTM squeeze being used for the watchlist? where can we set up timeframe?

Never mind. it can be modified when column is added.
 
Last edited by a moderator:

Top