Back-Testing a Famous Profitable Trading Strategy in Python.
Coding and Back-Testing Larry Connors Strategy on the RSI.
In his brilliant book, Larry Connors described a powerful strategy relying on a 2-period RSI. Unfortunately for me, I thought I was the one who first introduced this short-term RSI when I started publishing last year, but this actually confirms that it is a very good indicator. This article will discuss the strategy in detail and presents a simple back-test to evaluate the performance.
I have just published a new book after the success of my previous one “New Technical Indicators in Python”. It features a more complete description and addition of structured trading strategies with a GitHub page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below Amazon link, or if you prefer to buy the PDF version, you could contact me on LinkedIn.
The Book of Trading Strategies
Amazon.com: The Book of Trading Strategies: 9798532885707: Kaabar, Sofien: Books
Introduction to the Strategy
The strategy was originally designed for stocks but it should not stop us from back-testing it on the FX market. We will mainly use two ingredients for entry and one for exit:
- A long (Buy) signal is generated whenever the market is above its 200-period simple moving average while the 2-period RSI closes below 5. The long (Buy) position is exited whenever the market surpasses its 5-period moving average.
- A short (Sell) signal is generated whenever the market is below its 200-period simple moving average while the 2-period RSI closes above 95. The short (Sell) position is exited whenever the market breaks its 5-period moving average.
Before we start back-testing the strategy, let us create the RSI and moving averages in Python to set the framework.
# The function to add a number of columns inside an array
def adder(Data, times):
for i in range(1, times + 1):
new_col = np.zeros((len(Data), 1), dtype = float)
Data = np.append(Data…