Multi-Time Frame Squeeze

Build a multiple time frame squeeze that shows you all the different time frames in which we have a TTM_Squeeze

youtube-video-thumbnail
Volatility Box Members:

The Multi-Time Frame Triple Pro Squeeze is available for download here, and is included with your Volatility Box membership. In the pro version, we expand the squeeze to work with 3 different compression factors to find more squeezes.

For our 18th episode of "how to ThinkScript," we’re going to be building a Multi-Time Frame (MTF) Squeeze indicator, that helps you easily find the default TTM_Squeezes on multiple time frames, in one easy glance.

MTF Squeeze - ThinkOrSwim Indicator

The basic version of the MTF Squeeze indicator is available for free download at the bottom of this page.

For all of our Volatility Box members, we’ve taken this indicator one step further for you, and added in all 3 compressions from the Triple Pro Squeeze course, along with implemented functionality to allow you to easily change the label’s colors.

Multi-Time Frame (MTF) Squeeze Tutorial

The custom code written for the Multi-Time Frame Squeeze Indicator is available for free download below.

Volatility Box Invite

We are TOS Indicators.com, home of the Volatility Box.

Our Futures Volatility Box gave us a nearly perfect entry to get short Natural Gas (/NG Futures), which led to a beautiful trade into the close of Friday.

  1. Price hit our Volatility Box levels for a short
  2. We even had an Edge Signals confirmation arrow
  3. And we can see what ended up happening to price

Our first and second targets were $0.017 and $0.029 /NG ticks, and we saw a max move of a little more than $0.050 /NG ticks.

For anyone interested in using the Volatility Box to trade either Futures or Stock, we’re offering a bundle discount for a limited time.

If you’d like more information, send us an e-mail at co*****@to***********.com .

That’s the power of being able to use Volatility Models and Price Movement Ranges that you can trust.

 

Concepts

There are a few different concepts that we’re going to be covering in this tutorial.

Multi-Time Frame Squeeze Tutorial Concepts

The main concept that we’re going to be implementing is using our “Drag and Drop” multiple time frame module code, that we built as part of the MTF DMI indicator tutorial, as our main building blocks here.

We had discussed this in that tutorial as well – the importance of writing some of this type of code in a way that we can easily lift and re-use it for new purposes.

Similarly, if you wish to build your own MTF version of something, you should be able to use this same framework, that’s available for free.

Another concept that we’re going to be discussing is around formatting. In this particular tutorial, we’re going to be working a lot with labels, and connecting Boolean conditions, such as whether or not we have a squeeze, to turn a certain color.

Multi Time Frame (MTF) Squeeze Histogram and Multi Time Frame (MTF) Squeeze

For all of our Volatility Box members who have already gone through the MTF Squeeze Histogram tutorial, we’ll also be showing you the trick to have the labels stack on top of one another.

And finally, the last concept that we’re going to discuss is finding an alternative to referencing the built-in TTM_Squeeze function in ThinkOrSwim, and using source code instead.

One of the nuances, or glitches rather, is that references to the TTM_Squeeze function, inside of an if/else clause that also includes an aggregation period tends to lead to false-squeezes. That is, the labels don’t plot as expected.

To work around that limitation, we use the source code for the TTM_Squeeze instead.

Here is a link to the thinkScripter who has the TTM_Squeeze source code available via Blogspot.

What is the TTM_Squeeze?

We’re going to start by first reading the definition of the TTM_Squeeze, using the TLC ThinkOrSwim website. This is a great resource if you’re looking for more help around particular indicators.

Here, the key takeaways should be that the squeeze measures the relationship between two indicators:

  • Bollinger Bands
  • Keltner Channels

They even tell us that the squeeze occurs whenever the Bollinger Bands fall inside of the Keltner Channels.

So that’s the trigger condition, and while the TTM_Squeeze source code is hidden in ThinkOrSwim, the Bollinger Bands and Keltner Channels code is available for the public.

Bollinger Band Source Code

Here is the Bollinger Band source code, for those interested in using this along with the Keltner Channels to recreate the squeeze:

input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = price[-displace], length = length);

def MidLine = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

The code can also be found directly inside of your ThinkOrSwim platform (clicking the scroll icon on the Bollinger Band study).

As covered in the Triple Pro Squeeze course, the Bollinger Bands fuel the input of the "nB" factor in the built-in TTM_Squeeze study.

Keltner Channels Source Code

Here is the source code for the Keltner Channels, once again, available for access via the ThinkOrSwim platform.

input displace = 0;
input factor = 1.5;
input length = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

def average = MovingAverage(averageType, price, length);

def Avg = average[-displace];
def Upper_Band = average[-displace] + shift[-displace];
def Lower_Band = average[-displace] - shift[-displace];

A couple (easy) things to note:

  • You can check for either the upper Bollinger Band crossing below the upper Keltner Channels or, use the opposite logic with the lower set of bands
  • Several of the input variables are duplicated, and will need to be consolidated to have only one variable value

Multi-Time Frame "Framework" Code

Here is the “framework” for our multiple time frame code, from the MTF DMI:

Multi-Time Frame (MTF) DMI ThinkOrSwim indicator

You should start to notice is a pattern.

We have our variables that change for each aggregation period, defined above the “if” clause.

Those variables are then defined inside of the “if” and “else” clauses, although our else clause automatically sets the value to equal 0. And each of our if periods is a check to see whether or not we are on an Aggregation Period less than the one we are testing against.

This is another little nuance of ThinkOrSwim. You can only see the aggregation periods equal to or greater than your current time frame chart.

This means, if you are on a 5m chart, you will not be able to see a 1m, 2m, 3m or 4m squeeze.

Monthly MTF Squeeze Code

Let's start by first using the MTF Framework to create the Monthly TTM_Squeeze label code:

##Global Variables
def length = 20;
def AlertLine = 1;
def nk = 1.5;
def nBB = 2;
def averageTpype = AverageType.SIMPLE;
def displace = 0;
def trueRangeAverageType = AverageType.SIMPLE;

## Month Aggregation Period Variables
def monthPrice;
def monthATR;
def monthSDev;
def monthDenom;
def monthBBSInd;
def monthSqueeze;
def monthAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.Month {
    monthPrice = close(period="Month");
    monthATR = Average(TrueRange(high (period="Month"), close(period="Month"), low(period="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;
    monthAggregationPeriod = 1;
}
else {
    monthPrice = 0;
    monthATR = 0;
    monthSDev = 0;
    monthDenom = 0;
    monthBBSInd = 0;
    monthSqueeze = 0;
    monthAggregationPeriod = 0;
}
AddLabel(monthSqueeze and monthAggregationPeriod, "M", color.red);
AddLabel(!monthSqueeze and monthAggregationPeriod,"M", color.dark_green);

[su_note note_color="#FAFAFA" text_color="#333333" radius="3" class="" id=""] **NOTE: An "aggregationPeriod" variable in the form of "monthAggregationPeriod" is added to turn off the irrelevant labels, if on a smaller time frame chart. [/su_note]

Download

Click the button below to download the code for the Multi-Time (MTF) Frame Squeeze Indicator.

We're always looking for folks who enjoy thinkScripting, and testing new trading indicators.

If this sounds like you, join our Beta Group here.

Table of Contents
    Add a header to begin generating the table of contents