Moving Average Crossover Backtester
Learn to build two advanced ATR scans in ThinkOrSwim. Discover stocks with high volatility and compression patterns near key moving averages.
Introduction
This tutorial reveals how to leverage ThinkOrSwim’s scanning tools to identify high-probability trading setups using Average True Range (ATR) and moving averages. The first scan detects stocks with above-average volatility by comparing current ATR values to their 50-period moving average. This helps traders spot potential breakout candidates before major price movements occur.
The second scan combines ATR compression with moving average relationships to find consolidation patterns near the 50 SMA. Using examples like Micron Technologies (MU), we’ll demonstrate how to identify stocks where the 8 EMA > 34 EMA > 50 SMA while maintaining tight trading ranges. These conditions help traders locate potential continuation plays in trending markets.
Both scans incorporate practical filters including $10+ stock price, 2M+ average volume, and specific percentage thresholds from key moving averages. By mastering these techniques, traders can efficiently screen 6,000+ stocks to find the best opportunities while avoiding common execution timeout errors.
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
Understanding the ATR Scanning Framework
The Average True Range (ATR) measures market volatility by calculating the true price range over a specified period. In Scan 1, we compare current ATR values to a 50-period simple moving average to identify above-average volatility conditions. Stocks like NVDA and F appear in results when their daily ATR exceeds this benchmark, signaling potential momentum shifts.
Scan 2 combines ATR with moving average hierarchy to find consolidation patterns. The tutorial uses Micron Technologies (MU) as a prime example, where price compresses within 5% of the 50 SMA while maintaining 8 EMA > 34 EMA > 50 SMA structure. This multi-filter approach reduces 6,123 stocks to just 4 high-probability candidates in the final scan results.
Both scans use ThinkOrSwim’s custom filter builder with liquidity safeguards. The $10 minimum price and 2M+ volume filters ensure traders focus on liquid assets, while the ATR(14) and SMA(50) parameters create adaptable conditions for different market environments.
Key Components and Settings
The volatility scan requires three core elements: ATR(14) calculation, 50-period SMA of ATR, and comparison logic (current ATR > SMA). Users can modify the ATR length (20 shown in demo) and average type (Wilders vs Exponential) for different volatility measurements. Results like Ford (F) demonstrate successful triggers when daily ranges expand beyond historical norms.
The compression scan adds four layers: 10-bar price range (High-Low) < 2xATR, price within 5% of 50 SMA, 8 EMA > 34 EMA, and 34 EMA > 50 SMA. These settings identified MU when it traded between $75.60-$79.20 (5% of $77.40 SMA) with aligned moving averages. The 2xATR multiplier ensures meaningful compression relative to recent volatility.
Additional filters include SMA(200) positioning and adjustable percentage thresholds. By requiring SMA(50) > SMA(200), traders eliminated stocks like ROKU that showed compression but lacked broader trend alignment. Reducing the SMA proximity from 5% to 3% further refined results to 2 prime candidates.
Step-by-Step Implementation
Start Scan 1 by creating a Stock Filter with price > $10 and volume > 2M shares. Add Custom Study using ‘def atr = ATR();’ and ‘def avgAtr = Average(atr,50);’. Set plot condition to ‘atr > avgAtr’ and select Daily timeframe. This produced 246 results including NVDA pre-breakout.
For Scan 2, build the base liquidity filters then add: 10-bar range (highest(high,10) – lowest(low,10)) < 2*ATR. Create EMA(8), EMA(34), and SMA(50) variables. Add conditions: Close within 5% of SMA(50), EMA(8) > EMA(34), EMA(34) > SMA(50). Final filters reduced 25 compression candidates to MU and AM through SMA(200) validation.
Optimize scans using ThinkorSwim’s ‘Edit Studies’ feature. Change ATR length to 20 via parameter input, or switch from SMA to EMA averages by modifying the ‘AverageType.EXPONENTIAL’ argument. Test different compression multipliers (1.5x-3xATR) and SMA proximity (3%-7%) across sectors for varied results.
Trading Strategies
Use Scan 1 results for breakout plays: When NVDA’s ATR surpassed its 50-day average, the stock rallied 12% in three sessions. Combine with upper Bollinger Band breaks or volume spikes for confirmation. Set stops below recent lows using 1.5xATR values (e.g., $3.50 stop on $70 stock).
Scan 2 candidates suit mean-reversion strategies: MU’s compression near SMA(50) preceded a 9% upside move. Enter long when price crosses above EMA(8) with bullish RSI divergence. Target previous swing highs while monitoring the 34 EMA as dynamic support.
Combine both scans for sector rotation: High ATR stocks indicate sector momentum, while compression patterns highlight consolidation areas. Trade SPY options when multiple sector leaders like MU and AM trigger both scan conditions simultaneously.
Advanced Techniques
Incorporate secondary confirmation via ThinkorSwim’s ‘Edge Signals’ study. The green arrow indicator appeared on MU’s chart during compression, validating the bullish bias. Add this as an extra filter using ‘Edges.Direction.UP’ in scan code to reduce false signals.
Create scan alerts for real-time notifications. Right-click any scan result > Create Alert > Choose ‘Play Sound’ or ‘Send Email’. Set alerts for when stocks exit compression ranges (Close > highest(high,10)) to catch early breakouts.
Backtest parameters using ThinkorSwim’s OnDemand feature. Test how 3% vs 5% SMA proximity performed during 2023’s bull market vs 2022’s bear market. Historical analysis showed 5% thresholds captured 22% more valid setups in trending markets.
Common Pitfalls to Avoid
Avoid using scans in isolation – always validate with price action. ROKU met all technical filters but failed because resistance at $85 SMA(200) overwhelmed the pattern. Check higher-timeframe levels before executing trades.
Don’t ignore sector context. The scan identified T-Mobile (TMUS) during sector-wide consolidation. Pair results with SPDR sector ETF analysis – only trade setups aligning with XLC’s bullish structure in this case.
Prevent timeout errors by optimizing filters. The tutorial’s 2M volume filter reduced scan universe from 6,123 to 4,891 stocks. If scans timeout, increase price/volume thresholds incrementally rather than removing technical conditions.
Best Practices
Save scan configurations as templates for quick access. Name them ‘ATR Volatility Scan’ and ‘SMA Compression Scan’ with version numbers (v1.2). Export/share scans via ThinkorSwim’s ‘Setup > Export’ feature for team collaboration.
Update parameters quarterly. During earnings seasons, increase ATR multiples to 2.5x to account for heightened volatility. In range-bound markets, tighten SMA proximity to 3% and require ADX(14) > 25 for clearer trends.
Combine with options flow analysis. When MU appeared in scans, unusual $80 call buying preceded the breakout. Use ThinkorSwim’s Options Flow scanner to detect smart money activity in scan results.
downloads
Download the Moving Average Crossover Backtester Indicator for ThinkOrSwim.
The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.
Download Indicator
Download the Moving Average Crossover Backtester Indicator for ThinkOrSwim.
The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.