TTM Squeeze Format, Scan, Watchlist, Label For ThinkOrSwim

Here ya go. Paste this into the thinkscript editor for study scan. Won't need to add any conditions. I coded it in

Code:
# Momentum Squeeze
# Mobius
# Added Squeeze Label with directional color
# Label is green when momentum is ascending, red when descending

declare lower;

input lengthe = 20; #hint length: Length for average calculation
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;

   def K = (Highest(High, lengthe) + Lowest(low, lengthe)) /
               2 + ExpAverage(close, lengthe);
  def Momo = Inertia(price - K / 2, lengthe);

def SD = StDev(close, lengthe);
def Avg = Average(close, lengthe);
def ATR = Average(TrueRange(high, close, low), lengthe);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (AtrMult * ATR);

def Squeeze = SDup < ATRup;
        
def zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

Plot breakout = squeeze[1] is true and squeeze is false;
 
thanks !!! i will try it out.

Thanks wtf_dude for your work !!! but its not exactly what i was looking for .... what i am wanting is when the red dot changes to green .. so like the picture, when the red dots , change to green...

also would be super cool, to have a secondary condition of a scan that said when the momentum histogram color changed from dark green to dark blue (upside).... or from red to yellow (downside)

think you could put something together? is it possible?

w1D8g58.jpg
 
@shoecharlie The default setting when you copy paste in a new scanner is for day. You would need to manually change over the D to 1h box in the upper left hand corner. I checked that it's firing off correctly on the day scan

Ok, so did an overhaul since I haven't really seen a more advanced squeeze scanner.
This will give you a scan for:
A breakout either direction, breakout down, breakout up, or trend(color) reversals on bull and bear sides.

Be sure to copy the code in the charts tab to make it a study, don't copy it into the scan tab.
When you add the saved study into the scanner:
Pick the drop down of whatever you want to scan and pick "is true"
Be sure to change the aggregation box to whatever time frame you want

Code:
# AdvancedSqueezeScanner
# Momentum Squeeze open coding by Moebius, based on John Carter
# Scan by WTF_Dude
# Added Squeeze Label with directional color
# Label is green when momentum is ascending, red when descending

declare lower;

input length = 20; #hint length: Length for average calculation
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;

   def K = (Highest(High, length) + Lowest(low, length)) /
               2 + ExpAverage(close, length);
  def Momo = Inertia(price - K / 2, length);

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (AtrMult * ATR);

def Squeeze = SDup < ATRup;
        
def zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

def momobullup = Momo > Momo[1] and Momo > 0;
def momobulldown = Momo > 0 and Momo < Momo[1];
def momobeardown =  Momo > Momo[1] and Momo > 0;
def momobearup = Momo < 0 and Momo > Momo[1];


Plot Breakout = squeeze[1] is true and squeeze is false;
plot BreakoutBull = squeeze[1] is true and squeeze is false and momobullup;
plot BreakoutBear = squeeze[1] is true and squeeze is false and momobulldown;

Plot BullTrendChange = momobulldown is true and momobulldown[1] is false;
Plot BearTrendChange = momobearup is true and momobearup[1] is false;
 
I am unsure what you mean to download it to the chart tab... i have no idea where to do that ....can you point me in the right direction?
 
@shoecharlie If you're running a scan, you're on the scan tab. If you want to look at your charts, you go to the chart tab. The menu where you pick what studies you want on your chart, there's a button to create a new study, and that's where you paste that code in and give it a name like SqueezeScan. Then when you load a custom study scan you can pick that option
 
A get a message it says at least one condition needs to be corrected.
That would mean you're setting up the scan incorrectly. The code itself doesn't have a condition. You want the study to be matched as "is true" and that would be the condition
 
That would mean you're setting up the scan incorrectly. The code itself doesn't have a condition. You want the study to be matched as "is true" and that would be the condition
I think a lot of people here are used to the #comment out instead of setting the true/false from the menu...hence the confusion.
 
I think a lot of people here are used to the #comment out instead of setting the true/false from the menu...hence the confusion.
Right, I get it, I just find that it's safer to make a drop down option menu rather than risk messing with code to pick a condition.
 
Right, I get it, I just find that it's safer to make a drop-down options menu rather than risk messing with code to pick a condition.

I'm too used to copying & pasting the code in the editor than the drop-down menu, but how's that down? Add study, custom, and then what?
 
I'm too used to copying & pasting the code in the editor than the drop-down menu, but how's that down? Add study, custom, and then what?
Then select whatever you named my study as on the chart tab. Then on the "add conditions" screen it will give you a drop down menu with different options to choose from like squeeze breakout bull, squeeze breakout bear, bull trend change, etc. Select the option you want to scan for and then choose "is true" in the middle column. Good to go
 
Hi @wtf_dude ...quick question...do I delete the "CLOSE" condition on the condition wizard tab or keep that in the code also?? (ie...plot Data = close and 100 is true;) or......do I delete the close condition and just keep the "is true" value...(plot Data = 100 is true;)....and also this is a lower study and you will see colored triangular arrows correct? thanks Joseph
 
Man, I threw this together hoping it would make things EASIER, not more complicated lol.
Joseph, this is a scanner, not an indicator. There is already an indicator to use in TOS if you want (TTM_Squeeze)

Check out the image below to see how you would load this up. All you would change is the Plot dropdown. You can pick trend change, breakout to the upside, downside, etc. HOPEFULLY, this should clear everything up haha

For some reason, its not letting me upload the image itself so just check the link....

lFLaJIi.jpg
 
@wtf_dude LOLnah it's just me...I am new to this so I first try to figure it out on my own and then if I can't I'll finally give in and ask...I went back and forth and read and reread and jumped from chart to scanner but couldn't get it right...but thanks so much for your time and help its greatly appreciated!

K got it...thanks...here it is if people are still confused...

STEP 1) Go to CHARTS...click on the Bunsen burner icon STUDIES and open it...then bottom left hand side of chart that pops up click on CREATE....top left rename newstudy to say TOS_SQUEEZE_SCANNER then copy and paste from post # 7 above in the same window highlighting the "plot data=close" and pasting code....then OK and Ok...

STEP 2) Go to SCAN tab and click on it...clear all of the filters by pressing X on right hand side...then open a new FILTER by clicking on FILTER then STUDY...then click on the box that pops up (should be ADX Crossover) click on it then scroll down to CUSTOM...then click on it..then new box opens up with ads crossover and click on DELETE...which will remove that option...then bottom left click on ADD CONDITION...then SELECT CONDITION then STUDY....THEN SCROLL DOWN TO WHATEVER YOU NAMED THE "CHART" "STUDIES" FILE (in this example it would be TOS_SQUEEZE_SCANNER)...click on that then a menu will pop up and then click on "IS TRUE" then click SAVE button...then top left of original box look for AGGREGATION BUTTON (should have a D on it for DAY...) and click on in then look for aggregation period that you want ...I use 3 and 5 minute period...then click OK and that's it...and if it was done correctly you should see..."TOS_SQUEEZE_SCANNER breakout "is true" in the filter scan box....then to save it right above that box on the right hand side click on the 3 lines hamburger and click on SAVE SCAN QUERY..and name it whatever you want...you will then also see (in my example TOS_SQUEEZE_SCANNER) also in your WATCHLISTS WHEN YOU SCROLL THRU THEM YOU WILL SEE THE NEW SCANNER...GOOD LUCK AND THANKS TO WTF :)
 
Hi @wtf_dude not sure if I'm posting this in the right place, hoping you can help ...
Looking for code for a study (to then put in a scan) where TTM Squeeze histogram goes positive while still in a squeeze.
Thanks if you can help!
 
Just throw these 2 lines in the code and it will give you 2 additional dropdown functions for that:

plot SqueezeChangetoBull = beartrendchange and squeeze is true;
plot SqueezeChangetoBear = bulltrendchange and squeeze is true;
 
@wtf_dude sorry, I'm a newbie. Trying to figure this out. Where exactly would I put those 2 lines of code into? Tried putting into the TTM Squeeze script but it won't let me.
 
@wtf_dude sorry, I'm a newbie. Trying to figure this out. Where exactly would I put those 2 lines of code into? Tried putting into the TTM Squeeze script but it won't let me.
Oh no, you have to put it with the code I posted earlier. Just create a new study, call it something like AdvancedSqueezeScanner and paste all of this and then use it on the scan tab. Should be go to go.

Code:
# AdvancedSqueezeScanner
# Momentum Squeeze open coding by Moebius, based on John Carter
# Scan by WTF_Dude
# Added Squeeze Label with directional color
# Label is green when momentum is ascending, red when descending

declare lower;

input length = 20; #hint length: Length for average calculation
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;

   def K = (Highest(High, length) + Lowest(low, length)) /
               2 + ExpAverage(close, length);
  def Momo = Inertia(price - K / 2, length);

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (AtrMult * ATR);

def Squeeze = SDup < ATRup;
        
def zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

def momobullup = Momo > Momo[1] and Momo > 0;
def momobulldown = Momo > 0 and Momo < Momo[1];
def momobeardown =  Momo > Momo[1] and Momo > 0;
def momobearup = Momo < 0 and Momo > Momo[1];



Plot BreakoutEitherDirection = squeeze[1] is true and squeeze is false;
plot BreakoutBull = squeeze[1] is true and squeeze is false and momobullup;
plot BreakoutBear = squeeze[1] is true and squeeze is false and momobulldown;

Plot BullTrendReversal = momobulldown is true and momobulldown[1] is false;
Plot BearTrendReversal = momobearup is true and momobearup[1] is false;

plot Squeeze_ChangetoBull = BearTrendReversal and squeeze is true;
plot Squeeze_ChangetoBear = BullTrendReversal and squeeze is true;

#End Code
 
@wtf_dude This code also doesn't work, TOS. says "
No such variable: Momo at 13:28
No such variable: Momo at 13:40
No such variable: Momo at 14:18
No such variable: Momo at 14:31"
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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