Back to Community
Long-Term Momentum Strategy Using Smoothed RSI

TRADING RULES
SMA100(RSI20) cross> 50 = sell $IEI + buy $VTI
SMA200(RSI20) cross< 50 = sell $VTI + buy $IEI

This simple momentum algorithm uses a 100-day SMA of the 20-day RSI for $VTI to trigger buy signals and a 200-day SMA of the 20-day RSI to trigger sell signals. When a sell signal is triggered, the algorithm rotates out of $VTI and into $IEI until a new buy signal is generated, at which point it will rotate out of $IEI and back into $VTI. I consider this a semi-passive strategy that combines long-term buy-and-hold with a tactical overlay to potentially avoid major market corrections.

The concept behind this strategy is as follows:

1) Mathematically speaking, an RSI reading above 50 indicates positive trailing momentum and a reading below 50 indicates negative trailing momentum. Most momentum traders like to buy when the RSI is "oversold" at 30 and sell when the RSI is "overbought" at 70. This, however, is inappropriate (and downright dangerous) because it is a mean-reversion trade technique, not a momentum technique. To better apply the RSI for a momentum strategy, it is better to use 50 as the buy/sell trigger.

2) The RSI by itself is too "noisy," meaning it crosses above and below 50 too often, generating many false trade signals in the process. In order to remedy this problem, you can smooth out the RSI using an SMA or EMA. A smoothed RSI is less noisy but it does tend to lag more.

3) Using a faster smoothed RSI to buy can capture positive momentum earlier and using a slower smoothed RSI to sell can avoid under-performance caused by minor corrections.

Here is a 100-year backtest for $INDU using a similar strategy that I created on TradingView: https://www.tradingview.com/chart/KH147vi4/

Clone Algorithm
210
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 57130d86bf91800f858cef6a
There was a runtime error.
10 responses

Good work Kory! I like the notion of a smoothed RSI...will def tinker with this algo!

When I clone and try to test, I get 2 “build errors” …

5 Warning Undefined name 'ta'
5 Error Runtime exception: NameError: name 'ta' is not defined

… and a testing error ..

Error - There was a problem starting your backtest. Please try again.

These codes were made for Quantopian 1. I think you need to update it to run with Quantopian 2 now.

I see.

How would a total beginner start on this? Is there a tutorial perhaps?

Thanks …

Mark see attached to get you started with this algo setup in Quantopian 2

See below for tutorials:
https://www.quantopian.com/tutorials/getting-started

Weird how Quantopian 1 didnt give error for starting algo above back Aug 2002 given that IEI started trading on 2007-01-11 - maybe was just trading VTI which makes sense eyeing the tracking between the performance and index on the original algo between 2002-start2007

Clone Algorithm
17
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 582d1c68a41cf51070eb4a36
There was a runtime error.

Awesome – thank you.

Long only version with less leverage (more realistic) even better in all respects.

Clone Algorithm
56
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 582d5cd9692bfd1081d8f8d7
There was a runtime error.

I modified the algo as follows:
• Rebalance weekly • Leverage = 2 • 90/10 (or 10/90) ratio for stocks / bonds

Feedback would be appreciated, and I have a question:

Under “Transaction Details” why do some weeks show multiple buys / sales of the same symbol just minutes apart, while in other weeks you get one buy or sale per symbol (which is what I'd expect)?

Thanks …

Clone Algorithm
56
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 582e4ff32c068273cb9f40dd
There was a runtime error.

Mark,

The algo I posted above may hypothetically withstand leverage 6 or even more.
But what is the margin in yours real brokerage account if any?
Be realistic.

My broker (and I expect most) would allow leverage = 3, so I believe leverage =2 is quite realistic.