TTM Squeeze Format, Scan, Watchlist, Label For ThinkOrSwim

@gravity2726 The following code should work but you may want to add additional filters... There may be better ways to do this and I'll see what else I can come up with...

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

Using the same code, how to capture the first yellow histogram using the code? Thanks
 

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

HI Rad,

Using the same code, how to capture the first yellow histogram using the code? Thanks

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

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
 
Last edited by a moderator:
Looking for help with a Scan for TTM Squeeze fired please? This scan is for fired scan for one bar. I'm trying to get a scan for fired 2 and 3 bars. Any suggestions?

TTM_Squeeze()."SqueezeAlert" [1] is false and
TTM_Squeeze()."SqueezeAlert" [2] is false and
TTM_Squeeze()."SqueezeAlert" [3] is false and
TTM_Squeeze()."SqueezeAlert" [4] is false and
TTM_Squeeze()."SqueezeAlert" [5] is false and
TTM_Squeeze()."SqueezeAlert" [6] is false and
TTM_Squeeze()."SqueezeAlert" is true

With this scan above, it will show Stocks that are in the squeeze for 6 days, then fired. Thanks to Mandeep Bhullar on Youtube for this scan
 
Last edited:
I think what you need would be that. If I understand what you're asking properly.

#squeeze fired one bar:
TTM_Squeeze().SqueezeAlert[1] == 0 and TTM_Squeeze().SqueezeAlert == 1

#squeeze has fired two bars ago, so 2 green dots:
TTM_Squeeze().SqueezeAlert[2] == 0 and TTM_Squeeze().SqueezeAlert == 1

You get the formula now
 
I was working on some experimental code for watchlist with squeeze and RSI. its not loading for some scripts.
 
Last edited by a moderator:
@BenTen I was working on some experimental code for watchlist with squeeze and RSI. Can I message you somewhere as sometimes its not loading for some scripts.

I just mentioned this in another topic where a member was having similar issues... There are times, especially when working extensively on experimental code, when chart panels become corrupt... When this happens, detach the chart into a separate window, delete the window, and recreate from scratch... I've had to do this multiple times during complex indicator development as well as when multiple indicators have been repeatedly loaded and removed from the same chart panel...
 
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:
Hi and thank for this. I am new to watchlist customization so i don't know how to make this visible on my ToS. I imported the code but i cant get this watch list or column. Can you share how should I do that (I'm sure it's something basic that I'm missing :).
 
I use John Carter's TTM Label on price chart Label A, B and C. I would appreciate is anyone could help by adding the value of A, B & C to these Labels truncating it to 0.00 digits

Code:
#TTM_Label
declare upper;
def ttmwavea= TTM_Wave().wave1;
def ttmwaveb= ttm_wave().wave2high;
def ttmwavec= ttm_wave().wave2low;
AddLabel(yes, if ttmwavea > 0 then "A-Up" else "A-Dn", if ttmwavea > 0 then
Color.GREEN else Color.RED);
AddLabel(yes, if ttmwaveb > 0 then "B-Up" else "B-Dn", if ttmwaveb > 0 then
Color.GREEN else Color.RED);
AddLabel(yes, if ttmwavec > 0 then "C-Up" else "C-Dn", if ttmwavec > 0 then
Color.GREEN else Color.RED);
 

Attachments

  • 2021-04-16-TOS_CHARTS.png
    2021-04-16-TOS_CHARTS.png
    48 KB · Views: 514
@Born2Win You're not going to believe how easy your request is... If you examine the code you'll see...

Ruby:
#TTM_Label
declare upper;
def ttmwavea= TTM_Wave().wave1;
def ttmwaveb= ttm_wave().wave2high;
def ttmwavec= ttm_wave().wave2low;
AddLabel(yes, if ttmwavea > 0 then "A-Up = " + Round(ttmwavea, 2) else "A-Dn = " + Round(ttmwavea, 2), if ttmwavea > 0 then Color.GREEN else Color.RED);
AddLabel(yes, if ttmwaveb > 0 then "B-Up = " + Round(ttmwaveb, 2) else "B-Dn = " + Round(ttmwaveb, 2), if ttmwaveb > 0 then Color.GREEN else Color.RED);
AddLabel(yes, if ttmwavec > 0 then "C-Up = " + Round(ttmwavec, 2) else "C-Dn = " + Round(ttmwavec, 2), if ttmwavec > 0 then Color.GREEN else Color.RED);
 
Does anyone know how to create thinkscript code for stock alerts/scans where the TTM Squeeze Histogram color is cyan and the current bar's height is higher than the previous bar?
 
@GetRichOrDieTrying here is how that works as a Scan... You can then setup alerts based on the Scan results... This should be what you need...

Ruby:
def hist = reference TTM_Squeeze.Histogram;
# First Cyan Momentum Histogram Bar
plot scan = if hist > 0 and hist[1] < 0 and hist[2] < hist[1] then 1 else Double.NaN;
# Second Cyan Momentum Histogram bar
plot scan = if hist > 0 and hist[1] > 0 and hist[2] < 0 then 1 else Double.NaN;
 
Last edited by a moderator:
Code:
# adapted this label into 1 piece and made it change color after 6 dots.  Giving Back because I have learned so much already. ENJOY.

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;
# the original code here counted the number of green dots, so we comment this out and leave it here for safe-keeping
#def alertCount = if squeezeDots[1] == 0 and squeezeDots == 1 then 1 else if squeezeDots == 1 then alertCount[1] + 1 else 0;
# and here we have modified it to count the red dots
def alertCount = if squeezeDots[1] == 1 and squeezeDots == 0 then 1 else if squeezeDots == 0 then alertCount[1] + 1 else 0;
# NEXT FOUR ROWS COMMENTED OUT AND COMBINED THE LABEL.
# alertCount is the variable that keeps track of our red dots
# we can produce a label that displays Green or Red depending on the state of the squeeze
# AddLabel(yes, "SQ_RED", if alertCount > 0 then Color.GREEN else Color.WHITE);
# next, we can produce a label that displays the number of red dots
AddLabel(yes, Concat("SQ_RED DOTS : ", alertCount), if alertCount >=6 then Color.RED else Color.ORANGE);
 
I use John Carter's TTM Label on price chart Label A, B and C. I would appreciate is anyone could help by adding the value of A, B & C to these Labels truncating it to 0.00 digits

Code:
#TTM_Label
declare upper;
def ttmwavea= TTM_Wave().wave1;
def ttmwaveb= ttm_wave().wave2high;
def ttmwavec= ttm_wave().wave2low;
AddLabel(yes, if ttmwavea > 0 then "A-Up" else "A-Dn", if ttmwavea > 0 then
Color.GREEN else Color.RED);
AddLabel(yes, if ttmwaveb > 0 then "B-Up" else "B-Dn", if ttmwaveb > 0 then
Color.GREEN else Color.RED);
AddLabel(yes, if ttmwavec > 0 then "C-Up" else "C-Dn", if ttmwavec > 0 then
Color.GREEN else Color.RED);
Born2Win what exactly is this label used for. I use the TTM Squeeze also I don't get it. Please educate me.
 
Hi John,
I don't use the indicator only these labels. In one of the class I took with John carter he said to look at Wave C. So on smaller timeframes if Wave C is above 0 and green it is an indication the stock is rising.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
211 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