Hello. I recently got into backtesting and have tested a few strategies with mixed results.
I wanted to test a strategy that was already fairly well known, to see if it still holds up. This is the RSI 2 strategy popularised by Larry Connors in the book “Short Term Trading Strategies That Work”. It’s a pretty simple strategy with very few rules.
Indicators:
The strategy uses 3 indicators:
Strategy Steps Are:
Trade Examples:
Example 1:
The price is above the 200 day MA (Yellow line) and the RSI has dipped below 5 (green arrow on bottom section). Buy at the close of the red candle, then hold until the price closes above the 5 day MA (blue line), which happens on the green candle.
Example 2: Same setup as above. The 200 day MA isn’t visible here because price is well above it. Enter at the close of the red candle, exit the next day when price closes above the 5 day MA.
Analysis
To test this out I ran a backtest in python over 34 years of S&P500 data, from 1990 to 2024. The RSI was a pain to code and after many failed attempts and some help from stackoverflow, I eventually got it calculated correctly (I hope).
Also, the strategy requires you to buy on the close, but this doesn’t seem realistic as you need the market to close to confirm the final values of your indicators. So I changed it to buy on the open of the next day.
This is the equity chart for the backtest. Looks good at first glance - pretty steady without too many big peaks and troughs.
Notice that the overall return over such a long time period isn’t particularly high though. (more on this below)
Results
Going by the equity chart, the strategy performs pretty well, here are a few metrics compared to buy and hold:
Variations
I tested a few variations to see how they affect the results.
Variation 1: Adding a stop loss. When the price closes below the 200day MA, exit the trade. This performed poorly and made the strategy worse on pretty much every metric. I believe the reason was that it cut trades early and took a loss before they had a chance to recover, so potentially winning trades became losers because of the stop.
Variation 2: Time based hold period. Rather than waiting for the price to close above 5 day MA, hold for x days. Tested up to 20 day hold periods. Found that the annual return didn’t really change much with the different periods, but all other metrics got worse since there was more exposure and bigger drawdowns with longer holds. The best result was a 0 day hold, meaning buy at the open and exit at the close of the same day. Result was quite similar to RSI2 so I stuck with the existing strategy.
Variation 3: On my previous backtests, a few comments pointed out that a long only strategy will always work in a bull market like S&P500. So I ran a short only test using the same indicators but with reversed rules. The variation comes out with a measly 0.67% annual return and 1.92% time in the market. But the fact that it returns anything in a bull market like the S&P500 shows that the method is fairly robust. Combining the long and short into a single strategy could improve overall results.
Variation 4: I then tested a range of RSI periods between 2 and 20 and entry thresholds between 5 and 40. As RSI period increases, the RSI line doesn’t go up and down as aggressively and so the RSI entry thresholds have to be increased. At lower thresholds there are no trades triggered, which is why there are so many zeros in the heatmap.
See heatmap below with RSI periods along the vertical y axis and the thresholds along the horizontal x axis. The values in the boxes are the annual return divided by time in the market. The higher the number, the better the result.
While there are some combinations that look like they perform well, some of them didn’t generate enough trades for a useful analysis. So their good performance is a result of overfitting to the dataset. But the analysis gives an interesting insight into the different RSI periods and gives a comparison for the RSI 2 strategy.
Conclusion:
The strategy seems to hold up over a long testing period. It has been in the public domain since the book was published in 2010, and yet in my backtest it continues to perform well after that, suggesting that it is a robust method.
The annualised return is poor though. This is a result of the infrequent trades, and means that the strategy isn’t suitable for trading on its own and in only one market as it would easily be beaten by a simple buy and hold.
However, it produces high quality trades, so used in a basket of strategies and traded on a number of different instruments, it could be a powerful component of a trader’s toolkit.
Caveats:
There are some things I didn’t consider with my backtest:
The code for this backtest can be found on my github: https://github.com/russs123/RSI
More info
The post is really long again so for a more detailed explanation I have linked a video below. In that video I explain the setup steps, show a few examples of trades, and explain my code. So if you want to find out more or learn how to tweak the parameters of the system to test other indices and other markets, then take a look at the video here:
Video:
What do you all think about these results? Does anyone have experience trading RSI strategies?
I wanted to test a strategy that was already fairly well known, to see if it still holds up. This is the RSI 2 strategy popularised by Larry Connors in the book “Short Term Trading Strategies That Work”. It’s a pretty simple strategy with very few rules.
Indicators:
The strategy uses 3 indicators:
- 5 day moving average
- 200 day moving average
- 2 period RSI
Strategy Steps Are:
- Price must close above 200 day MA
- RSI must close below 5
- Enter at the close
- Exit when price closes above the 5 day MA
Trade Examples:
Example 1:
The price is above the 200 day MA (Yellow line) and the RSI has dipped below 5 (green arrow on bottom section). Buy at the close of the red candle, then hold until the price closes above the 5 day MA (blue line), which happens on the green candle.
Example 2: Same setup as above. The 200 day MA isn’t visible here because price is well above it. Enter at the close of the red candle, exit the next day when price closes above the 5 day MA.
Analysis
To test this out I ran a backtest in python over 34 years of S&P500 data, from 1990 to 2024. The RSI was a pain to code and after many failed attempts and some help from stackoverflow, I eventually got it calculated correctly (I hope).
Also, the strategy requires you to buy on the close, but this doesn’t seem realistic as you need the market to close to confirm the final values of your indicators. So I changed it to buy on the open of the next day.
This is the equity chart for the backtest. Looks good at first glance - pretty steady without too many big peaks and troughs.
Notice that the overall return over such a long time period isn’t particularly high though. (more on this below)
Results
Going by the equity chart, the strategy performs pretty well, here are a few metrics compared to buy and hold:
- Annual return is very low compared to buy and hold. But this strategy takes very few trades as seen in the time in market.
- When the returns are adjusted by the exposure (Time in the market), the strategy looks much stronger.
- Drawdown is a lot better than buy and hold.
- Combining return, exposure and drawdown into one metric puts the RSI strategy well ahead of buy and hold.
- The winrate is very impressive. Often strategies advertise high winrates simply by setting massive stops and small profits, but the reward to risk ratio here is decent.
Variations
I tested a few variations to see how they affect the results.
Variation 1: Adding a stop loss. When the price closes below the 200day MA, exit the trade. This performed poorly and made the strategy worse on pretty much every metric. I believe the reason was that it cut trades early and took a loss before they had a chance to recover, so potentially winning trades became losers because of the stop.
Variation 2: Time based hold period. Rather than waiting for the price to close above 5 day MA, hold for x days. Tested up to 20 day hold periods. Found that the annual return didn’t really change much with the different periods, but all other metrics got worse since there was more exposure and bigger drawdowns with longer holds. The best result was a 0 day hold, meaning buy at the open and exit at the close of the same day. Result was quite similar to RSI2 so I stuck with the existing strategy.
Variation 3: On my previous backtests, a few comments pointed out that a long only strategy will always work in a bull market like S&P500. So I ran a short only test using the same indicators but with reversed rules. The variation comes out with a measly 0.67% annual return and 1.92% time in the market. But the fact that it returns anything in a bull market like the S&P500 shows that the method is fairly robust. Combining the long and short into a single strategy could improve overall results.
Variation 4: I then tested a range of RSI periods between 2 and 20 and entry thresholds between 5 and 40. As RSI period increases, the RSI line doesn’t go up and down as aggressively and so the RSI entry thresholds have to be increased. At lower thresholds there are no trades triggered, which is why there are so many zeros in the heatmap.
See heatmap below with RSI periods along the vertical y axis and the thresholds along the horizontal x axis. The values in the boxes are the annual return divided by time in the market. The higher the number, the better the result.
While there are some combinations that look like they perform well, some of them didn’t generate enough trades for a useful analysis. So their good performance is a result of overfitting to the dataset. But the analysis gives an interesting insight into the different RSI periods and gives a comparison for the RSI 2 strategy.
Conclusion:
The strategy seems to hold up over a long testing period. It has been in the public domain since the book was published in 2010, and yet in my backtest it continues to perform well after that, suggesting that it is a robust method.
The annualised return is poor though. This is a result of the infrequent trades, and means that the strategy isn’t suitable for trading on its own and in only one market as it would easily be beaten by a simple buy and hold.
However, it produces high quality trades, so used in a basket of strategies and traded on a number of different instruments, it could be a powerful component of a trader’s toolkit.
Caveats:
There are some things I didn’t consider with my backtest:
- The test was done on the S&P 500 index, which can’t be traded directly. There are many ways to trade it (ETF, Futures, CFD, etc.) each with their own pros/cons, therefore I did the test on the underlying index.
- Trading fees - these will vary depending on how the trader chooses to trade the S&P500 index (as mentioned in point 1). So i didn’t model these and it’s up to each trader to account for their own expected fees.
- Tax implications - These vary from country to country. Not considered in the backtest.
- Dividend payments from S&P500. Not considered in the backtest. I’m not really sure how to do this from the yahoo finance data, but if someone knows, then I’d be happy to include it in future backtests.
- And of course - historic results don’t guarantee future returns
The code for this backtest can be found on my github: https://github.com/russs123/RSI
More info
The post is really long again so for a more detailed explanation I have linked a video below. In that video I explain the setup steps, show a few examples of trades, and explain my code. So if you want to find out more or learn how to tweak the parameters of the system to test other indices and other markets, then take a look at the video here:
Video:
What do you all think about these results? Does anyone have experience trading RSI strategies?