- Build a Comprehensive Multi-Time Frame Squeeze Dashboard
- Understanding Multi-Timeframe Trading Challenges
- The Reusable Code Framework Concept
- TTM Squeeze Logic and Custom Implementation
- Step-by-Step Coding Tutorial: Building the MTF Squeeze
- Advanced Implementation Strategies
- Common Implementation Mistakes and Solutions
- Real-World Trading Applications
- Framework Extension for Other Indicators
Multi-Timeframe Analysis with the MTF Squeeze Indicator
Stop switching between timeframes to check squeeze conditions. This Multi-Time Frame Squeeze indicator displays TTM squeeze status across all major timeframes in one compact dashboard.
Key features of this MTF Squeeze indicator:
- Displays squeeze conditions from monthly down to 1-minute charts
- Color-coded labels for instant visual identification
- Reusable framework for other multi-timeframe indicators
- Custom source code that avoids built-in TTM squeeze limitations
Perfect for traders who need comprehensive timeframe analysis without cluttering their charts with multiple indicators.
Build a Comprehensive Multi-Time Frame Squeeze Dashboard
Most traders struggle with timeframe analysis because they’re constantly switching between charts to check squeeze conditions. The Multi-Time Frame (MTF) Squeeze indicator solves this problem by displaying squeeze status across all major timeframes in one compact, visual dashboard. This tutorial teaches you to build a sophisticated MTF indicator using reusable code frameworks and custom squeeze calculations.
Understanding Multi-Timeframe Trading Challenges
Effective trading requires understanding market conditions across multiple timeframes, but traditional approaches create several problems:
Chart Clutter: Loading separate squeeze indicators for each timeframe makes charts unreadable and overwhelming.
Time Wastage: Constantly switching between timeframes to check conditions interrupts trading flow and causes missed opportunities.
Incomplete Analysis: Traders often check only 2-3 timeframes instead of the comprehensive view needed for optimal entries.
Platform Limitations: ThinkOrSwim’s built-in TTM squeeze has restrictions when used with aggregation periods that create false signals.
The MTF Squeeze dashboard addresses all these issues by providing a single indicator that monitors squeeze conditions across 17 different timeframes simultaneously.
The Reusable Code Framework Concept
Before diving into the squeeze-specific code, it’s crucial to understand the modular framework approach that makes this indicator possible. This same framework can be adapted for any multi-timeframe indicator, whether you want MTF moving average crossovers, RSI conditions, or custom oscillators.
Framework Benefits:
- Write the core logic once and replicate it across timeframes
- Easy maintenance and updates to calculation methods
- Consistent variable naming makes debugging simple
- Text editor find-and-replace speeds up development
The framework uses a specific pattern: define variables outside if/else blocks, then populate them within aggregation period checks. This approach ensures clean code organization and prevents compilation errors.
TTM Squeeze Logic and Custom Implementation
The TTM Squeeze measures the relationship between Bollinger Bands and Keltner Channels. When Bollinger Bands contract inside Keltner Channels, a squeeze condition exists, indicating low volatility that often precedes significant price movements.
Why Custom Source Code is Necessary:
ThinkOrSwim’s built-in TTM squeeze function has limitations when used within aggregation period if/else statements. The function doesn’t return expected boolean values, leading to false squeeze signals. Instead, we implement the squeeze calculation using the documented relationship between Bollinger Bands and Keltner Channels.
Core Squeeze Calculation:
- Calculate Bollinger Band standard deviation
- Calculate Keltner Channel ATR-based width
- Compare the ratio to determine squeeze conditions
- Use boolean logic to create clear on/off signals
Step-by-Step Coding Tutorial: Building the MTF Squeeze
Follow this comprehensive tutorial to build your MTF Squeeze indicator from scratch, learning the framework approach that can be applied to any multi-timeframe analysis.
Step 1: Setting Up Global Variables
Start by defining variables that remain constant across all timeframes. These represent the core squeeze parameters that don’t change whether you’re analyzing monthly or 1-minute data:
def length = 20;
def AlertLine = 1;
def nK = 1.5;
def nBB = 2;
def averageType = AverageType.SIMPLE;
def displace = 0;
def trueRangeAverageType = AverageType.SIMPLE;
These values match ThinkOrSwim’s default TTM squeeze settings. The nK factor (1.5) controls the Keltner Channel width, while nBB (2) sets the Bollinger Band standard deviation multiplier. The AlertLine (1) determines the threshold for squeeze detection.
Step 2: Understanding the Aggregation Period Framework
ThinkOrSwim has a key limitation: you can only access timeframes equal to or greater than your current chart timeframe. This means on a 5-minute chart, you can access 5-minute, 15-minute, hourly, and higher timeframes, but not 1-minute through 4-minute data.
The framework uses this logic pattern:
if GetAggregationPeriod() <= AggregationPeriod.MONTH {
// Define calculations for monthly timeframe
} else {
// Set default values when timeframe isn't accessible
}
This ensures the indicator only shows data for accessible timeframes while maintaining clean code structure.
Step 3: Defining Variables for the First Timeframe
For each timeframe, we need to define the same set of variables outside the if/else blocks, then populate them inside. Start with the monthly timeframe:
def monthPrice;
def monthATR;
def monthSDev;
def monthDenom;
def monthBBSInd;
def monthSqueeze;
def monthAggregationPeriod;
Each variable serves a specific purpose in the squeeze calculation:
- monthPrice: Closing price for the monthly timeframe
- monthATR: Average True Range for Keltner Channel calculation
- monthSDev: Standard deviation for Bollinger Band width
- monthDenom: Denominator (nK × ATR) for the squeeze ratio
- monthBBSInd: Final squeeze ratio calculation
- monthSqueeze: Boolean squeeze condition (1 or 0)
- monthAggregationPeriod: Flag indicating if timeframe is accessible
Step 4: Implementing the Squeeze Calculation Logic
Inside the aggregation period check, implement the core squeeze calculation. This is where we translate the Bollinger Band vs. Keltner Channel relationship into code:
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;
}
The key insight is the monthBBSInd calculation: When (nBB × Standard Deviation) ÷ (nK × ATR) is less than 1, Bollinger Bands are inside Keltner Channels, indicating a squeeze condition.
Step 5: Creating Visual Labels
Transform the boolean squeeze conditions into visual labels that provide instant feedback about market conditions:
AddLabel(monthSqueeze and monthAggregationPeriod, "M", Color.RED);
AddLabel(!monthSqueeze and monthAggregationPeriod, "M", Color.DARK_GREEN);
This creates two labels for the monthly timeframe:
- Red "M" label: Appears when a monthly squeeze exists
- Dark green "M" label: Appears when no monthly squeeze exists
The monthAggregationPeriod condition ensures labels only appear when the timeframe is accessible from your current chart.
Step 6: Scaling to Multiple Timeframes Using Text Editors
Rather than manually typing code for each timeframe, use a text editor's find-and-replace function to rapidly create variations. Copy your monthly code block to a text editor like Sublime Text or VS Code.
Find-and-Replace Process:
- Copy the complete monthly code block
- Use Ctrl+H (or Cmd+H on Mac) to open find-and-replace
- Find: "month" → Replace: "week"
- Update the aggregation period: AggregationPeriod.Month → AggregationPeriod.WEEK
- Update the period string: "Month" → "Week"
- Update the label: "M" → "W"
This process transforms your monthly code into weekly code in seconds. Repeat for all desired timeframes: 4-day, 3-day, 2-day, daily, 4-hour, 2-hour, 1-hour, 30-minute, 20-minute, 15-minute, 10-minute, 5-minute, 4-minute, 3-minute, 2-minute, and 1-minute.
Step 7: Handling Timeframe-Specific Nuances
Some timeframes require special handling due to ThinkOrSwim's naming conventions:
Day Period: Use "day" instead of "1 day"
Hour Period: Use "1 Hour" for the period string
Minute Periods: Use "1 Min", "2 Min", etc.
Multi-Day Periods: Use "4 days", "3 days", "2 days" with numbers
These nuances are important for proper compilation. Test each timeframe addition to ensure no syntax errors.
Step 8: Color Coding and Visual Organization
Organize your labels with consistent color coding that provides intuitive market feedback:
Standard Color Scheme:
- Red: Squeeze condition exists (low volatility, potential breakout coming)
- Dark Green: No squeeze (normal volatility conditions)
- Gray: Alternative for fast compression squeezes (if implementing multiple compressions)
- Yellow: Alternative for slow compression squeezes
For advanced implementations, you can create input variables that allow users to customize colors directly from the studies menu, making the indicator more versatile for different trading styles and visual preferences.
Step 9: Testing and Validation
Before using the indicator live, validate its accuracy against ThinkOrSwim's built-in TTM squeeze:
Validation Process:
- Apply your MTF Squeeze indicator to a chart
- Add the built-in TTM Squeeze indicator
- Switch to monthly timeframe and verify the "M" label matches TTM squeeze status
- Repeat for weekly, daily, and intraday timeframes
- Test on different stocks to ensure consistent behavior
Any discrepancies likely indicate syntax errors in the aggregation period strings or calculation logic.
Step 10: Advanced Features and Customization
Once your basic MTF Squeeze works correctly, consider these advanced enhancements:
Multiple Compression Levels: Add variables for nK2 and nK3 to track fast, medium, and slow squeeze compressions simultaneously.
User Inputs: Convert def variables to input variables, allowing customization of length periods, color schemes, and compression factors.
Alert Integration: Add Alert() functions to notify when squeeze conditions change on key timeframes.
Label Stacking: Use chart window sizing to stack multiple MTF indicators vertically for comprehensive dashboard views.
Advanced Implementation Strategies
Performance Optimization: The MTF Squeeze can be resource-intensive due to multiple timeframe calculations. Consider limiting timeframes to those most relevant to your trading style. Day traders might focus on 1-minute through 4-hour timeframes, while swing traders emphasize daily through monthly periods.
Integration with Other Indicators: The MTF Squeeze works excellently alongside other multi-timeframe tools. Consider combining with MTF moving averages, RSI conditions, or custom oscillators using the same framework approach.
Market Context Awareness: Different markets behave differently during squeeze conditions. Stocks often see explosive moves after squeezes, while forex pairs might show more gradual trend development. Adjust your interpretation based on the asset class.
Common Implementation Mistakes and Solutions
Variable Definition Errors: Always define variables outside if/else blocks before populating them inside. ThinkScript requires this order for proper compilation.
Aggregation Period Mismatches: Ensure your period strings match ThinkOrSwim's exact naming conventions. "1 Hour" works, but "1hour" doesn't.
Label Overlap Issues: When multiple timeframes show squeezes, labels can overlap. Use different colors or adjust chart window sizing to maintain readability.
False Signal Debugging: If labels don't match expected squeeze conditions, verify your nK and nBB factors match the built-in TTM squeeze settings you're comparing against.
Real-World Trading Applications
Entry Timing: Use multiple timeframe squeeze alignment for high-probability entries. When 3+ timeframes show squeezes simultaneously, subsequent breakouts often have exceptional follow-through.
Exit Strategy: Monitor higher timeframes for squeeze resolution as exit signals. If daily and weekly squeezes resolve while intraday squeezes remain, consider profit-taking approaches.
Market Scanning: Apply the MTF Squeeze to watchlists for systematic opportunity identification. Stocks showing squeeze alignment across multiple timeframes often provide the best risk-reward setups.
Risk Management: Avoid trading during widespread squeeze conditions across many timeframes, as these periods often precede high-volatility events that can be unpredictable in direction.
Framework Extension for Other Indicators
The MTF framework used for the squeeze indicator can be adapted for virtually any trading concept:
MTF Moving Average Crossovers: Track EMA/SMA crossovers across timeframes to identify trend alignment opportunities.
MTF RSI Conditions: Monitor overbought/oversold conditions across multiple timeframes for confluence-based entries.
MTF Support/Resistance: Identify key levels that align across multiple timeframes for high-probability reversal zones.
MTF Volume Analysis: Track volume spikes or unusual activity patterns across different timeframes for breakout confirmation.
Each adaptation follows the same variable definition → aggregation period check → calculation → label display pattern, making the framework highly reusable for systematic indicator development.
The Multi-Time Frame Squeeze indicator represents more than just a trading tool—it's a comprehensive approach to timeframe analysis that can transform how you identify and execute trading opportunities. By mastering both the specific squeeze implementation and the underlying framework concepts, you gain the ability to create sophisticated multi-timeframe analysis tools tailored to your exact trading requirements.
#TOS Indicators
#Home of the Volatility Box
#Indicator Name: Multi-Time Frame Squeeze
#Full Tutorial Available Here: www.tosindicators.com/indicators/mtf-squeeze
#Contains TTM_Squeeze Source Code, found here (http://freethinkscript.blogspot.com/2009/05/ttm-like-squeeze-indicator-with.html)
// ... 33 more lines ...Here are some resources that you may find useful: