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?
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.
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 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:
- Click the studies icon, switch to the strategies tab, and click create.
- 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!
downloads
Download the SPY Meltdown Backtester for ThinkorSwim.
The download contains a STRATEGY.ts file, which you can directly import into your ThinkOrSwim platform.
Download Backtester
Download the SPY Meltdown Backtester for ThinkorSwim.
The download contains a STRATEGY.ts file, which you can directly import into your ThinkOrSwim platform.