@Sagar That is a snippet to add labels to your chart, I don't think it has to do anything with the scanner. Maybe this thread will help https://usethinkscript.com/threads/scanner-for-ttm-squeeze-fired.2751/
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
def S = reference TTM_Squeeze().SqueezeAlert;
def H = reference TTM_Squeeze().Histogram;
plot Arrow = !S[1] and S and H > 0 and H > H[1];
Arrow.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
Arrow.SetLineWeight(3);
Arrow.SetDefaultColor(color.cyan);
@wtf_dude wondering how I can scan for advanced squeeze alert (breakout bull) ONLY if above ATR? Thanks in advance.
For the scan, though, I would want candidates that have printed only one dark blue or one yellow bar on the daily. It would go on my watchlist for confirmation of a second bar print the following day. I would very much appreciate any help with this scan. Thank you!
# Advanced Squeeze Scanner v2.0
# Momentum Squeeze basis coding by Moebius, based on John Carter
# Scanner by WTF_Dude. Mods on 9.9.20
# 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 ATR_mult = 1.5;
input ATR_length = 14;
input Move_Threshold = 50;
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), ATR_length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (Atr_Mult * 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 > Move_Threshold;
def momobulldown = Momo > 0 and Momo < Momo[1];
def momobeardown = Momo > Momo[1] and Momo >(-Move_Threshold);
def momobearup = Momo < 0 and Momo > Momo[1];
def change = absvalue(close - close[1]);
# Squeeze breaks out in EITHER direction
Plot Breakout = squeeze[1] is true and squeeze is false;
# Breakout of squeeze to the upside
plot BreakoutBull = squeeze[1] is true and squeeze is false and momobullup;
# Breakout of squeeze to the downside
plot BreakoutBear = squeeze[1] is true and squeeze is false and momobulldown;
# Breakout of squeeze to the upside with move larger than ATR
plot BreakoutBullATRplus = squeeze[1] is true and squeeze is false and momobullup and change>ATR;
# Breakout of squeeze to the downside with move larger than ATR
plot BreakoutBearATRplus = squeeze[1] is true and squeeze is false and momobulldown and change>ATR;
# Bull trend reverses and turns down while the color changes to dark blue
Plot BullTrendReversal = momobulldown is true and momobulldown[1] is false;
# Bear trend reverses and turns up while the color changes to yellow
Plot BearTrendReversal= momobearup is true and momobearup[1] is false;
# Zero line turns red and becomes a squeeze
plot EnteringSqueeze = Squeeze[1] is false and Squeeze is true;
alright, since printing confirmation bars is a little bit tricky to do by default I had to do a recode. This is just for bull breakouts, but you can add how many extra bars ago you want the squeeze breakout to have happened . You can also change the percent threshold you want the change to be between now and however many bars ago you chose. I also made it so there must have been at least 3 periods/days of squeeze to count (right now there are crap tons of squeeze "breakouts" that were only in a squeeze for one day.Hi @wtf_dude , thank you so much for sharing this. I've been trying out numerous different setting combos to get what I want, but not having luck. What are the settings you'd suggest if I'm looking for stocks that were on a red dot(s), and are now two cyan bars into a switch to green dots, and the price action is unusual for the stock (e.g., usually, within a bar, price goes +/-0.2%, but within these two most recent cyan bars, price moved up +0.6%)? I'm basically looking for the start of a strong breakout. TIA!
# Advanced Squeeze Bull Breakout v1.0
# WTF_Dude on 9.10.20
input length = 20; #hint length: Length for average calculation
input price = close;
input SDmult = 2.0;
input ATR_mult = 1.5;
input ATR_length = 20;
input Extra_bars= 1;
input percent_move = .06;
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), ATR_length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (Atr_Mult * 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 change =(close - close[Extra_bars]);
def PercentChg = 100 * (price / price[Extra_bars] - 1);
# Squeeze breakout to the upside 2 bars ago with move greater than percent_move
plot BreakoutBull = squeeze[Extra_bars+1] is true and squeeze[Extra_bars+2] is true and squeeze[Extra_bars+3] is true and squeeze [Extra_bars] is false and squeeze is false and momobullup and percentchg>= percent_move;
How do we make this count on a different time metric?Use this in a column in your watch list:
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);
Once you have the study loaded as one of the filters, the right side of the row will have a square box with D in it (day is default) click on the box and you can change the time frame. BE SURE to check or uncheck the EXT box if you want the extended hours included with the scan or your results will look like a bunch of false signals.How do we make this count on a different time metric?
alright, since printing confirmation bars is a little bit tricky to do by default I had to do a recode. This is just for bull breakouts, but you can add how many extra bars ago you want the squeeze breakout to have happened . You can also change the percent threshold you want the change to be between now and however many bars ago you chose. I also made it so there must have been at least 3 periods/days of squeeze to count (right now there are crap tons of squeeze "breakouts" that were only in a squeeze for one day.
PLEASE REMEMBER: take this code and save it as a study on the CHART tab. Then on the SCAN tab, you will then load it up as a condition >> add study >>custom and select whatever name you saved it as on charts. All the default settings are the ones you requested, so just load it up, leave the inputs as is, select the middle box as "is true" and leave "within bars" as 1
Code:# Advanced Squeeze Bull Breakout v1.0 # WTF_Dude on 9.10.20 input length = 20; #hint length: Length for average calculation input price = close; input SDmult = 2.0; input ATR_mult = 1.5; input ATR_length = 20; input Extra_bars= 1; input percent_move = .06; 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), ATR_length); def SDup = Avg + (SdMult * Sd); def ATRup = Avg + (Atr_Mult * 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 change =(close - close[Extra_bars]); def PercentChg = 100 * (price / price[Extra_bars] - 1); # Squeeze breakout to the upside 2 bars ago with move greater than percent_move plot BreakoutBull = squeeze[Extra_bars+1] is true and squeeze[Extra_bars+2] is true and squeeze[Extra_bars+3] is true and squeeze [Extra_bars] is false and squeeze is false and momobullup and percentchg>= percent_move;
This should work. Not much firing atm from what I can tell@wtf_dude do you happen to have a Bear version of this scanner? Still going through the other scanners to see what the major differences are and what sort of results are generated. Thanks.
# Advanced Squeeze Bear Scan
# WTF_Dude 9.15.20
input length = 20; #hint length: Length for average calculation
input price = close;
input SDmult = 2.0; #standard deviations
input ATR_mult = 1.5; #average true range multiplier
input ATR_length = 20; # length used for calculating ATR
input Extra_bars= 1; #extra bars allows you to select how many extra bars needed to confirm the breakout
input percent_move = .06; #how big of a percent move to confirm the breakout
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), ATR_length);
def SDup = Avg + (SdMult * Sd);
def ATRup = Avg + (Atr_Mult * ATR);
def Squeeze = SDup < ATRup;
def zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;
def momobulldown = Momo < Momo[1] and momo<0;
def change = (close - close[Extra_bars]);
def PercentChg = absvalue(100 * (price / price[Extra_bars] - 1));
# Squeeze breakout to the upside 2 bars ago with move greater than percent_move
plot BreakoutBear = squeeze[Extra_bars+1] is true and squeeze[Extra_bars+2] is true and squeeze[Extra_bars+3] is true and squeeze [Extra_bars] is false and squeeze is false and momobulldown and percentchg>= percent_move;
# 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];
def BullTrendReversal = momobulldown is true and momobulldown[1] is false;
def BearTrendReversal = momobearup is true and momobearup[1] is false;
#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)
Not sure why you would need the code changed to add the SLM as a filter? You just have them loaded as 2 different studies on the same scan page and it will use both. Save that scan and you're good to go. What am I missing?@wtf_dude Thanks for the scanner...Yeah I actually went through the whole thread here and tested the results from EVERY scanner condition you made thus far individually...I agree that not much results with the last two scanners...The best results that I personally found was from the scanner from your post #4.
I actually was using the different conditions of that scanner as filters for the Slim Ribbon scanner @diazlaz made here:
https://usethinkscript.com/threads/slim-ribbon-indicator-for-thinkorswim.245/page-3#post-21700
Your Squeeze Scanner with the combination of the Slim Ribbon scanner on a DAILY timeframe actually filtered out and generated some great results. Would it be possible for you to combine ALL BULL/BEAR conditions from scanner in your post #4 to scan either BULLISH or BEARISH scans?
With my limited skill set I don't feel confident in doing this but perhaps you can set the scanner to scan for multiple BULLISH or BEARISH conditions at once...IF so that would be awesome! But would you be able to make a scan using the #comment out method instead of the wizard...? Its less confusing at least to me...Here is what I tried to do...by changing plot to def but I can't figure out how to plot "both" or "and" conditions since you have 3 different conditions for each BULL/BEAR. If this is not too much work try this out with the SLIM Ribbon scanner I linked to...with the following plot options at the end of the script:
def both = bullish or bearish;
def both = neutral or bullish;
def both = neutral or bearish;
#plot results = bullish; #bullish scan
#plot results = bearish; #bearish scan
plot results = both; #include both bullish and bearish or neutral
#plot resultsChanged = bullish and bullish[0] != bullish[1]; # instant bullish change scan
#plot resultsChanged = bearish and bearish[0] != bearish[1]; #instant bearish change scan
I like to scan the SLIM Ribbon with both neutral or bullish or neutral and bearish conditions...
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]; def BullTrendReversal = momobulldown is true and momobulldown[1] is false; def BearTrendReversal = momobearup is true and momobearup[1] is false; #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)
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
C | TTM Squeeze Fire Signal - Another Take! | Indicators | 19 | |
TTM Squeeze Clouds Indicator for ThinkorSwim | Indicators | 42 | ||
D | TTM Trend Source Code For ThinkOrSwim | Indicators | 2 | |
H | My version of the TTM Trend for ThinkorSwim | Indicators | 12 | |
T | Beardy Squeeze Pro For ThinkOrSwim | Indicators | 25 |
Start a new thread and receive assistance from our community.
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.
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.