# SPY Meltdown Backtester: What Happens After a Big Sell-Off (Free Download)

Backtester Free Beginner 8 min video 12 lines of code Aug 28, 2022 Updated Oct 21, 2026

A free SPY meltdown backtester for ThinkOrSwim. It buys the open the day after SPY drops more than 3% from open to close, then sells at that day's close.

## Overview

In this tutorial I build a SPY meltdown backtester for ThinkOrSwim to answer one question: after the S&P 500 has a big sell-off day, does the selling continue the next day, or do buyers step in? The strategy buys at the open on the day after SPY closes more than 3% below its open, and sells at the close of that same day.

The whole backtester is 4 lines of thinkScript, so it makes a good first strategy if you have never written one. I recorded it on a Sunday, two days after a Friday meltdown, most likely in late August 2022, to see what the next session has looked like after past drops like it. It's for traders who want to test a market event themselves before they act on it.

## Key Takeaways

- The SPY meltdown backtester is a free ThinkOrSwim strategy that buys at the open the day after SPY closes more than 3% below its own open, and sells at the close of that same day.

- The size of the meltdown is the threshold input, -0.03 in the download. The drop is measured from the day's open to its close, as (close - open) / open.

- In the video, on 5 years of daily SPY bars, the Floating P/L was green, and the report showed 3 trades making up the bulk of it. The video doesn't give a trade count or a total for that run.

- On SPY's maximum available daily history, which reaches back past 1997, the backtester found 48 meltdown days. The P/L graph was still green for the most part, and the trades at the low end included a loss of about $7 on 1 share. No total is read out.

- My first version of the code bought at the meltdown day's own open. Checking the previous bar's move with move[1] fixed it.

## What the SPY Meltdown Backtester Tests

The SPY meltdown backtester tests what the S&P 500 has done on the day after a sharp sell-off. There are two possible answers. Sellers could ride the momentum lower, or buyers could treat the drop as exhaustion and push price higher. Intuition suggests the first, and the backtester checks that against history.

The test covers the very next day only. It doesn't hold for a week or wait for a rebound. That keeps the question narrow and the code short, and it makes the result easy to read: a green P/L graph means buying the next morning has made money over the period on the chart, and a red one means it has lost money.

## The Meltdown Rule

A meltdown day in this backtester is a daily bar where SPY closes more than 3% below its own open. The rule compares the open and the close of the same day, so a day that gaps down 3% and then trades flat from its open doesn't count.

Part of the rule Setting in the download

Event A bar where (close - open) / open is below -0.03, a drop of more than 3% from open to close

Entry Buy to open at the open of the next bar

Exit Sell to close at the close of that same bar

Holding time 1 session

Size 1 share per trade

Direction Long only

Chart used in the video SPY, daily bars, 5 years and then maximum data

Because the entry is the next day's open, the overnight gap after a meltdown is not part of the result. The trade measures how the following session traded from its open to its close.

## How to Build the Backtester in ThinkOrSwim

The SPY meltdown backtester is a ThinkOrSwim strategy, the kind of script that places simulated orders with AddOrder and draws a Floating P/L under the chart. To set it up:

- Click the Studies icon on your chart.

- Switch to the Strategies tab and click Create.

- Give the strategy a name. I called mine TI SPY research, and any name works.

- Delete the starter AddOrder code, paste in the code from the Code tab on this page, then click OK and Apply.

- If no P/L bars appear under the chart, click Global Strategy Settings and turn on the option to display the Floating P/L study with strategies.

- Load SPY on a daily chart and zoom out to see the trades.

You can skip the typing: the download holds the finished strategy as a .ts file, and our guide on [how to import a thinkScript file into ThinkOrSwim](https://tosindicators.com/thinkscript/how-to-import-thinkorswim) walks through adding it.

## How the Code Works

The SPY meltdown backtester code has one input, one calculation and two orders. The snippets below come from the downloaded file.

### Step 1: The Threshold

(This step's code is free with an account.)

The threshold is the move that counts as a meltdown. In the video I describe it as 3%, and the code stores it as a decimal: -0.03 is a 3% drop. Because it's an input, you can change it from the strategy's settings without editing the code.

### Step 2: The Move From Open to Close

(This step's code is free with an account.)

The move takes the close, subtracts the open, and divides by the open, which gives the percentage change for that day as a decimal. A day that opens at $100 and closes at $96 has a move of -0.04. Our tutorial on [tracking percent change from the open](https://tosindicators.com/thinkscript/pct-change-from-open) uses the same idea for a chart label.

### Step 3: The Entry Order

(This step's code is free with an account.)

AddOrder places the simulated trade. This line buys to open when the previous bar's move was below the threshold, at the open of the current bar, for 1 share. The [1] after move is what points it at the previous bar, and the next section shows why it matters.

### Step 4: The Exit Order

(This step's code is free with an account.)

The exit condition is the number 1, which is always true. The strategy sells to close at the close of every bar where it holds a position, so every trade lasts exactly one session: in at the open, out at the close.

## The Bug That Bought the Meltdown Day's Open

The first version of the SPY meltdown backtester checked move < threshold without the [1] . To test it, I right-clicked, chose Show report , and compared the prices with the chart.

The first trade I checked was the meltdown of June 11, 2020. The report showed an entry at $311.46 and an exit at $300.61. But the open on the next day was $308.24. The $311.46 was the open of the meltdown day itself, so the strategy was buying before the drop it was supposed to react to.

A move from open to close is only known at the close, so a rule built on it can't trade that same day's open. Adding [1] makes the strategy look at yesterday's move and buy today's open. After the fix, the report showed the entry at $308.24 and the exit at $304.21, the close of that next day, both matching the chart.

Our guide on [how to fix bugs in thinkScript code](https://tosindicators.com/thinkscript/fix-bugs) covers more checks like this one.

## Results From the Video

The SPY meltdown backtester produced these results on daily SPY charts in the video. They are historical results for 1 share per trade, so each dollar figure is per share. The video shows the P/L graph and a few trades, and it doesn't read out a total P/L or a win rate for any run.

Test in the video Period Meltdown days (trades) What the video shows

First version, no [1] June 11, 2020 1 checked Entry $311.46, the meltdown day's own open. Exit $300.61. Wrong entry bar.

Fixed version The day after June 11, 2020 1 checked Entry $308.24 at the open, exit $304.21 at the close, both matching the chart

Fixed version 5 years of daily bars Not stated Floating P/L green. The report showed 3 trades making up the bulk of the P/L.

Fixed version Maximum data, back past 1997, including the 2000 crash 48 P/L graph still green for the most part. The low end of the report included a loss of about $7. Total not read out.

On the 5-year chart, I walked through the first meltdown in the window. The next day closed green. Two days later came another big bearish day, and the session after that was still a green candle, if only marginally. Further on, a February to March decline had a series of meltdown days. When I opened the report there, 3 trades were making up the bulk of the P/L.

On the maximum data, the P/L graph stayed green for the most part across all 48 meltdowns, so buying the next open and selling the close came out ahead over that history. The report is where to study the individual trades, from the largest dollar gains down to losers like that $7 loss.

## How I Read the Results

The SPY meltdown backtester gave me a read on the next session, which I set beside my existing bias. That bias was bearish. In a video on August 20, I had laid out 4 reasons, mainly that SPY sat near the top of a downtrending channel and had just closed back inside it with an overbought signal. Price then gapped down, tried to hold a shorter-term trend line, and had Friday's meltdown.

After the backtest, I was still looking for more bearish activity, with the midline of the channel as the first target and the lower end of the channel as the main one. The backtest added one thing: I didn't expect a straight free fall, because on the day after past meltdowns, the P/L graph showed a little more buying than selling.

Our tutorial on [drawing price channels in ThinkOrSwim](https://tosindicators.com/thinkscript/price-channels) shows how to plot a channel like that one.

A green P/L graph on 48 past meltdown days describes those days. It's a read on the next session and not an entry signal by itself. If you trade the day after a sell-off, decide where your stop goes first, and size the position so a stop-out costs a small, fixed share of your account.

## Ways to Customize the Test

The SPY meltdown backtester has one input and runs on whatever symbol you load, so most changes take a few seconds.

- Change the size of the meltdown. Set threshold to -0.02 to test drops of more than 2%, or -0.05 for more than 5%. A larger drop finds fewer days.

- Change the history. Compare 5 years with the maximum data, as I did in the video, to see whether a result holds over the longer sample.

- Test another market. Load a different ETF or stock on a daily chart. The strategy recalculates for that symbol.

- Study the report. Right-click and choose Show report to list every trade. In the video I suggest comparing the trades with the largest dollar gains against the losers, like the $7 loss, to look for patterns between them.

For a different kind of entry rule on the same chart, our [moving average crossover backtester](https://tosindicators.com/backtesters/moving-average-crossover) is another beginner-friendly strategy built with AddOrder .

## Common Problems

The SPY meltdown backtester has three common problems, and each has a quick fix.

- No P/L bars under the chart. Turn on the Floating P/L study in Global Strategy Settings.

- The entry price matches the meltdown day's open. The entry line is missing the [1]. It should read move[1] < threshold.

- The strategy trades every day, or never. The threshold has to be a negative decimal. A value of 3 makes every day qualify, because every daily move is below 3. A value of -3 asks for a 300% drop, so no day qualifies.

## Price Events vs. Calendar Events

The SPY meltdown backtester triggers on a price move. Our other free event tools start from the calendar instead, and each one shows a different thinkScript technique:

- The Santa Claus rally backtester finds its bars with getDayOfMonth and getMonth, so 2 lines of code catch every December on the chart.

- The election backtester stores 6 election dates as numbers and holds each trade for a set number of bars, 30 by default.

- The Super Bowl indicator is a study rather than a strategy. It reads yearly candles and labels each year with the Super Bowl winner's conference.

- The Seasonal Analysis indicator shows how often each month has closed higher and its average change.

You'll find the rest of our strategies on the [ThinkOrSwim backtesters page](https://tosindicators.com/backtesters).

## The backtester on real data

Drawn from real daily bars with the code on this page, through Oct 20, 2026. A meltdown day is a daily bar that closes more than 3% below its own open. The backtester buys 1 share at the next day's open and sells at that day's close.

### SPY, Nov 20, 2025

SPY's most recent meltdown day was Nov 20, 2025, -3.03% from open to close. The next day it opened at $655.05 and closed at $659.03.

That trade made +$3.98 a share (+0.61%). SPY had 11 meltdown days from Jan 4, 2016 to Oct 20, 2026, and the day after was green 8 times.

### Four index ETFs since 2016

Fund Meltdown days Next day green Average next day Total, 1 share Any day: green, average

SPY 11 73% +1.73% +$85.02 54%, +0.02%

QQQ 37 57% +0.87% +$102.27 54%, +0.03%

DIA 12 58% +0.99% +$41.59 53%, +0.02%

IWM 33 67% +0.56% +$33.88 50%, -0.01%

Open to close on the day after each meltdown, Jan 4, 2016 to Oct 20, 2026, 1 share, as the code trades. The last column is every day in the same years, open to close.

The full thinkScript code is free with an account: [create one](https://tosindicators.com/register) or [sign in](https://tosindicators.com/login) on this page.

## Download

SPY Meltdown Backtester Download the SPY Meltdown Backtester for ThinkOrSwim. The download is a .zip with one strategy file, TI_MeltdownBacktesterSTRATEGY.ts, the same code as the Code tab on this page. Import it as a strategy, load SPY on a daily chart, and change the threshold input to test a different size of drop. If you haven't imported a file before, here's [how to import into your ThinkOrSwim platform](https://tosindicators.com/thinkscript/how-to-import-thinkorswim).

[Download free](https://tosindicators.com/backtesters/spy-meltdown)

## Video: SPY Meltdown Backtester, built line by line

8 minutes on YouTube.

[Watch on YouTube](https://www.youtube.com/watch?v=4FthAFQmNlk)

## Questions

What is the SPY meltdown backtester?

It's a free ThinkOrSwim strategy that tests what SPY has done on the day after a meltdown. A meltdown is a day that closes more than 3% below its open. The strategy buys at the next day's open and sells at that day's close, so the P/L graph shows whether buyers or sellers have controlled the next session.

What counts as a meltdown day in the backtester?

A daily bar where the close is more than 3% below the open. The code calculates the move as close minus open, divided by open, and compares it to the threshold input of -0.03. The drop from the previous close and the overnight gap are not part of the rule.

What happened the day after SPY meltdowns in the video?

Buying the next day's open came out ahead in both tests. On 5 years of daily SPY bars the Floating P/L was green. On the maximum data, back past 1997, the strategy found 48 meltdown days and the P/L graph was still green for the most part. These are historical results for 1 share, and no total is read out.

How do I build a meltdown backtester in ThinkOrSwim?

Click the Studies icon, switch to the Strategies tab and click Create. Name the strategy, delete the starter code, and paste in the 4 lines from the Code tab: the threshold input, the move calculation, a buy to open order and a sell to close order. Click OK and Apply, then turn on the Floating P/L study in Global Strategy Settings.

Why does the code use move[1] instead of move?

The [1] makes the strategy check the previous bar. Without it, the strategy bought at the open of the meltdown day itself, $311.46 on June 11, 2020, before the drop it was reacting to. With it, the strategy buys the next day's open, $308.24 in that example, which matched the chart.

How do I change the meltdown threshold?

Double-click the strategy to open its settings and change the threshold input. It's a decimal: -0.02 tests drops of more than 2%, -0.03 is the default 3%, and -0.05 tests more than 5%. A larger drop finds fewer days, so the sample gets smaller as the threshold grows.

Why don't I see a P/L graph under my chart?

The Floating P/L study is turned off. Open the Studies menu, click Global Strategy Settings, and turn on the option to display the Floating P/L study with strategies. The histogram then shows the running profit and loss of the meltdown trades and updates each time you change the threshold or the symbol.

Can I run the meltdown backtester on other symbols?

Yes. The strategy runs on whatever symbol is on the chart and recalculates the trades for it. In the video I test SPY on daily bars over 5 years and over the maximum data. Load another ETF or stock on a daily chart to see how its next session has behaved after a drop of more than 3%.

## Related tools

[Santa Claus Rally Backtester: Backtester · Free](https://tosindicators.com/backtesters/santa-claus-rally)[Super Bowl Indicator: Indicator · Free](https://tosindicators.com/indicators/superbowl)[Post-Election Backtester: Backtester · Free](https://tosindicators.com/backtesters/election)[Seasonal Analysis: Indicator · Free](https://tosindicators.com/indicators/seasonal-analysis)[TTM Squeeze Histogram Backtester: Backtester · Free](https://tosindicators.com/backtesters/ttm-squeeze-histogram)[Moving Average Pullback Backtester: Backtester · Free](https://tosindicators.com/backtesters/moving-average-pullback)

## Get each new indicator by email

One email on Sundays with the week's new tool and its code. A free account also unlocks every .txt download.

No credit card. Unsubscribe anytime.
