Skip to main content SPY Meltdown Backtester For ThinkOrSwim - Free Backtester Skip to main content Skip to content
Master the TTM Squeeze with our comprehensive 19-module course Start Learning →
TOS Indicators
  • Tools

    Categories

    • Indicators
    • Backtesters
    • Scans
    • Dashboards
    • thinkScript
    • Member Resources
    Browse Full Library

    Featured Tutorials

    Heiken Ashi Trend Indicator
    Heiken Ashi Trend Indicator
    Indicators

    Download our Custom Heiken Ashi indicator for ThinkOrSwim. Full ThinkScript code, formula...

    Learn more →
    Commodities Tracker
    Commodities Tracker
    Indicators

    For acceleration signals: trend-following strategies and buying pullbacks. For deceleration signals: short...

    Learn more →
    Build an Election Backtester in 10 Minutes
    Build an Election Backtester in 10 Minutes
    Backtesters

    Learn how to create a Post-Election Backtester in ThinkOrSwim to analyze market...

    Learn more →

    Popular Posts

    Unusual Volume
    Unusual Volume
    Scans

    Build 4 scans to easily find stocks with greater than...

    Learn more →
    Upcoming Earnings with High Short Interest
    Upcoming Earnings with High Short Interest
    Scans

    Build a scan to find stocks that are likely to...

    Learn more →
    Unusual Volume Pro Scans
    Unusual Volume Pro Scans
    Scans

    4 additional scans to find unusual volume overlapping with key...

    Learn more →
  • Courses
    Squeeze Course
    Squeeze Course
    19 Modules

    Scan, backtest, and trade the TTM Squeeze setup with precision.

    Unlock Course →
    Earnings Course
    Earnings Course
    3 Modules

    Master earnings plays with free indicators and proven strategies for ThinkOrSwim.

    Unlock Course →
    V-Shaped Reversals
    V-Shaped Reversals
    7 Modules

    Identify and trade powerful V-shaped reversal patterns with confidence and precision.

    Unlock Course →
    Fibonacci Trading
    Fibonacci Trading
    4 Modules

    Learn to trade Fibonacci retracements and extensions in ThinkOrSwim effectively.

    Unlock Course →
  • Products
    Futures Volatility Box Premium
    Futures Volatility Box

    Volatility models for 10 major futures markets, including micros & SPX.

    Explore Futures VB →
    Stock Volatility Box Premium
    Stock Volatility Box

    Dynamic support & resistance for 595+ stocks/ETFs, with a live scanner.

    Explore Stock VB →
    Opening Range Breakouts Premium
    Opening Range Breakouts

    Powerful live scanner & backtester for ORB strategies on 595+ stocks.

    Explore ORB Setups →
My Account
Back to Tutorials
Beginner-Friendly 8 mins

SPY Meltdown Backtester

Test what happens the day after a meltdown in the S&P 500 - do we see continued selling, or do buyers stage a short term rally?

Download Backtester
How to install in ThinkOrSwim →
Table of Contents
  • Understanding the Bias and Context
  • Defining the thinkScript Code
  • Testing and Adjusting the Code
  • Analyzing the Results
  • Conclusion

Introduction

In this tutorial, we will create a simple SPY Meltdown backtester to analyze the behavior of the S&P 500 following significant sell-off days. Specifically, we aim to determine whether the S&P tends to continue its downward momentum or if it experiences a rebound the next day.

You can use the backtester that we will build to test sell-offs in the S&P 500 as they happen, and gauge the recent term performance. SPY meltdowns are inevitable, and the patterns are proof that history continues to repeat itself.

Understanding the Bias and Context

Our analysis begins with a bearish bias, based on a recent downtrending channel and overbought signals. After a significant sell-off, our goal is to see if the S&P continues to decline or if buyers step in, viewing the move as exhaustive and pushing prices higher.

Defining the thinkScript Code

We will write a few lines of thinkScript code to create our backtester. Follow these steps to get started:

  1. Click the studies icon, switch to the strategies tab, and click create.
  2. Name the script (e.g., “TI SPY Research”) and define the threshold for our analysis.

The threshold represents the percentage move that defines a significant sell-off. For this example, we’ll use a 3% threshold.

input threshold = 3;

Next, we need to calculate the percentage move from the open to the closing price:

def move = (close - open) / open;

Now, we can define the conditions for our backtester:


AddOrder(OrderType.BUY_TO_OPEN, move < threshold, open, 1);
AddOrder(OrderType.SELL_TO_CLOSE, close, close, 1);

This code sets up our buy and sell orders based on the defined threshold.

Testing and Adjusting the Code

To test the code, click OK, apply the strategy, and check if the floating P/L appears on your chart. Ensure “Display Floating P/L Study with Strategies” is turned on in the global strategy settings.

Review the initial trades and validate the calculations. If needed, adjust the code to correct any discrepancies.

For example, if the opening price for a day does not match the expected value, ensure the move calculation considers the previous bar’s data.

After making necessary adjustments, apply the code and validate the updated results.

Analyzing the Results

Zoom out to review the P/L graph. In our case, we observed that buying the next day after a significant sell-off often resulted in a positive P/L. This counter-intuitive result suggests that buyers tend to step in after a major sell-off, pushing prices higher the following day.

Expand the analysis to the maximum available data to understand the long-term trends. Review the P/L report to identify patterns and commonalities in the data.

Conclusion

Through this tutorial, we demonstrated how to write simple thinkScript code to create a backtester for analyzing SPY meltdown days. Our findings indicate that buying the next day after a significant sell-off can often be profitable.

We hope you found this tutorial helpful. Good luck with your trading, and stay tuned for our next update!

Featured Tools:
Stock Volatility Box

Stock Volatility Box

Spot reversal zones across 600 stocks & ETFs.

  • Hourly & daily models
  • Powerful Live Scanner
  • Built for day traders
Futures Volatility Box

Futures Volatility Box

Pinpoint reversal zones in 10 major futures markets.

  • 5 models (incl. Scalper)
  • ThinkOrSwim & TradingView
  • SPX traders
ORB Setups

ORB Setups

Find the best Opening Range Breakout setups.

  • Powerful real-time scanner
  • Instant backtests
  • 2+ years data

Get Free Access

Create a free account for downloads and new tutorial alerts.

Create Free Account

More Tutorials Like This

Moving Average Pullback Backtester

Moving Average Pullback Backtester

Beginner-Friendly • 36 mins
TTM Squeeze Histogram Backtester

TTM Squeeze Histogram Backtester

Beginner-Friendly • 33 mins
Santa Claus Rally Backtester

Santa Claus Rally Backtester

Beginner • 14 minutes

Ready to Trade With an Edge?

Join 40,000+ traders using institutional-grade tools for ThinkOrSwim.

Get the Bundle
TOS Indicators

Premium thinkorswim indicators, scans, and trading tools to help you trade smarter.

ThinkOrSwim Tools

  • Indicators
  • Scans
  • Backtesters
  • Dashboards
  • thinkScript
  • Browse All

Courses

  • Squeeze Course
  • Earnings Course
  • V-Shaped Reversals
  • Fibonacci Trading

Products

  • Futures Volatility Box
  • Stock Volatility Box
  • ORB Setups
  • Shop All

Guides

  • TTM Squeeze
  • Automated Trading
  • Volatility Trading
  • Opening Range Breakouts
  • Trade Reports
  • Contact Us

© 2026 TOS Indicators. All rights reserved.

Privacy Policy Terms of Service Disclaimer

The information contained on this website is solely for educational purposes, and does not constitute investment advice. The risk of trading in securities markets can be substantial. You must review and agree to our Terms of Service prior to using this site.

U.S. Government Required Disclaimer - Commodity Futures Trading Commission. Futures and options trading has large potential rewards, but also large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. Don't trade with money you can't afford to lose. This website is neither a solicitation nor an offer to Buy/Sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this website. The past performance of any trading system or methodology is not necessarily indicative of future results.

Individual results may vary, and testimonials are not claimed to represent typical results. All testimonials are by real people, and may not reflect the typical purchaser's experience, and are not intended to represent or guarantee that anyone will achieve the same or similar results.

TOS Indicator's Traders and employees will NEVER manage or offer to manage a customer or individual's options, stocks, currencies, futures, or any financial markets or securities account. If someone claiming to represent or be associated with TOS Indicator solicits you for money or offers to manage your trading account, do not provide any personal information and contact us immediately.

CFTC RULE 4.41 - HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY, SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.