Clouds with TTM Squeeze Indicator for ThinkorSwim

Welkin

Welkin

Member
I saw a video with John F. Carter explaining that the squeeze is when the Bollinger Bands cross inside of Keltner Channels. I decided to script it into cloud form. It appears this would have great applications for finding ranges to scalp as well.

thinkScript Code

Code:
#MTF Squeeze Clouds
#[email protected]

declare weak_volume_dependency;
input EnableAggregation2 = yes;
input EnableAggregation3 = yes;
input Aggregation1 = AggregationPeriod.FIVE_MIN;
input Aggregation2 = AggregationPeriod.THIRTY_MIN;
input Aggregation3 = AggregationPeriod.HOUR;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input factor = 1.5;
input trueRangeAverageType = AverageType.SIMPLE;

def NA = Double.NaN;
def price1 = close("Period" = Aggregation1);
def price2 = close("Period" = Aggregation2);
def price3 = close("Period" = Aggregation3);

#BollingerBands
def sDev1 = StDev(data = price1[-displace], length = length);
def sDev2 = StDev(data = price2[-displace], length = length);
def sDev3 = StDev(data = price3[-displace], length = length);

def MidLine1 = MovingAverage(averageType, data = price1[-displace], length = length);
def MidLine2 = MovingAverage(averageType, data = price2[-displace], length = length);
def MidLine3 = MovingAverage(averageType, data = price3[-displace], length = length);

def BLowerBand1 = MidLine1 + Num_Dev_Dn * sDev1;
def BLowerBand2 = MidLine2 + Num_Dev_Dn * sDev2;
def BLowerBand3 = MidLine3 + Num_Dev_Dn * sDev3;

def BUpperBand1 = MidLine1 + Num_Dev_up * sDev1;
def BUpperBand2 = MidLine2 + Num_Dev_up * sDev2;
def BUpperBand3 = MidLine3 + Num_Dev_up * sDev3;

#Keltner Channels
def shift1 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = Aggregation1), close("Period" = Aggregation1), low("Period" = Aggregation1)), length);
def shift2 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = Aggregation2), close("Period" = Aggregation2), low("Period" = Aggregation2)), length);
def shift3 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = Aggregation3), close("Period" = Aggregation3), low("Period" = Aggregation3)), length);

def average1 = MovingAverage(averageType, price1, length);
def average2 = MovingAverage(averageType, price2, length);
def average3 = MovingAverage(averageType, price3, length);

def Avg1 = average1[-displace];
def Avg2 = average2[-displace];
def Avg3 = average3[-displace];

def KUpperBand1 = average1[-displace] + shift1[-displace];
def kUpperBand2 = average2[-displace] + shift2[-displace];
def kUpperBand3 = average3[-displace] + shift3[-displace];

def KLowerBand1 = average1[-displace] - shift1[-displace];
def KLowerBand2 = average2[-displace] - shift2[-displace];
def KLowerBand3 = average3[-displace] - shift3[-displace];


#Squeeze upper and lower crossovers
def BollKeltUB1DiffH = if KUpperBand1 - BUpperBand1 <= 0 then NA else KUpperBand1;
def BollKeltUB1DiffL = if KUpperBand1 - BUpperBand1 <= 0 then NA else BUpperBand1;
def BollKeltLB1DiffH = if BLowerBand1 - KLowerBand1 <= 0 then NA else BLowerBand1;
def BollKeltLB1DiffL = if BLowerBand1 - KLowerBand1 <= 0 then NA else KLowerBand1;

def BollKeltUB2DiffH = if !EnableAggregation2 then NA else if KUpperBand2 - BUpperBand2 <= 0 then NA else KUpperBand2;
def BollKeltUB2DiffL = if !EnableAggregation2 then NA else if KUpperBand2 - BUpperBand2 <= 0 then NA else BUpperBand2;
def BollKeltLB2DiffH = if !EnableAggregation2 then NA else if BLowerBand2 - KLowerBand2 <= 0 then NA else BLowerBand2;
def BollKeltLB2DiffL = if !EnableAggregation2 then NA else if BLowerBand2 - KLowerBand2 <= 0 then NA else KLowerBand2;

def BollKeltUB3DiffH = if !EnableAggregation3 then NA else if KUpperBand3 - BUpperBand3 <= 0 then NA else KUpperBand3;
def BollKeltUB3DiffL = if !EnableAggregation3 then NA else if KUpperBand3 - BUpperBand3 <= 0 then NA else BUpperBand3;
def BollKeltLB3DiffH = if !EnableAggregation3 then NA else if BLowerBand3 - KLowerBand3 <= 0 then NA else BLowerBand3;
def BollKeltLB3DiffL = if !EnableAggregation3 then NA else if BLowerBand3 - KLowerBand3 <= 0 then NA else KLowerBand3;

#Cloud shading
AddCloud(BollKeltUB1DiffH, BollKeltUB1DiffL, Color.YELLOW, Color.YELLOW);
AddCloud(BollKeltLB1DiffH, BollKeltLB1DiffL, Color.YELLOW, Color.YELLOW);

AddCloud(BollKeltUB2DiffH, BollKeltUB2DiffL, Color.DARK_ORANGE, Color.DARK_ORANGE);
AddCloud(BollKeltLB2DiffH, BollKeltLB2DiffL, Color.DARK_ORANGE, Color.DARK_ORANGE);

AddCloud(BollKeltUB3DiffH, BollKeltUB3DiffL, Color.RED, Color.RED);
AddCloud(BollKeltLB3DiffH, BollKeltLB3DiffL, Color.RED, Color.RED);
Shareable Link: http://tos.mx/SZGo6Qe

clouds with ttm_squeeze to show correspondence


 
Last edited:
W

wen

New member
hello. the cloud barely see it, how can I make it bigger? thanks!
 
Welkin

Welkin

Member
hello. the cloud barely see it, how can I make it bigger? thanks!
I think if the cloud is too small it is probably not a very significant squeeze. and I wouldn't want them to be too visually intrusive, personally.

But here you go, I made it so that you can artificially inflate the squeeze cloud's top and bottom values, the inside values will stay the same.

just toggle inflatesqueezeclouds to yes and change the inflatevalue
1.0 = 100% increase




http://tos.mx/uC4rgih

 
Last edited:
W

wen

New member
I think if the cloud is too small it is probably not a very significant squeeze. and I wouldn't want them to be too visually intrusive, personally.

But here you go, I made it so that you can artificially inflate the squeeze cloud's top and bottom values, the inside values will stay the same.

just toggle inflatesqueezeclouds to yes and change the inflatevalue
1.0 = 100% increase



Code:
#Bollinger and Keltner SQUEEZE 1.1
#[email protected]
#added a toggle for inflating the outer values to increase size if you want them more visible. the inside values remain the same.
def NA = Double.NaN;
input inflatesqueezeclouds = no;
input inflatevalue = 1.0;

#Bollinger and Keltner Bands
plot BollUpBand1 = BollingerBands()."UpperBand";
plot BollLowBand1 = BollingerBands()."LowerBand";
plot BollMidBand1 = BollingerBands()."MidLine";


BollUpBand1.Hide();
BollLowBand1.Hide();
BollMidBand1.Hide();

def KeltUpBand1 = KeltnerChannels()."Upper_Band";
def KeltLowBand1 = KeltnerChannels()."Lower_Band";


#squeeze upper and lower crossovers
def BollKeltUB1DiffH = if inflatesqueezeclouds and KeltUpBand1 - BollUpBand1 > 0 then  (KeltUpBand1 + ((KeltUpBand1 - BollUpBand1)* inflatevalue)) else if KeltUpBand1 - BollUpBand1 <= 0 then NA else KeltUpBand1;
def BollKeltUB1DiffL = if KeltUpBand1 - BollUpBand1 <= 0 then NA else BollUpBand1;
def BollKeltLB1DiffH = if BollLowBand1 - KeltLowBand1 <= 0 then NA else BollLowBand1;
def BollKeltLB1DiffL = if inflatesqueezeclouds and BollLowBand1 - KeltLowBand1 > 0 then (KeltLowBand1 -  ((BollLowBand1 - KeltLowBand1)*inflatevalue)) else if BollLowBand1 - KeltLowBand1 <= 0 then NA else KeltLowBand1;

#format
BollUpBand1.SetStyle(Curve.FIRM);
BollUpBand1.SetDefaultColor(CreateColor(204, 0, 204));
BollLowBand1.SetStyle(Curve.FIRM);
BollLowBand1.SetDefaultColor(CreateColor(0, 100, 200));
BollMidBand1.SetStyle(Curve.FIRM);
BollMidBand1.SetDefaultColor(CreateColor(150, 150, 255));

#Cloud shading
AddCloud(BollKeltUB1DiffH, BollKeltUB1DiffL, Color.YELLOW, Color.YELLOW);
AddCloud(BollKeltLB1DiffH, BollKeltLB1DiffL, Color.YELLOW, Color.YELLOW);
http://tos.mx/uC4rgih

oh. so if big squeeze the cloud will bigger(this is nice). if I change that will still have this function?
 
Welkin

Welkin

Member
oh. so if big squeeze the cloud will bigger(this is nice). if I change that will still have this function?
its not an absolute, but from what I've seen after looking at them across a lot of charts, when they are thick with a more compact trading range the moves tend to have more substance. Again this isn't 100% or anything just observation, it could also have a small break in the squeeze clouds and continue sideways and form more squeeze clouds producing a type of channel, usually sloping towards one direction or another. Just keep in mind the overall context of what you're observing.
 
W

wen

New member
ok. BTW I did watched his YouTube channel just three ago. then I find u. lol.....THANK YOU!
 
M

mturtrader

New member
@Welkin Thanks for sharing. is it possible for this script to look up at different time frames for a squeeze and somehow show it on the chart? 5min/15min/30min/hourly/daily etc? also would it be possible to add long/short signals as well when in squeeze? TIA
 
Welkin

Welkin

Member
@Welkin Thanks for sharing. is it possible for this script to look up at different time frames for a squeeze and somehow show it on the chart? 5min/15min/30min/hourly/daily etc? also would it be possible to add long/short signals as well when in squeeze? TIA
here is MTF support for 3 aggregations

http://tos.mx/SZGo6Qe
 
T

Tostechnical

New member

So ST has this stats indicator for there squeeze indicator. Does anyone know how they coded this logic?

I want to create something similar to this for my own strategy/indicator. Its a pretty simple CCI one.

Thanks!
 
D

dolomick

Member
This is cool, thanks! Could you possibly do clouds for when the bollinger band is outside the keltner channels (this would be a different indicator, I realize). Currently I have both on and it really helps identify strong moves when prices are between the bollinger and keltner edges, ie, they are outside keltner channel but inside the edge of the bollinger bands. Currently it is kind of messy having both on in my chart. Thanks!
 
Welkin

Welkin

Member
This is cool, thanks! Could you possibly do clouds for when the bollinger band is outside the keltner channels (this would be a different indicator, I realize). Currently I have both on and it really helps identify strong moves when prices are between the bollinger and keltner edges, ie, they are outside keltner channel but inside the edge of the bollinger bands. Currently it is kind of messy having both on in my chart. Thanks!
not a hard change, this should do it: http://tos.mx/CFFtOoe
toggle OutlineClouds to no if you just want only clouds

 
D

dolomick

Member
Thanks for making my modification! I'm guessing this is still showing squeezes on the higher timeframes as the clouds sometimes appear for them but not always? How should I interpret those?

Also, is there a way to make this work on tick charts, even if it means making an alternate version that doesn't have multi-timeframe? Thanks!
 
Last edited:
Welkin

Welkin

Member
Thanks for making my modification! I'm guessing this is still showing squeezes on the higher timeframes as the clouds sometimes appear for them but not always? How should I interpret those?

Also, is there a way to make this work on tick charts, even if it means making an alternate version that doesn't have multi-timeframe? Thanks!
Sorry for the late response. Yes it is still showing the squeezes from the higher time aggregations but you can disable them. simply toggle 'enable aggregation2' or 'enable aggregation3' to no.


the squeeze lets you see points of what is considered low volatility, a prelude to higher volatility. Often you will see them act as support or resistance until price breaks out. When you see them stack up it is an even greater indication of some potential higher volatile moves on larger time frames. Do some backtesting on multiple tickers and use your own analysis and determine if these are informative enough to be used in your personal trading strategies.

I recommend checking out two books that talk about the squeeze:
John Bollinger - Bollinger on Bollinger Bands chapter 8 and chapter 12
and John F Carter - Mastering the Trade (3rd edition) chapter 12 (or chapter 11 in the 2nd edition)

as far as having these on tick charts or even range charts, thats something i'll have to look into.

edit: I'd also like to note that I do not personally use the squeeze the same way John F Carter does, his focus is on higher time frames such as days/weeks/months and he doesn't have clouds on his chart AFAIK, only a momentum indicator with a dotted line that toggles from green to red when a squeeze is taking place. Being able to see what is actually happening with the squeeze is a huge benefit imo. My use of them is primarily on a 5min chart in conjunction with VWAP deviation bands using them as an areas of interest for reversals . Thats why i bundled it with this: https://usethinkscript.com/threads/ultimate-vwap-indicator-for-thinkorswim.1681/
 
Last edited:
D

dolomick

Member
Thanks! I actually have tried Simpler Trading's free trials for their chat rooms. I am trying to get a hold of his book at my local library but they are hard to get so I may have to buy it (Carter). My hunch is the multi-timeframe aspect is what is messing up the ability to use it on tick charts, that usually seems to be the case. If that part could be stripped out it would be useful for futures trading on tick charts - paired with price action and support/resistance, when price spikes out of the keltner and bollinger bands, it can be a good reliable scalp for a reversion to the mean. Conversely it can also show a strong momentum move to trade with the trend.
 
Welkin

Welkin

Member
Thanks! I actually have tried Simpler Trading's free trials for their chat rooms. I am trying to get a hold of his book at my local library but they are hard to get so I may have to buy it (Carter). My hunch is the multi-timeframe aspect is what is messing up the ability to use it on tick charts, that usually seems to be the case. If that part could be stripped out it would be useful for futures trading on tick charts - paired with price action and support/resistance, when price spikes out of the keltner and bollinger bands, it can be a good reliable scalp for a reversion to the mean. Conversely it can also show a strong momentum move to trade with the trend.
here you go try this one, it doesn't have MTF squeeze clouds http://tos.mx/uC4rgih

I haven't looked explored its use on tick charts, thats definitely something to look into. I have a small pane with a 5tick range chart that i like to use, easier to see patterns forming on it, and have better idea of what price action is saying. I also use a reversion to mean strategy, but I use VWAP deviations not bollinger bands.
drop me an email perhaps i have some resources i'd like to share that you'd probably be interested in (or anyone else if they want :)). welkincall at gmail.
 

Top