Repaints Multiple Time Frame (MTF) Squeeze Indicator for ThinkorSwim

Repaints
@GetRichOrDieTrying Try the following code to see whether it performs better for your needs... I found several other price references within the code that benefit from the aggregation period modification... Let me know how the modified code performs...

Ruby:
# TTM_Squeeze_Pro_Selectable_Aggregation
#
# Assembled by TheBewb using existing Mobius Squeeze Momentum coding and "squeeze" concept made popular by John Carter.
#
# Modified 2021-07-27 by rad14733 for usethinkscript.com
# Added code to allow AggregationPeriod selection
# Added code to allow styling modifications
# Default colors are in standard TTM_Squeeze style
# Colors can be edited via study settings or in the code for TTM_Squeeze_Pro style
# v1.0 : 2021-07-27 : Initial Release
# v1.1 : 2021-07-28 : Implemented additional aggregation period prices within the code

declare lower;

input agg = AggregationPeriod.THIRTY_MIN;
def price = close(period = agg);
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input displace = 0;
def sDev = StDev(data = price[-displace], length = length);
def MidLineBB = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;
input factorhigh = 1.0;
input factormid = 1.5;
input factorlow = 2.0;
input trueRangeAverageType = AverageType.SIMPLE;
def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(period = agg), close(period = agg), low(period = agg)), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(period = agg), close(period = agg), low(period = agg)), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(period = agg), close(period = agg), low(period = agg)), length);
def average = MovingAverage(averageType, price, length);

def Avg = average[-displace];

def UpperBandKCLow = average[-displace] + shiftlow[-displace];
def LowerBandKCLow = average[-displace] - shiftlow[-displace];

def UpperBandKCMid = average[-displace] + shiftMid[-displace];
def LowerBandKCMid = average[-displace] - shiftMid[-displace];

def UpperBandKCHigh = average[-displace] + shifthigh[-displace];
def LowerBandKCHigh = average[-displace] - shifthigh[-displace];

def K = (Highest(high(period = agg), length) + Lowest(low(period = agg), length)) / 2 + ExpAverage(close(period = agg), length);
def momo = Inertia(price - K / 2, length);

def pos = momo >= 0;
def neg = momo < 0;
def up = momo >= momo[1];
def dn = momo < momo[1];

def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;

plot squeezeline = 0;
squeezeline.DefineColor("NoSqueeze", Color.GREEN);
squeezeline.DefineColor("PreSqueeze", Color.GRAY);
squeezeline.DefineColor("OriginalSqueeze", Color.RED);
squeezeline.DefineColor("ExtrSqueeze", Color.ORANGE);
squeezeline.SetPaintingStrategy(PaintingStrategy.POINTS);
squeezeline.SetLineWeight(3);
squeezeline.AssignValueColor(if ExtrSqueeze then squeezeline.Color("ExtrSqueeze") else if originalSqueeze  then squeezeline.Color("OriginalSqueeze") else if presqueeze then squeezeline.Color("PreSqueeze") else squeezeline.Color("NoSqueeze"));

plot momentum = momo;
momentum.DefineColor("PosUp", Color.CYAN);
momentum.DefineColor("PosDn", Color.BLUE);
momentum.DefineColor("NegDn", Color.DARK_RED);
momentum.DefineColor("NegUp", Color.YELLOW);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.SetLineWeight(3);
momentum.AssignValueColor(if PosUp then momentum.Color("PosUp") else if PosDn then momentum.Color("PosDn") else if NegDn then momentum.Color("NegDn") else if NegUp then momentum.Color("NegUp") else momentum.Color("NegUp"));

# END - TTM_Squeeze_Pro_Selectable_Aggregation
 

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

could you modify the MTF squeeze indicator to hide the label unless it's squeezing? i.e. if its green the label is hidden. Thanks.
 
Last edited by a moderator:
could you modify the MTF squeeze indicator to hide the label unless it's squeezing? i.e. if its green the label is hidden. Thanks.
change the last statement in the study from this:
AddLabel(yes, dStr, if dSQ

then Color.RED else Color.GREEN); # display label red if has squeeze
to this:
AddLabel(dSQ, dStr, if dSQ

then Color.RED else Color.GREEN); # display label red if has squeeze
 
Last edited:
All - I've been working on building a comparable setup to John Carter's squeeze pro labels + histogram labels.

I was able to modify code I found here to accomplish the "squeeze pro" portion of this. Unfortunately, it is tough to find a histogram that matches Carter's. Mobius' code has a good histogram but I find it not nearly as smooth as John Carter's. However, I found the "Awesome Oscillator" in TOS to be very close to the TTM_Squeeze histogram when you modify the 2 period lengths in the code to be 9 & 21 instead of 5 & 34. I took this logic and built an "MTF histogram label" that sits just underneath the squeeze label...similar to JC's. I've watched several of his videos and confirmed that the squeeze portion of my code works verbatim to his. The histogram is not exact but it is "damn close."

Pic of my setup here:

Screenshot-2020-05-15-22-33-27.png


Here is a link to my shared grid, containing the histogram & squeeze labels: https://tos.mx/xkLakTN

Color legend for those unfamiliar:
  • Top row are the squeezes - Gray = low squeeze, Red = med squeeze (same as the original TTM_Squeeze indicator) and Yellow = high squeeze (this is the tightest squeeze). Green indicates no squeeze.
  • Bottom row contains histograms: Cyan = increasing positive momentum, Blue = waning positive momentum, Red = increasing negative momentum & Yellow = waning negative momentum.

Let me know your thoughts...
Can you add the code without the share link and the moving average lines? I just want the above MTF aspect thanks
 
All - I've been working on building a comparable setup to John Carter's squeeze pro labels + histogram labels.

I was able to modify code I found here to accomplish the "squeeze pro" portion of this. Unfortunately, it is tough to find a histogram that matches Carter's. Mobius' code has a good histogram but I find it not nearly as smooth as John Carter's. However, I found the "Awesome Oscillator" in TOS to be very close to the TTM_Squeeze histogram when you modify the 2 period lengths in the code to be 9 & 21 instead of 5 & 34. I took this logic and built an "MTF histogram label" that sits just underneath the squeeze label...similar to JC's. I've watched several of his videos and confirmed that the squeeze portion of my code works verbatim to his. The histogram is not exact but it is "damn close."

Pic of my setup here:

Screenshot-2020-05-15-22-33-27.png


Here is a link to my shared grid, containing the histogram & squeeze labels: https://tos.mx/xkLakTN

Color legend for those unfamiliar:
  • Top row are the squeezes - Gray = low squeeze, Red = med squeeze (same as the original TTM_Squeeze indicator) and Yellow = high squeeze (this is the tightest squeeze). Green indicates no squeeze.
  • Bottom row contains histograms: Cyan = increasing positive momentum, Blue = waning positive momentum, Red = increasing negative momentum & Yellow = waning negative momentum.

Let me know your thoughts...

good stuff! Thank you. Is there a way to select 9/21 EMA or make code so Multi_Histo to see is more exact?
 
Has anyone tried to do this with the most recent version from Mobius of the Momentum Squeeze:

https://usethinkscript.com/threads/mobius’-momentum-squeeze-for-thinkorswim.1123/post-73983

I think the squeeze code could just be substituted for the code use in above posts, but I am not sure how to convert these input variables to the ones used used in this thread, and trying to avoid rewriting the aggregations code.

For example modifying this code by @Pelonsax https://usethinkscript.com/threads/...eeze-indicator-for-thinkorswim.350/post-29267 above in post #93.

If not, anyone know an easy solution or how to convert?

Thanks!
 
It looks like I cutoff some of the code. paste this at the bottom of my last post.
It's a lower study. The colors represent the dots on the squeeze.

My hope is to make a label - just like yours - that tells me what color dot the squeeze is at for a given timeframe.
(i.e. - if the 5 minute squeeze is a black dot, the 5M label would be black)

Code:
def midSqueeze = BolKelDelta_Mid <= 0;
def triggerMid = if sum(midSqueeze,triggerBars) == triggerBars and !midSqueeze[triggerBars] then 1 else 0;

plot signalMidLong = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;

signalMidLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalMidLong.setDefaultColor(color.red);
signalMidLong.setLineWeight(5);

plot signalMidShort = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;

signalMidShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalMidShort.setDefaultColor(color.red);
signalMidShort.setLineWeight(5);

def highSqueeze = BolKelDelta_High <= 0;
def triggerHigh = if sum(highSqueeze,triggerBars) == triggerBars and !highSqueeze[triggerBars] then 1 else 0;

plot signalHighLong = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;

signalHighLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalHighLong.setDefaultColor(color.dark_orange);
signalHighLong.setLineWeight(5);

plot signalHighShort = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;

signalHighShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalHighShort.setDefaultColor(color.dark_orange);
signalHighShort.setLineWeight(5);
It looks like I cutoff some of the code. paste this at the bottom of my last post.
It's a lower study. The colors represent the dots on the squeeze.

My hope is to make a label - just like yours - that tells me what color dot the squeeze is at for a given timeframe.
(i.e. - if the 5 minute squeeze is a black dot, the 5M label would be black)

Code:
def midSqueeze = BolKelDelta_Mid <= 0;
def triggerMid = if sum(midSqueeze,triggerBars) == triggerBars and !midSqueeze[triggerBars] then 1 else 0;

plot signalMidLong = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;

signalMidLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalMidLong.setDefaultColor(color.red);
signalMidLong.setLineWeight(5);

plot signalMidShort = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;

signalMidShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalMidShort.setDefaultColor(color.red);
signalMidShort.setLineWeight(5);

def highSqueeze = BolKelDelta_High <= 0;
def triggerHigh = if sum(highSqueeze,triggerBars) == triggerBars and !highSqueeze[triggerBars] then 1 else 0;

plot signalHighLong = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;

signalHighLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalHighLong.setDefaultColor(color.dark_orange);
signalHighLong.setLineWeight(5);

plot signalHighShort = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;

signalHighShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalHighShort.setDefaultColor(color.dark_orange);
signalHighShort.setLineWeight(5);

It looks like I cutoff some of the code. paste this at the bottom of my last post.
It's a lower study. The colors represent the dots on the squeeze.

My hope is to make a label - just like yours - that tells me what color dot the squeeze is at for a given timeframe.
(i.e. - if the 5 minute squeeze is a black dot, the 5M label would be black)

Code:
def midSqueeze = BolKelDelta_Mid <= 0;
def triggerMid = if sum(midSqueeze,triggerBars) == triggerBars and !midSqueeze[triggerBars] then 1 else 0;

plot signalMidLong = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;

signalMidLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalMidLong.setDefaultColor(color.red);
signalMidLong.setLineWeight(5);

plot signalMidShort = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;

signalMidShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalMidShort.setDefaultColor(color.red);
signalMidShort.setLineWeight(5);

def highSqueeze = BolKelDelta_High <= 0;
def triggerHigh = if sum(highSqueeze,triggerBars) == triggerBars and !highSqueeze[triggerBars] then 1 else 0;

plot signalHighLong = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;

signalHighLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalHighLong.setDefaultColor(color.dark_orange);
signalHighLong.setLineWeight(5);

plot signalHighShort = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and  oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and  oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;

signalHighShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalHighShort.setDefaultColor(color.dark_orange);
signalHighShort.setLineWeight(5);
Hey! is there a way to code this so that it just plots the up and down arrows on the chart?
Similar to this?

https://simpler-cdn.s3.amazonaws.co...ides/TOS/ST-TOS-PDF/SqueezePRO_SignalsTOS.pdf
 
Hey! is there a way to code this so that it just plots the up and down arrows on the chart?
Similar to this?

https://simpler-cdn.s3.amazonaws.com/downloads/Squeeze Pro System/Indicator Guides/TOS/ST-TOS-PDF/SqueezePRO_SignalsTOS.pdf
declare lower;
##Global Variables
def length = 15;
def AlertLine = 1;
def nk = 1.5;
def nBB = 2;
def averageTpype = AverageType.SIMPLE;
def displace = 0;
def trueRangeAverageType = AverageType.SIMPLE;

## Signal Plots
def minSignal = 12;
def five_minSignal = 11;
def fifteen_minSignal =10;
def thirty_minSignal = 9;
def hour_Signal = 8;
def two_hour_Signal = 7;
def four_hour_Signal = 6;
def day_Signal = 5;
def two_day_Signal = 4;
def three_day_Signal = 3;
def week_Signal = 2;
def monthSignal = 1;


def minAggregationPeriod;
def five_minAggregationPeriod;
def fifteen_minAggregationPeriod;
def thirty_minAggregationPeriod;
def hourAggregationPeriod;
def two_hourAggregationPeriod;
def four_hourAggregationPeriod;
def dayAggregationPeriod;
def two_dayAggregationPeriod;
def three_dayAggregationPeriod;
def weekAggregationPeriod;
def monthAggregationPeriod;

if GetAggregationPeriod() == AggregationPeriod.MIN {
minAggregationPeriod = 1;
} else {
minAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.FIVE_MIN {
five_minAggregationPeriod = 1;
} else {
five_minAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN {
fifteen_minAggregationPeriod = 1;
} else {
fifteen_minAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN {
thirty_minAggregationPeriod = 1;
} else {
thirty_minAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.HOUR {
hourAggregationPeriod = 1;
} else {
hourAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.TWO_HOURS {
two_hourAggregationPeriod = 1;
} else {
two_hourAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.FOUR_HOURS {
four_hourAggregationPeriod = 1;
} else {
four_hourAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.DAY {
dayAggregationPeriod = 1;
} else {
dayAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.TWO_DAYS {
two_dayAggregationPeriod = 1;
} else {
two_dayAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.THREE_DAYS {
three_dayAggregationPeriod = 1;
} else {
three_dayAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.WEEK {
weekAggregationPeriod = 1;
} else {
weekAggregationPeriod = 0;
}
if GetAggregationPeriod() == AggregationPeriod.MONTH {
monthAggregationPeriod = 1;
} else {
monthAggregationPeriod = 0;
}



## 1 Minute Aggregation for TTM Squeeze
def minPrice;
def minATR;
def minSDev;
def minDenom;
def minBBSInd;
def minSqueeze;

if GetAggregationPeriod() <= AggregationPeriod.MIN {
minPrice = close(period=AggregationPeriod.MIN);
minATR = Average(TrueRange(high (period=AggregationPeriod.MIN), close(period=AggregationPeriod.MIN), low(period=AggregationPeriod.MIN)), Length);
minSDev = stdev(minPrice, Length);
minDenom = (nK*minATR);
minBBSInd = if (minDenom <> 0, ((nBB * minSDev) /minDenom), 0);
minSqueeze = if minBBSInd < AlertLine then 1 else 0;
}
else {
minPrice = 0;
minATR = 0;
minSDev = 0;
minDenom = 0;
minBBSInd = 0;
minSqueeze = 0;
}
plot minPlot = if !IsNaN(minPrice) and minAggregationPeriod == 1 then minSignal else Double.NaN;
minPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
minPlot.SetLineWeight(3);
minPlot.AssignValueColor(if minSqueeze == 1 then Color.RED else Color.GREEN);

## 5 Minute Aggregation for TTM Squeeze
def five_minPrice;
def five_minATR;
def five_minSDev;
def five_minDenom;
def five_minBBSInd;
def five_minSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
five_minPrice = close(period=AggregationPeriod.FIVE_MIN);
five_minATR = Average(TrueRange(high (period=AggregationPeriod.FIVE_MIN), close(period=AggregationPeriod.FIVE_MIN), low(period=AggregationPeriod.FIVE_MIN)), Length);
five_minSDev = stdev(five_minPrice, Length);
five_minDenom = (nK*five_minATR);
five_minBBSInd = if (five_minDenom <> 0, ((nBB * five_minSDev) /five_minDenom), 0);
five_minSqueeze = if five_minBBSInd < AlertLine then 1 else 0;
}
else {
five_minPrice = 0;
five_minATR = 0;
five_minSDev = 0;
five_minDenom = 0;
five_minBBSInd = 0;
five_minSqueeze = 0;
}
plot five_minPlot = if !IsNaN(five_minPrice) and (five_minAggregationPeriod == 1 or minAggregationPeriod ==1) then five_minSignal else Double.NaN;
five_minPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
five_minPlot.SetLineWeight(3);
five_minPlot.AssignValueColor(if five_minSqueeze == 1 then Color.RED else Color.GREEN);


## 15 Minute Aggregation for TTM Squeeze
def fifteen_minPrice;
def fifteen_minATR;
def fifteen_minSDev;
def fifteen_minDenom;
def fifteen_minBBSInd;
def fifteen_minSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
fifteen_minPrice = close(period=AggregationPeriod.fifteen_min);
fifteen_minATR = Average(TrueRange(high (period=AggregationPeriod.fifteen_min), close(period=AggregationPeriod.fifteen_min), low(period=AggregationPeriod.fifteen_min)), Length);
fifteen_minSDev = stdev(fifteen_minPrice, Length);
fifteen_minDenom = (nK*fifteen_minATR);
fifteen_minBBSInd = if (fifteen_minDenom <> 0, ((nBB * fifteen_minSDev) /fifteen_minDenom), 0);
fifteen_minSqueeze = if fifteen_minBBSInd < AlertLine then 1 else 0;
}
else {
fifteen_minPrice = 0;
fifteen_minATR = 0;
fifteen_minSDev = 0;
fifteen_minDenom = 0;
fifteen_minBBSInd = 0;
fifteen_minSqueeze = 0;
}
plot fifteen_minPlot = if !IsNaN(fifteen_minPrice) and (fifteen_minAggregationPeriod == 1 or five_minAggregationPeriod == 1 or minAggregationPeriod == 1) then fifteen_minSignal else Double.NaN;
fifteen_minPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
fifteen_minPlot.SetLineWeight(3);
fifteen_minPlot.AssignValueColor(if fifteen_minSqueeze == 1 then Color.RED else Color.GREEN);


## 30 Minute Aggregation for TTM Squeeze
def thirty_minPrice;
def thirty_minATR;
def thirty_minSDev;
def thirty_minDenom;
def thirty_minBBSInd;
def thirty_minSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.thirty_min {
thirty_minPrice = close(period=AggregationPeriod.thirty_min);
thirty_minATR = Average(TrueRange(high (period=AggregationPeriod.thirty_min), close(period=AggregationPeriod.thirty_min), low(period=AggregationPeriod.thirty_min)), Length);
thirty_minSDev = stdev(thirty_minPrice, Length);
thirty_minDenom = (nK*thirty_minATR);
thirty_minBBSInd = if (thirty_minDenom <> 0, ((nBB * thirty_minSDev) /thirty_minDenom), 0);
thirty_minSqueeze = if thirty_minBBSInd < AlertLine then 1 else 0;
}
else {
thirty_minPrice = 0;
thirty_minATR = 0;
thirty_minSDev = 0;
thirty_minDenom = 0;
thirty_minBBSInd = 0;
thirty_minSqueeze = 0;
}
plot thirty_minPlot = if !IsNaN(thirty_minPrice) and (thirty_minAggregationPeriod == 1 or fifteen_minAggregationPeriod == 1 or five_minAggregationPeriod == 1 or minAggregationPeriod == 1) then thirty_minSignal else Double.NaN;
thirty_minPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
thirty_minPlot.SetLineWeight(3);
thirty_minPlot.AssignValueColor(if thirty_minSqueeze == 1 then Color.RED else Color.GREEN);


## 1 HOUR Aggregation for TTM Squeeze
def hourPrice;
def hourATR;
def hourSDev;
def hourDenom;
def hourBBSInd;
def hourSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.hour {
hourPrice = close(period=AggregationPeriod.hour);
hourATR = Average(TrueRange(high (period=AggregationPeriod.hour), close(period=AggregationPeriod.hour), low(period=AggregationPeriod.hour)), Length);
hourSDev = stdev(hourPrice, Length);
hourDenom = (nK*hourATR);
hourBBSInd = if (hourDenom <> 0, ((nBB * hourSDev) /hourDenom), 0);
hourSqueeze = if hourBBSInd < AlertLine then 1 else 0;
}
else {
hourPrice = 0;
hourATR = 0;
hourSDev = 0;
hourDenom = 0;
hourBBSInd = 0;
hourSqueeze = 0;
}
plot hourPlot = if !IsNaN(hourPrice) and (hourAggregationPeriod == 1 or thirty_minAggregationPeriod == 1 or fifteen_minAggregationPeriod == 1 or five_minAggregationPeriod == 1 or minAggregationPeriod == 1) then hour_Signal else Double.NaN;
hourPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
hourPlot.SetLineWeight(3);
hourPlot.AssignValueColor(if hourSqueeze == 1 then Color.RED else Color.GREEN);


## 2 HOUR Aggregation for TTM Squeeze
def two_hourPrice;
def two_hourATR;
def two_hourSDev;
def two_hourDenom;
def two_hourBBSInd;
def two_hourSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.two_hours {
two_hourPrice = close(period=AggregationPeriod.two_hours);
two_hourATR = Average(TrueRange(high (period=AggregationPeriod.two_hours), close(period=AggregationPeriod.two_hours), low(period=AggregationPeriod.two_hours)), Length);
two_hourSDev = stdev(two_hourPrice, Length);
two_hourDenom = (nK*two_hourATR);
two_hourBBSInd = if (two_hourDenom <> 0, ((nBB * two_hourSDev) /two_hourDenom), 0);
two_hourSqueeze = if two_hourBBSInd < AlertLine then 1 else 0;
}
else {
two_hourPrice = 0;
two_hourATR = 0;
two_hourSDev = 0;
two_hourDenom = 0;
two_hourBBSInd = 0;
two_hourSqueeze = 0;
}
plot two_hourPlot = if !IsNaN(two_hourPrice) and (two_hourAggregationPeriod == 1 or hourAggregationPeriod == 1 or thirty_minAggregationPeriod == 1 or fifteen_minAggregationPeriod == 1 or five_minAggregationPeriod == 1 or minAggregationPeriod == 1) then two_hour_Signal else Double.NaN;
two_hourPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
two_hourPlot.SetLineWeight(3);
two_hourPlot.AssignValueColor(if two_hourSqueeze == 1 then Color.RED else Color.GREEN);


## 4 HOUR Aggregation for TTM Squeeze
def four_hourPrice;
def four_hourATR;
def four_hourSDev;
def four_hourDenom;
def four_hourBBSInd;
def four_hourSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
four_hourPrice = close(period=AggregationPeriod.FOUR_HOURS);
four_hourATR = Average(TrueRange(high (period=AggregationPeriod.FOUR_HOURS), close(period=AggregationPeriod.FOUR_HOURS), low(period=AggregationPeriod.FOUR_HOURS)), Length);
four_hourSDev = stdev(four_hourPrice, Length);
four_hourDenom = (nK*four_hourATR);
four_hourBBSInd = if (four_hourDenom <> 0, ((nBB * four_hourSDev) /four_hourDenom), 0);
four_hourSqueeze = if four_hourBBSInd < AlertLine then 1 else 0;
}
else {
four_hourPrice = 0;
four_hourATR = 0;
four_hourSDev = 0;
four_hourDenom = 0;
four_hourBBSInd = 0;
four_hourSqueeze = 0;
}
plot four_hourPlot = if !IsNaN(four_hourPrice) and (four_hourAggregationPeriod == 1 or two_hourAggregationPeriod == 1 or hourAggregationPeriod == 1 or thirty_minAggregationPeriod == 1) then four_hour_Signal else Double.NaN;
four_hourPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
four_hourPlot.SetLineWeight(3);
four_hourPlot.AssignValueColor(if four_hourSqueeze == 1 then Color.RED else Color.GREEN);


## 1 DAY Aggregation for TTM Squeeze
def dayPrice;
def dayATR;
def daySDev;
def dayDenom;
def dayBBSInd;
def daySqueeze;
if GetAggregationPeriod() <= AggregationPeriod.day {
dayPrice = close(period=AggregationPeriod.day);
dayATR = Average(TrueRange(high (period=AggregationPeriod.day), close(period=AggregationPeriod.day), low(period=AggregationPeriod.day)), Length);
daySDev = stdev(dayPrice, Length);
dayDenom = (nK*dayATR);
dayBBSInd = if (dayDenom <> 0, ((nBB * daySDev) /dayDenom), 0);
daySqueeze = if dayBBSInd < AlertLine then 1 else 0;
}
else {
dayPrice = 0;
dayATR = 0;
daySDev = 0;
dayDenom = 0;
dayBBSInd = 0;
daySqueeze = 0;
}
plot dayPlot = if !IsNaN(dayPrice) and (dayAggregationPeriod == 1 or four_hourAggregationPeriod == 1 or two_hourAggregationPeriod == 1 or hourAggregationPeriod == 1) then day_Signal else Double.NaN;
dayPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
dayPlot.SetLineWeight(3);
dayPlot.AssignValueColor(if daySqueeze == 1 then Color.RED else Color.GREEN);


## 2 DAY Aggregation for TTM Squeeze
def two_dayPrice;
def two_dayATR;
def two_daySDev;
def two_dayDenom;
def two_dayBBSInd;
def two_daySqueeze;
if GetAggregationPeriod() <= AggregationPeriod.two_days {
two_dayPrice = close(period=AggregationPeriod.two_days);
two_dayATR = Average(TrueRange(high (period=AggregationPeriod.two_days), close(period=AggregationPeriod.two_days), low(period=AggregationPeriod.two_days)), Length);
two_daySDev = stdev(two_dayPrice, Length);
two_dayDenom = (nK*two_dayATR);
two_dayBBSInd = if (two_dayDenom <> 0, ((nBB * two_daySDev) /two_dayDenom), 0);
two_daySqueeze = if two_dayBBSInd < AlertLine then 1 else 0;
}
else {
two_dayPrice = 0;
two_dayATR = 0;
two_daySDev = 0;
two_dayDenom = 0;
two_dayBBSInd = 0;
two_daySqueeze = 0;
}
plot two_dayPlot = if !IsNaN(two_dayPrice) and (two_dayAggregationPeriod == 1 or dayAggregationPeriod == 1 or four_hourAggregationPeriod == 1 or two_hourAggregationPeriod == 1) then two_day_Signal else Double.NaN;
two_dayPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
two_dayPlot.SetLineWeight(3);
two_dayPlot.AssignValueColor(if two_daySqueeze == 1 then Color.RED else Color.GREEN);


## 3 DAY Aggregation for TTM Squeeze
def three_dayPrice;
def three_dayATR;
def three_daySDev;
def three_dayDenom;
def three_dayBBSInd;
def three_daySqueeze;
if GetAggregationPeriod() <= AggregationPeriod.three_days {
three_dayPrice = close(period=AggregationPeriod.three_days);
three_dayATR = Average(TrueRange(high (period=AggregationPeriod.three_days), close(period=AggregationPeriod.three_days), low(period=AggregationPeriod.three_days)), Length);
three_daySDev = stdev(three_dayPrice, Length);
three_dayDenom = (nK*three_dayATR);
three_dayBBSInd = if (three_dayDenom <> 0, ((nBB * three_daySDev) /three_dayDenom), 0);
three_daySqueeze = if three_dayBBSInd < AlertLine then 1 else 0;
}
else {
three_dayPrice = 0;
three_dayATR = 0;
three_daySDev = 0;
three_dayDenom = 0;
three_dayBBSInd = 0;
three_daySqueeze = 0;
}
plot three_dayPlot = if !IsNaN(three_dayPrice) and (three_dayAggregationPeriod == 1 or two_dayAggregationPeriod == 1 or dayAggregationPeriod == 1 or four_hourAggregationPeriod == 1) then three_day_Signal else Double.NaN;
three_dayPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
three_dayPlot.SetLineWeight(3);
three_dayPlot.AssignValueColor(if three_daySqueeze == 1 then Color.RED else Color.GREEN);


## 1 WK Aggregation for TTM Squeeze
def weekPrice;
def weekATR;
def weekSDev;
def weekDenom;
def weekBBSInd;
def weekSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.week {
weekPrice = close(period=AggregationPeriod.week);
weekATR = Average(TrueRange(high (period=AggregationPeriod.week), close(period=AggregationPeriod.week), low(period=AggregationPeriod.week)), Length);
weekSDev = stdev(weekPrice, Length);
weekDenom = (nK*weekATR);
weekBBSInd = if (weekDenom <> 0, ((nBB * weekSDev) /weekDenom), 0);
weekSqueeze = if weekBBSInd < AlertLine then 1 else 0;
}
else {
weekPrice = 0;
weekATR = 0;
weekSDev = 0;
weekDenom = 0;
weekBBSInd = 0;
weekSqueeze = 0;
}
plot weekPlot = if !IsNaN(weekPrice) and (weekAggregationPeriod == 1 or three_dayAggregationPeriod == 1 or two_dayAggregationPeriod == 1 or dayAggregationPeriod == 1) then week_Signal else Double.NaN;
weekPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
weekPlot.SetLineWeight(3);
weekPlot.AssignValueColor(if weekSqueeze == 1 then Color.RED else Color.GREEN);

## Month Aggregation Period Variables
def monthPrice;
def monthATR;
def monthSDev;
def monthDenom;
def monthBBSInd;
def monthSqueeze;
if GetAggregationPeriod() <= AggregationPeriod.Month {
monthPrice = close(period="Month");
monthATR = Average(TrueRange(high (period=AggregationPeriod.MONTH), close(period=AggregationPeriod.MONTH), low(period=AggregationPeriod.MONTH)), Length);
monthSDev = stdev(monthPrice, Length);
monthDenom = (nK*monthATR);
monthBBSInd = if (monthDenom <> 0, ((nBB * monthSDev) /monthDenom), 0);
monthSqueeze = if monthBBSInd < AlertLine then 1 else 0;
}
else {
monthPrice = 0;
monthATR = 0;
monthSDev = 0;
monthDenom = 0;
monthBBSInd = 0;
monthSqueeze = 0;
}
plot monthPlot = if !IsNaN(monthPrice) and (monthAggregationPeriod == 1 or weekAggregationPeriod == 1 or three_dayAggregationPeriod == 1 or two_dayAggregationPeriod == 1) then monthSignal else Double.NaN;
monthPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
monthPlot.SetLineWeight(3);
monthPlot.AssignValueColor(if monthSqueeze == 1 then Color.RED else Color.GREEN);

## END TTM SQUEEZE MTF SIGNAL SCRIPT
@lucassow @laketrader MultiTime Frame TTM Squeeze. Here you go.
View attachment 5160
Code:
###CollegeTrader

###CT_MTF_TTM_Squeeze_Replica

###

###Original TTM_Squeeze_Replica Code from Mobius

#hint:Helps identify periods of low volatility on multiple timeframes

 

Declare lower;

### Time Aggregations ############

 

input time1 = AggregationPeriod.five_min; #hint time1:  Plot @ 0.

input time2 = AggregationPeriod.ten_min; #hint time2:  Plot @ 0.5.

input time3 = AggregationPeriod.twenty_min; #hint time3:  Plot @ 1.

input time4 = AggregationPeriod.hour; #hint time4:  Plot @ 1.5.

 

### Master Plot On/Off ###########

input Master_Squeeze_Plot = Yes; #hint Master_Squeeze_Plot:  Turns the master squeeze plot on or off.

 

### Time1 Squeeze Code ##############

 

input length  = 20;

input AtrMult = 1.5;

input SdMult  = 2.0;

 

 

def SD = StDev(close(period = time1), length);

def Avg = Average(close(period = time1), length);

def ATR = Average(TrueRange(high(period = time1), close(period = time1), low(period = time1)), length);

def SDup = Avg + (SdMult * Sd);

def ATRup = Avg + (AtrMult * ATR);

 

plot Squeeze = if SDup < ATRup

then 0

else Double.NaN;

Squeeze.SetPaintingStrategy(PaintingStrategy.Points);

Squeeze.SetLineWeight(4);

Squeeze.SetDefaultColor(Color.Red);

 

plot zero = if IsNaN(close(period = time1)) or !IsNaN(Squeeze) then Double.NaN else 0;

zero.SetPaintingStrategy(PaintingStrategy.Points);

zero.SetLineWeight(4);

zero.SetDefaultColor(Color.Green);

 

### time2 Code #####################

 

def SD2 = StDev(close(period = time2), length);

def Avg2 = Average(close(period = time2), length);

def ATR2 = Average(TrueRange(high(period = time2), close(period = time2), low(period = time2)), length);

def SDup2 = Avg2 + (SdMult * Sd2);

def ATRup2 = Avg2 + (AtrMult * ATR2);

 

plot Squeeze2 = if SDup2 < ATRup2

then 0.5

else Double.NaN;

Squeeze2.SetPaintingStrategy(PaintingStrategy.Points);

Squeeze2.SetLineWeight(4);

Squeeze2.SetDefaultColor(Color.Red);

 

plot zero2 = if IsNaN(close(period = time2)) or !IsNaN(Squeeze2) then Double.NaN else 0.5;

zero2.SetPaintingStrategy(PaintingStrategy.Points);

zero2.SetLineWeight(4);

zero2.SetDefaultColor(Color.Green);

 

### time3 Code ####################

 

def SD3 = StDev(close(period = time3), length);

def Avg3 = Average(close(period = time3), length);

def ATR3 = Average(TrueRange(high(period = time3), close(period = time3), low(period = time3)), length);

def SDup3 = Avg3 + (SdMult * Sd3);

def ATRup3 = Avg3 + (AtrMult * ATR3);

 

plot Squeeze3 = if SDup3 < ATRup3

then 1

else Double.NaN;

Squeeze3.SetPaintingStrategy(PaintingStrategy.Points);

Squeeze3.SetLineWeight(4);

Squeeze3.SetDefaultColor(Color.Red);

 

plot zero3 = if IsNaN(close(period = time3)) or !IsNaN(Squeeze3) then Double.NaN else 1;

zero3.SetPaintingStrategy(PaintingStrategy.Points);

zero3.SetLineWeight(4);

zero3.SetDefaultColor(Color.Green);

 

### time4 Code ########################

 

def SD4 = StDev(close(period = time4), length);

def Avg4 = Average(close(period = time4), length);

def ATR4 = Average(TrueRange(high(period = time4), close(period = time4), low(period = time4)), length);

def SDup4 = Avg4 + (SdMult * Sd4);

def ATRup4 = Avg4 + (AtrMult * ATR4);

 

plot Squeeze4 = if SDup4 < ATRup4

then 1.5

else Double.NaN;

Squeeze4.SetPaintingStrategy(PaintingStrategy.Points);

Squeeze4.SetLineWeight(4);

Squeeze4.SetDefaultColor(Color.Red);

 

plot zero4 = if IsNaN(close(period = time4)) or !IsNaN(Squeeze4) then Double.NaN else 1.5;

zero4.SetPaintingStrategy(PaintingStrategy.Points);

zero4.SetLineWeight(4);

zero4.SetDefaultColor(Color.Green);

 

### Master Squeeze Signal ################

 

plot line = if !IsNaN(close) and Master_Squeeze_Plot == Yes then 1.75 else Double.Nan;

line.SetPaintingStrategy(PaintingStrategy.Line);

line.SetLineWeight(5);

line.setdefaultcolor(color.white);

 

plot Master_Squeeze = if Master_Squeeze_Plot == Yes and ((SDup < ATRup) and (SDup2 < ATRup2) and (SDup3 < ATRup3) and (SDup4 < ATRup4))

 

then 2

else Double.NaN;

Master_Squeeze.SetPaintingStrategy(PaintingStrategy.Points);

Master_Squeeze.SetLineWeight(4);

Master_Squeeze.SetDefaultColor(Color.Red);

 

plot Master_Zero = if IsNaN(close) or !(SDup < ATRup) and !(SDup2 < ATRup2) and !(SDup3 < ATRup3) and !(SDup4 < ATRup4)

then Double.NaN

else if (Master_Squeeze_Plot == Yes) then 2

else Double.NaN;

Master_Zero.SetPaintingStrategy(PaintingStrategy.Points);

Master_Zero.SetLineWeight(4);

Master_Zero.SetDefaultColor(Color.Green);
Can the dots in the multi-time frame be indicated if the TTM fired to the upside or to the down side. I would like to see the red to the down side and green to the upside and orange when it in the squeeze. Otherwise you have to check each time frame which direction it fired to. Thank you
 
All multi-timeframe (MTF) indicators present a type of repainting behavior.
Think about it. You have a 30-min overlay on a five-min chart. There is no way of predicting at what price that 30min candle is going to close until it closes. So for 30 minutes, it will continually repaint the 6 bars with the most recent 30min bar tick price.

Then, when the 30min candle finally closes, it will do a final repaint of the previous 6 bars with the 30min close price.

Read more:
https://usethinkscript.com/threads/...d.-,Multi-Timeframe,-REPAINTING-type Behavior
Hi MerryDay ... is there a chance to create a MTF (multi-timeframe) indicator to show if the stock is in a "Squeeze" condition over multiple time frames? Similar to the Super Trend "Dot"
https://usethinkscript.com/threads/multi-timeframe-supertrend-chart-setup-for-thinkorswim.13844/
but instead creating a "Squeeze Dot" ... thanx in advance!
 
Last edited by a moderator:
Hi MerryDay ... is there a chance to create a MTF (multi-timeframe) indicator to show if the stock is in a "Squeeze" condition over multiple time frames? Similar to the Super Trend "Dot"
https://usethinkscript.com/threads/multi-timeframe-supertrend-chart-setup-for-thinkorswim.13844/
but instead creating a "Squeeze Dot" ... thanx in advance!
There are several in this thread.
Start with this one:
https://usethinkscript.com/threads/...eeze-indicator-for-thinkorswim.350/#post-3453
and see if you can make it into what you are looking for.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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