Gamestop Stock Backtester
How to build a Hull Moving Average backtester for GameStop (GME) in ThinkOrSwim. Includes full ThinkScript code, TTM Squeeze filter, scanner setup, and tips for analyzing your own backtest results.
- Why Backtest the Hull Moving Average on GameStop?
- What Is the Hull Moving Average?
- Hull MA Backtester: The ThinkScript Code
- What the GME Backtest Actually Shows
- How to Analyze Your Results
- Adding Filters to Improve Results
- Building a Hull MA Scanner
- Adapting This Backtester for Other Stocks
- Risk Management Considerations
- Next Steps
- Frequently Asked Questions
Why Backtest the Hull Moving Average on GameStop?
GameStop (GME) is one of the most volatile stocks in the market. That volatility makes it a good stress test for any moving average system. The Hull Moving Average (HMA) is a speed-optimized moving average developed by Alan Hull that reduces lag compared to a standard SMA or EMA while maintaining smoothness. Running a backtest on GME helps you determine whether faster signal generation translates to better results on a high-volatility ticker.
In the companion video above, we build this entire backtester from scratch in under 5 minutes. This article walks through the code, the setup, and how to interpret and extend the results yourself.
What Is the Hull Moving Average?
The Hull Moving Average uses weighted moving averages and a square root smoothing period to cut lag. Alan Hull introduced this indicator in 2005 to solve a common problem: traditional moving averages are either too slow (SMA) or too noisy (short-period EMA). The HMA formula calculates a WMA of length N, a WMA of length N/2, then applies a final WMA of length square root of N to the difference.
In ThinkOrSwim, the Hull MA is available as a built-in study under "Studies > Moving Averages > HullMovingAvg." You can adjust the length and price type. The Hull MA changes color when its slope shifts from positive to negative. This color change acts as the buy/sell trigger in our backtester.
Many traders using thinkorswim indicators rely on this slope-based signal rather than a traditional crossover with price.
Hull MA Backtester: The ThinkScript Code
The backtester uses a straightforward approach. A buy signal triggers when the Hull MA shifts to its "up" color (current value greater than the previous bar). A sell signal triggers on the opposite condition. We also add Boolean inputs so you can toggle long entries and short entries independently, giving you cleaner results for each direction.
# Hull Moving Average Backtester
# Builds a simple strategy using HMA color changes as entry/exit triggers
input longEntries = yes;
input shortEntries = yes;
input price = close;
input length = 20;
def HMA = HullMovingAvg(price, length);
def buyTrigger = HMA > HMA[1];
def sellTrigger = HMA <= HMA[1];
# Long side
AddOrder(OrderType.BUY_TO_OPEN, buyTrigger and longEntries, close, 1,
Color.GREEN, Color.GREEN, "Hull Buy");
AddOrder(OrderType.SELL_TO_CLOSE, sellTrigger and longEntries, close, 1,
Color.RED, Color.RED, "Hull Sell");
# Short side
AddOrder(OrderType.SELL_TO_OPEN, sellTrigger and shortEntries, close, 1,
Color.RED, Color.RED, "Hull Short");
AddOrder(OrderType.BUY_TO_CLOSE, buyTrigger and shortEntries, close, 1,
Color.GREEN, Color.GREEN, "Hull Cover");This code plugs directly into the ThinkOrSwim strategy engine. The AddOrder functions execute trades at the closing price of the candle where the condition is met. You can apply it to any chart timeframe and any stock.
What the GME Backtest Actually Shows
In the video, we test this on GME across two timeframes to see how the Hull MA behaves on a volatile ticker.
On the 1-hour chart (180 days of data), the strategy caught one large long-side move but otherwise flipped back and forth frequently. The net P&L was negative for that period. The Hull MA's sensitivity creates whipsaws during choppy, sideways action, and GME spends a lot of time chopping between moves.
Switching to the 15-minute chart produced a different picture. More trade entries, more precision on shorter swings, and a P&L curve that looked considerably better than the 1-hour version. The shorter timeframe gave the Hull MA more data points to work with and reduced the impact of any single whipsaw.
The takeaway: timeframe matters. The same indicator on the same stock can produce very different results depending on how you configure the chart. This is exactly why you run the backtest yourself rather than relying on someone else's numbers.
How to Analyze Your Results
After running the strategy, right-click on the chart and select "Show Report." The Strategy Report shows total trades, win rate, net P&L, profit factor, and a full trade-by-trade log. You can export this data to CSV for deeper analysis in Excel or Google Sheets.
Some things to look for when reviewing GME backtest results:
- Are most of the profits coming from one or two outlier trades, or is the P&L distributed across many winners?
- During which market hours does the Hull MA perform best? You can filter the trade log by time of day.
- How does the strategy perform during high-volatility events (earnings, short squeezes) versus normal trading days?
The video mentions this directly: take the raw data and dissect it to find patterns. Maybe the Hull MA color change works better during regular market hours than during extended sessions. Maybe it works better on specific days of the week. The backtester gives you the data. The analysis is up to you.
Adding Filters to Improve Results
The base backtest uses only the Hull MA color change as an entry signal. That is intentionally simple so you can see the raw indicator performance. From there, you can layer on filters to reduce false signals.
A few approaches worth testing:
- Add a momentum oscillator (like the Momentum Cross study) as exit confirmation instead of waiting for the Hull MA to change color again
- Use the TTM Squeeze to filter entries. Only take Hull MA signals when the squeeze has recently fired, avoiding range-bound chop
# Hull MA Backtester with TTM Squeeze Confirmation
# Only enters when squeeze has recently released
input longEntries = yes;
input shortEntries = yes;
input price = close;
input hmaLength = 20;
input squeezeLength = 20;
input nk = 1.5;
input nBB = 2.0;
def HMA = HullMovingAvg(price, hmaLength);
def buyTrigger = HMA > HMA[1];
def sellTrigger = HMA <= HMA[1];
# TTM Squeeze Detection
def bbUpper = BollingerBands(price, squeezeLength, 0, nBB).UpperBand;
def bbLower = BollingerBands(price, squeezeLength, 0, nBB).LowerBand;
def kcUpper = KeltnerChannels(squeezeLength, nk, 0).Upper_Band;
def kcLower = KeltnerChannels(squeezeLength, nk, 0).Lower_Band;
def squeezeFiring = bbLower > kcLower and bbUpper < kcUpper;
def squeezeReleased = !squeezeFiring and squeezeFiring[1];
# Only enter on Hull trigger when squeeze recently released
AddOrder(OrderType.BUY_TO_OPEN, buyTrigger and longEntries
and squeezeReleased within 3 bars, close, 1,
Color.GREEN, Color.GREEN, "Hull+Squeeze Buy");
AddOrder(OrderType.SELL_TO_CLOSE, sellTrigger and longEntries, close, 1,
Color.RED, Color.RED, "Hull+Squeeze Sell");Run both the filtered and unfiltered versions on the same chart to compare. ThinkOrSwim renders each strategy's buy/sell arrows in different colors, making it easy to see where the squeeze filter would have kept you out of losing trades.
Building a Hull MA Scanner
Beyond backtesting GME, you can scan the entire market for Hull MA signals. This helps you find other volatile tickers where the Hull MA color change is occurring right now.
# Hull MA Color Change Scanner for ThinkOrSwim
# Finds stocks where Hull MA just shifted bullish
def HMA = HullMovingAvg(close, 20);
def bullishShift = HMA > HMA[1] and HMA[1] <= HMA[2];
def momentum = HMA > HMA[1];
plot scan = bullishShift and momentum and volume > 1000000;To use this, open the ThinkOrSwim Stock Hacker tab and add a custom filter with this code. Set your universe to "All Stocks" or a specific watchlist. The volume filter ensures you only see liquid names. These scanners update in real-time during market hours.
Adapting This Backtester for Other Stocks
The code works on any ticker. Change the chart symbol from GME to SPY, AAPL, TSLA, or any stock you trade. Each ticker will produce different results because of different volatility profiles and trending characteristics.
High-volatility stocks like GME stress-test the indicator. If the Hull MA produces acceptable results on GME, it will likely perform at least as well on calmer tickers. Conversely, if it fails on GME, that does not mean it fails everywhere. Lower-volatility stocks with cleaner trends may suit the Hull MA better.
You can also adjust the Hull MA length parameter. Shorter lengths (9, 14) react faster and generate more signals. Longer lengths (26, 50) react slower with fewer but potentially higher-quality signals. Run the backtester with different length settings on the same chart to find what works for your timeframe and trading style.
Risk Management Considerations
Any backtester gives you raw signal performance without accounting for position sizing or risk controls. Before trading any strategy live, define your risk parameters.
For a stock like GME that can gap 20% or more overnight, position sizing matters more than entry timing. Consider limiting each trade to a fixed percentage of your account. Use stop-losses based on ATR (Average True Range) to adapt to current volatility conditions.
The Volatility Box calculates statistical price boundaries for stocks and futures. These levels can serve as dynamic stop-loss targets that adapt to realized volatility, rather than using fixed dollar or percentage stops. The Volatility Box for stocks covers 595 tickers including GME.
Next Steps
You now have a working Hull MA backtester that you can apply to any stock in ThinkOrSwim. The process from here is iterative: test different parameters, add filters, analyze the trade log, and refine your approach based on what the data shows.
For more on the TTM Squeeze filter mentioned in this article, see the TTM Squeeze Course. For a library of other indicators you can combine with the Hull MA, browse the full ThinkOrSwim Indicators collection.
Frequently Asked Questions
What is the Hull Moving Average and how is it different from a standard moving average?
The Hull Moving Average uses weighted moving averages and a square root smoothing period to reduce lag compared to the SMA and EMA. Alan Hull introduced it in 2005. In ThinkOrSwim, the Hull MA changes color when its slope shifts direction, which is the signal used in this backtester. The reduced lag means faster signal generation, which can be both an advantage (catching moves earlier) and a disadvantage (more false signals during chop).
How do I set up this backtester in ThinkOrSwim?
Go to Charts > Studies > Strategies tab, click "Create," and paste the ThinkScript code from this article. Name it something like "Hull MA Backtester" and click OK. Apply it to a GME chart (or any stock), then right-click and select "Show Report" to view trade results. You can adjust the Hull MA length and toggle long/short entries using the strategy inputs.
Which timeframe works best for the Hull MA on GameStop?
In our testing, the 15-minute chart produced more precise entries and a better P&L curve compared to the 1-hour chart. The 1-hour timeframe suffered from excessive whipsaws during sideways periods. However, results will vary depending on the date range and market conditions. Run the backtester on multiple timeframes and compare the Strategy Reports to find what works for your trading style.
Can I use this backtester on stocks other than GME?
Yes. Change the chart symbol to any ticker and the backtester runs identically. GME serves as a stress test because of its high volatility. Calmer stocks with cleaner trends may produce different results. Test across several tickers to see where the Hull MA crossover adds value.
How can I reduce false signals from the Hull MA?
Add a filter. The TTM Squeeze is one option: only take Hull MA entries when the squeeze has recently released, which filters out range-bound chop. You can also add a momentum oscillator as an exit signal instead of waiting for the Hull MA to change color again. The filtered backtester code is included in this article so you can compare results directly.
Does the backtester account for slippage and commissions?
No. ThinkOrSwim's built-in strategy backtester executes at the closing price of the signal candle and does not model slippage, spread widening, or commission costs. For a stock like GME where spreads can widen during high-volatility events, real-world performance will differ from backtest results. Treat the numbers as directional guidance and add a buffer for execution costs.
Ready to Trade With an Edge?
Join 40,000+ traders using institutional-grade tools for ThinkOrSwim.
Get the Bundle