Multiple Time Frame (MTF) Squeeze Indicator for ThinkorSwim

L

laketrader

New member
VIP
Hi all

To give back a little to the community, I developed a MTF squeeze indicator for ThinkOrSwim as an alternative to the overpriced internet version . TTM squeeze code is not available on TOS but luckily Mobius provided a replication of TTM squeeze on onedrive.

The base scrip is as follows:

thinkScript Code

Code:
# the script develped by laketrader trying to replicate multitimeframe squeeze

# indicator as an alternative to the overpriced internet version.

# TTM squeeze code is not available on TOS  but luckily Mobius provided a excellent

# replication of TTM squeeze on onedrive. Thus, the squeeze logic was based on Mobius's

# code.

#

# changing the first line dStr to diffeent timeframe will switch to different timeframe.

# e.g.

# dStr = "Weekly" wil change to weekly squeeze

input dStr ="Day";

script MySqueeze{

def length  = 20;

def AtrMult = 1.5;

def SdMult  = 2.0;

input period ="Daily";

def valueClose   =  close(period = period);

def valueHigh   =  high(period = period);

def valueLow   =  low(period = period);

def SD = StDev(valueClose, length);

def Avg = Average(valueClose, length);

def ATR = Average(TrueRange(valueHigh, valueClose, valueLow), length);

def SDup = Avg + (SdMult * SD);

def ATRup = Avg + (AtrMult * ATR);

plot Squeeze = if SDup < ATRup

               then 1

               else 0;

}

def dSQ= MySqueeze(dStr);

AddLabel(yes, dStr, if dSQ

then  Color.RED else  Color.GREEN); # display label red if has squeeze

TOS shareable link:

 
N

noobstocktrader101

New member
VIP
I modified your script to make it a bit easier to select a time frame and how it is displayed. It still requires to add several to see which time frame is in a squeeze.

Code:
changed line :  input dStr ="Day";    to
        input dStr =aggregationPeriod.DAY;


changed line :  input period ="Daily";   to
        input period =aggregationPeriod.DAY;

changed lines:    AddLabel(yes, dStr,   to

    AddLabel(yes, if dStr == aggregationPeriod.MONTH then "M"
    else
    if dStr == aggregationPeriod.WEEK then "W"
    else
    if dStr == aggregationPeriod.FOUR_DAYS then "4D"
    else
    if dStr == aggregationPeriod.THREE_DAYS then "3D"
    else
    if dStr == aggregationPeriod.TWO_DAYS then "2D"
    else
    if dStr == aggregationPeriod.DAY then "D"
    else
    if dStr == aggregationPeriod.FOUR_HOURS then "4H"
    else
    if dStr == aggregationPeriod.TWO_HOURS then "2H"
    else
    if dStr == aggregationPeriod.HOUR then "60m"
    else
    if dStr == aggregationPeriod.THIRTY_MIN then "30m"
    else
    if dStr == aggregationPeriod.TWENTY_MIN then "20m"
    else
    if dStr == aggregationPeriod.FIFTEEN_MIN then "15m"
    else
    if dStr == aggregationPeriod.TEN_MIN then "10m"
    else
    if dStr == aggregationPeriod.FIVE_MIN then "5m"
    else
    if dStr == aggregationPeriod.FOUR_MIN then "4m"
    else
    if dStr  == aggregationPeriod.THREE_MIN then "3m"
    else
    if dStr == aggregationPeriod.TWO_MIN then "2m"
    else
    if dStr  == aggregationPeriod.MIN then "1m"
    else "",
This way you just click on the desired time frame.

 
L

laketrader

New member
VIP
Great. It is a good modification. I am still trying to see if we can do some custom timeframe like 195 min, 130 min etc. Have not figured it out yet.
 
N

noobstocktrader101

New member
VIP
I don't believe it is possible. The time frames are predefined. Should be possible with getAggregationPeriod() but it is limited does not return required value.
 
L

lucassow

New member
Hi Guy,
Just to check, anyone have Multi Time Frame MTF Trend script for TOS?
 
markos

markos

Well-known member
VIP
Great. It is a good modification. I am still trying to see if we can do some custom timeframe like 195 min, 130 min etc. Have not figured it out yet.
@laketrader @noobstocktrader101 I believe that the Fractal used by many to divide a day is 78 Minutes.
Which is 5x smaller than Day, then Week is 5x larger than Day. Don't over think it.
If too many time frames are checked, it can lead to analysis paralysis.

It is not the indicator that should change. Only the chart agg. 20 periods is 20 periods, no matter the time frame.
 
Last edited:
markos

markos

Well-known member
VIP


Looking for something like the bottom pane ?
@horserider THIS is how to do it. Notice in the study numbers that the AGG changes but the 20, 1.5, 2.0 do not. Excellent.
btw, please share complete chart and then just the study for the dots! If possible, greatly appreciated by all!
Sharing is Caring ;)
 
Last edited:
markos

markos

Well-known member
VIP
I don't believe it is possible. The time frames are predefined. Should be possible with getAggregationPeriod() but it is limited does not return required value.
@noobstocktrader101 Help yourself get balance. Trade using Paper Money for 1 Month and record everything you do incl. why you "Bot" or Sold.
General rules of thumb, NOT trading advice:
  • Always keep individual trades to 1% of potential loss, trade small and live to trade another day. This is simple but not easy.
  • Stick to a few stocks & indicators you know well and watch / write down if they fit the time you bot/sold.
  • Do you cut your losses & let winners run?
Why are you working with TTM Squeeze? What other indicators have you tried? Tell us, so it's easier to possibly help you. Thanks!
 
Last edited:
L

lucassow

New member
@lucassow Is this what you’re looking for? https://usethinkscript.com/threads/multi-timeframe-mtf-moving-average-indicator-for-thinkorswim.135/

If not, please make a separate post and explain what that trend script is.

Hi Ben Ten,
No it was not what i am looking for. Normally, i will click on different time frame to see the the particular candle is trending up or down.
I will probably click on 5M, then 15M, then 30M, then 1H and so on.
Wait, let me quickly Google it and see similarities in market, wait......
..........
ohhh i found something from google...

for MT4, it probably looks like:

Supposed if you are trading on current candle 1M showing bearish, then you would
want to know the trend up or down in 5M, 15M, and 30M just to see bigger picture.
Instead of doing it manually, i was thinking if thinkorswim have something similar?
(like an indicator to show different time frame on same chart)
 
BenTen

BenTen

Administrative
Staff
VIP
@lucassow Got it. Now, how would you define trend in this particular scenario? Did you look at the screenshot @horserider posted earlier. The indicator from the pic. seems to be based off of TTM.

Saying “MTF Trend” is too general. Is it based on MA, MACD, etc?
 
L

lucassow

New member
@lucassow Got it. Now, how would you define trend in this particular scenario? Did you look at the screenshot @horserider posted earlier. The indicator from the pic. seems to be based off of TTM.

Saying “MTF Trend” is too general. Is it based on MA, MACD, etc?
Hi
No it is not based on any MA, MACD etc indicator. Its just a multiple time frame to indicate different
trend of UP/DOWN by candlestick. Very basic ones. Let me try on @horserider script in TOS. Can i know
what does TTM stands for?
 
markos

markos

Well-known member
VIP
TTM is the name of the Person or Group that created the Study. As in, Bollinger Bands were created by Mr. Bollinger.
 
L

lucassow

New member
Ohhhh.... ok...
I dont seem to find the links on MY_MTF_TTM squeeze as the picture uploaded above. Do you have it?
 
T

tradegeek

New member
VIP
I believe TTM stands for "Trade The Markets" which was a collaborative venture between John Carter and Hubert Senters.

By the way, John Carter has updated the Squeeze with the Squeeze Pro after 10+ years. The updated indicator supposedly catches a lot of breakouts that the original Squeeze indicator misses.
 
H

horserider

Active member
@lucassow @laketrader MultiTime Frame TTM Squeeze. Here you go.

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);
 
L

lucassow

New member
@horserider
Do you have reading material to explain on its functionalities?
 

Top