TTM Squeeze Backtester
Build a light weight TTM Squeeze Backtester that allows you to test squeezes on different time frames, with tweaked nK and nBB factors.
Introduction
In today’s tutorial, we’ll walk you through the process of building a manual backtester for the TTM Squeeze in ThinkOrSwim. This guide will cover the basics of the TTM Squeeze, how to set up backtests, and how to optimize the indicator for various tickers and timeframes.
Today’s video is going to be in response to several user requests to try and understand the updated version of John Carter’s TTM_Squeeze Pro.
JC invented the squeeze and it has since become quite popular. Recently, he came out with a new version of this famous indicator, with updated settings that have new bells & whistles, among which includes updated settings for more accurate and more frequent signals.
In this tutorial, we try and build a lite-backtester, in which a user can tweak the user settings of the TTM_Squeeze to discover what settings work best for particular tickers. For example, on AAPL, we notice that that the TTM_Squeeze settings with an nBB factor of 1.5 outperformed the default 2.0 factor by almost 3x.
- TTM_Squeeze Default ( Close , 20, 1.5, 2.0) — Total P/L $1,281.99
- TTM_Squeeze Modified ( Close , 20, 2.0, 2.0) — Total P/L $562.72
- TTM_Squeeze Modified (Close, 20, 2.0, 1.5) — Total P/L $1,689.74
If you’d like to skip the tutorial and start playing with the indicator right away, it’s available to download for free below.
By the end of this tutorial, you’ll have a solid understanding of how to leverage the TTM Squeeze in ThinkOrSwim to build and refine your own custom trading strategies.
Volatility Box Invite
We are TOS Indicators.com, home of the Volatility Box.
The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.
We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.
Futures Volatility Box - Trade Major Markets With an Edge
Designed For: Futures, Micro-Futures and Index Market Traders
Supported Models: Hourly Volatility Box models
Supported Markets: 10 Major Futures Markets
The Futures Volatility Box comes with:
- 5 Volatility Models for each market
- Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
- Video Setup Guide
- Trade Plan
- Access to all members-only resources, including Squeeze Course
Learn More About the Futures Volatility Box
Trade futures and micro futures with a consistent volatility edge
Stock Volatility Box - Powerful Web Based Volatility Platform
Designed For: Stock and Options Traders
Supported Models: Hourly and Daily Volatility Box models
Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)
A Stock Volatility Box membership includes access to:
- Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
- Dashboard - A quick and easy way to view daily volatility model levels online
- Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
- Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
- All Members Only Indicators - We don't nickel and dime you. Everything really is included.
- And much more!
Learn More About the Stock Volatility Box
Trade stocks and options with a consistent volatility edge
What is the TTM Squeeze?
The TTM Squeeze is a momentum and volatility indicator designed to identify periods when a market is consolidating and preparing for a significant move. John Carter developed this indicator to capture explosive price movements that follow low-volatility periods. The indicator uses Bollinger Bands and Keltner Channels to determine market compression. When the Bollinger Bands move inside the Keltner Channels, it signifies a squeeze, indicating low volatility. When the Bollinger Bands move outside the Keltner Channels, it indicates that the squeeze has released, often leading to a strong price movement.
Why Backtest the TTM Squeeze?
Backtesting allows traders to simulate trades using historical data to evaluate the effectiveness of a strategy. By manually backtesting the TTM Squeeze, traders can identify the best settings for specific stocks, ensuring they maximize their chances of capitalizing on explosive price movements. This process helps refine the strategy, reduce risks, and improve overall trading performance.
Getting Started
Step 1: Switching to the Strategies Tab
- Open ThinkOrSwim and navigate to the Studies icon in the top right.
- Switch to the Strategies tab instead of the default Studies tab.
- Click Create to start building your strategy.
Switching to the Strategies tab is crucial as it allows us to test the strategy and analyze the results, providing a profit and loss report that helps in comparing different settings.
Step 2: Defining Variables
Start by defining the variables for the settings you want to test. These variables will allow you to tweak the TTM Squeeze settings to find the most effective configuration.
input length = 20;
input nk = 1.5;
input nb = 2.0;
def squeeze = TTM_Squeeze(close, length, nk, nb, 1.0).squeezeAlert;
Step 3: Creating a Trend Indicator
To determine the overall market direction, we’ll use exponential moving averages (EMAs). This helps in understanding whether the market trend is bullish or bearish, which is critical for making informed trading decisions.
def EMA13 = ExpAverage(close, 13);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def bullish = EMA13 > EMA21 and EMA21 > EMA34;
def bearish = EMA13 < EMA21 and EMA21 < EMA34;
Step 4: Setting Up Trade Conditions
We need to wait for at least five red squeeze dots before entering a trade. This ensures that the market has been in a low-volatility state for a sufficient period before we expect a significant move.
def squeezeAlert = Sum(squeeze, 5) == 0;
def bullishSignal = if squeezeAlert and bullish then 1 else 0;
def bearishSignal = if squeezeAlert and bearish then 1 else 0;
Step 5: Defining Exit Conditions
Set exit conditions based on EMA crosses. This helps in determining the best time to exit a trade, ensuring that we capture maximum profit or minimize losses.
def exitBullish = EMA13 crosses below EMA21;
def exitBearish = EMA13 crosses above EMA21;
Step 6: Adding Orders
Use AddOrder
to implement buy and sell conditions. This is where we define the actual trading logic, telling ThinkOrSwim when to enter and exit trades.
AddOrder(OrderType.BUY_TO_OPEN, bullishSignal, close, 100);
AddOrder(OrderType.SELL_TO_CLOSE, exitBullish, close, 100);
AddOrder(OrderType.SELL_TO_OPEN, bearishSignal, close, 100);
AddOrder(OrderType.BUY_TO_CLOSE, exitBearish, close, 100);
Running the Strategy
After defining the strategy, click OK and review the trades on your chart. Use the Global Strategy Settings to display the floating P&L for a quick overview of performance. This helps in quickly assessing whether the strategy is profitable or needs adjustments.
Practical Examples
Example 1: Testing on Goldman Sachs
- Using default settings:
- EMA13 > EMA21 > EMA34 for bullish signals
- EMA13 < EMA21 < EMA34 for bearish signals
- Resulted in an overall negative P&L
This example shows that not all stocks will perform well with the default settings, highlighting the importance of backtesting and tweaking the parameters.
Example 2: Testing on Apple
- Tweaking settings to:
length = 20
nk = 1.5
nb = 2.0
- Resulted in a positive P&L
By adjusting the settings, we found a configuration that works well for Apple, resulting in profitable trades. This demonstrates the value of customizing the TTM Squeeze settings for different stocks.
Advanced Customizations
Adding Profit Targets
In addition to exit conditions based on EMA crosses, you can set profit targets to exit trades once a certain profit level is achieved.
AddOrder(OrderType.SELL_TO_CLOSE, high >= EntryPrice() * 1.03, close, 100);
AddOrder(OrderType.BUY_TO_CLOSE, low <= EntryPrice() * 0.97, close, 100);
Including Stop-Loss Orders
Incorporate stop-loss orders to limit potential losses, ensuring that your trading strategy remains robust under different market conditions.
AddOrder(OrderType.SELL_TO_CLOSE, low <= EntryPrice() * 0.97, close, 100); AddOrder(OrderType.BUY_TO_CLOSE, high >= EntryPrice() * 1.03, close, 100);
Optimizing the Strategy
To optimize the strategy, continuously test and tweak the settings. Analyze the results and adjust the parameters based on the performance of different stocks and timeframes.
Example: Testing Different Timeframes
Testing on a 30-minute chart:
- Adjust
length
,nk
, andnb
to see how the strategy performs on shorter timeframes. - Evaluate the P&L report to determine profitability.
Testing on a daily chart:
- Adjust the parameters to match the characteristics of the daily timeframe.
- Compare results with other timeframes to find the most profitable settings.
Conclusion
By following this comprehensive guide, you can build a manual backtester for the TTM Squeeze in ThinkOrSwim. Experiment with different settings and timeframes to find what works best for your preferred tickers. Download the strategy code for free from the link below and start optimizing your trading strategies today.
Thank you for watching this episode. If you have any indicators you’d like to see, feel free to comment below or contact us through our website. Happy trading!
Additional Resources
For more information on the TTM Squeeze and other trading strategies, check out our other tutorials and resources available on our website. Join our community of traders and stay updated with the latest trading techniques and tools.
downloads
Download the TTM Squeeze Backtester for ThinkorSwim.
The download contains a STRATEGY.ts file, which you can import directly into your TOS platform.
Download Backtester
Download the TTM Squeeze Backtester for ThinkorSwim.
The download contains a STRATEGY.ts file, which you can import directly into your TOS platform.