Buy the dip with an RSI algorithm.

In some cases, the components of a concept of a strategy read aloud and then combined, create a good place to build a workable strategy which can then be optimized. For example what if we wanted an RSI Algorithm with a SMA Algorithm in combination.  In the next two articles we will explore the RSI and the SMA and how a few steps can create such a strategy.

The RSI Algorithm breakdown

Let us break down some components for a long entry using a certain number of days (N) before we generate the signal:

//Long Entry
//1) Any security Say SPY the Close > 200 Day SMA
//2) Today’s close is less than previous close for N-1, for N Past days where N = 4,5,6,7 or 8 .
//This Means that there is a lower close on at least 3 days of last 4 days or 4 days of last 5 days etc.
//3) Submit X% limit buy order for next day. X can be either .99, 2 , 3 or 4%
//4) RSI(2) < 50
//This means the RSI of 2 days ago is below 50

 

We can add to this a simple exit strategy, something along the lines of, if the RSI 2 days ago is larger than 50, exit the trade.
//Long Exit :
//1) RSI(2) > 50 (Variable 50,60,70)

 

So below in our inputs we set out the initial:

Period for the SMA, – Set to 200 in the period in the inputs, as per our first entry idea.
The price – Set to the closing price
The Lot size -Set 100.
The X% percentage limit,- Set as a variable limitPercent in the inputs.
The RSI variable – Set at 50 in the inputs.
N – The number of days, set as 4 in the inputs.

Putting thoughts into code

We then using Equilla, we go through the steps initially set out. If today’s close is lower than yesterdays we start the counter (Y), we then check that Price is above the Average (AVG) and the RSI of 2 days ago is below 50.

We then check the counter has reached the number we chose for N (in this case 4) and then buy the specified Lot after the % limit set is added to the price (k).

RSI Algorithm buy the dip

The exit strategy checks if the price is above the average and if the RSI of 2 days ago is is greater than the variable, in this case 50.

Below is the un-optimized performance of this strategy on the Daily SPY chart:

RSI Algorithm shown on the S&P

 

Stay tuned for the second strategy and an optimized version.

 

***

Tradesignal® is a registered trademark of Tradesignal GmbH. Unauthorized use or misuse is strictly prohibited. Data by Thomson Reuters Eikon.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to this Blog