The traditional way to treat the RSI is to treat low RSI levels as good buying opportunities while treating high RSI levels as selling opportunities. However, we seek to gain fresh insight into the nature of RSI, with an eye toward discovering possible momentum return, by exploring the RSI using a visual quantitative approach.

#### Exporting And Visualizing The Data

We are interested in the next day returns of the RSI(2) for the E-mini S&P 500 (ES) futures contract. We will be using Tradestation and Excel for this analysis. For computing next day returns, we export the RSI(2) level and the close to close returns. We can export CSV data from Tradestation using the toolbox. However, I often find it convenient to print the data directly to the output window using Easylanguage, and then simply copy and paste it into Excel.

variables: firstBar(1); value1 = Rsi(Close,2)[1]; value2 = Close-Close[1]; if firstBar = 1 then begin print("Date", ",", "RSI 2",",", "Close Close Change"); firstbar = 0; end; print(datetojulian(date), ",", value1,",", value2);

Now with the data properly in Excel, a scatter plot can be generated.

The Y-Axis shows the next day returns for the given RSI value, as represented by the X-axis. We can see that when RSI values are low that the market tends to be more volatile but beyond that it is difficult to read much more from this chart thus I introduce the concept of the cumulative return scatter plot.

A cumulative return scatter plot shows the total return for given RSI ranges. We can generate a cumulative return scatter plot by breaking the RSI down into a series of distinct classes or buckets and performing a rolling sum for those buckets. This can be performed in Excel. But, due to the number of rows, I found it more productive to generate a strategy optimization report and export that into Excel.

//RSI Class Generator inputs: RsiLevel(20); variables: RsiEntryLevel(0); If Rsi(Close,2) >= RsiLevel-20 and Rsi(Close,2) < RsiLevel then buy this bar at close; If marketposition > 0 then sell this bar at close;

Optimizing the RsiLevel from 20 to 100 in steps of 20 will yield the report we need to create the cumulative return scatter plot.

This chart reveals that the ES has primarily been a mean reverting market over a couple days. Momentum or trending returns might only manifest over longer holding period, however. With a slight modification to the previous code, we can test the RSI returns over various holding periods.

inputs: RsiLevel(20), DaysHold(0); variables: RsiEntryLevel(0); If Rsi(Close,2) >= RsiLevel-20 and Rsi(Close,2) < RsiLevel then buy this bar at close; If marketposition > 0 and barssinceentry > dayshold then sell this bar at close;

We optimize both inputs to generate a new strategy report which can be used for visualizing the RSI returns over a range of holding periods. We look at returns from selling the next day up to 5 days out (where days refers to the value for our DaysHold variable– the actual number of days will be 6 or 7 depending on whether you want to count the overnight as the first day). Exporting to Excel, we can generate various heatmap displays.

The first heatmap shows the returns sorted by RSI class and number of days held. The second heatmap is sorted by net profit. The heatmaps reveal that buying weakness, at least as measured by RSI(2), even when holding up to 5 days out tends to be better than buying strength. However, it is also clear that some profits are being generated from modestly to moderately overbought conditions.

For maximal clarity, we can create a 3d bubble chart which will allows us to extend our cumulative returns scatter plot concept with the 3rd dimension. The custom 3d bubble chart below provides exceptional clarity into both how various holding periods affect specific RSI classes and how returns from different classes compare to one another on a relative basis. The size and color of the bubbles convey the magnitude of the gain or loss for each class while the X-axis shows the class with the Y-axis represents the holding period.

#### Summary

Our custom 3d bubble chart reveals quite a bit. First, it reveals that RSI levels under 20 are the most optimal. Yet, even when trading the RSI in a mean reversion nature, additional profits may be gained by trading more aggressively. Specifically, it looks like RSI class 40 (values 20-40) shows strong returns when holding for up to 1-5 days out with 2 days appearing to be the optimal. *The additional profits, however, won’t be cumulative because some trades will result in the RSI dipping even lower after entry. *As for momentum returns, we do see that there does appear to be, an albeit weaker, momentum driven return for RSI values from 60 to 80 when holding from 1 to 3 days out. On the other hand, extremely overbought conditions exhibit a strong reversionary nature. The returns from buying such extremely overbought conditions are very negative even when allowing for holding periods of up to 5 days out. *Note all reference to days references the value of the variable, you would add 1 or 2 to get the actual number of days out depending on whether you want to count the overnight as the first day or not. Tradestation counts the entry bar as the first day. Adding code to sell at the open would enable seeing the overnight returns.*

#### Premium Package Offer

We will be offering a premium program for some of our articles. This article will be offered as our first premium program in the near future. The premium program will feature step-by-step video tutorials with detailed narration showing you every single step needed to recreate our work– everything from generating the optimization reports in Tradestation to generating the custom Excel charts will be demonstrated. Additionally, the premium package will offer expanded proprietary analysis that will go deeper then what we cover here. Plus, you get all source code ready to run–including additional strategy code, all the worked Excel workbooks, and the expanded additional proprietary analysis all for a reasonable price. As an added bonus, you will learn several of the tips and tricks I use when working with Tradestation to maximize my productivity. And last but not least, program purchasers receive limited exclusive email support.

If you’d like to be notified when the premium package is available then please let me know by shooting an email to beyondbacktesting@gmail.com or simply click here to contact us using our contact form.

Hi,

This article is a little hard to fathom if you’re new to coding as it assumes the reader understands you’re code/description.

So the buying criteria is, you’re buying on a >= 20% (and in increasing bands of 20) RSI threshold but there’s no explanation of what “close to close returns are?” You can buy at the open and sell at the close or buy at the close and sell at the next days open/close?

“we export the RSI(2) “level”? The RSI “Level” being 20%, 40% etc?

So the values, although not stated, along the x axis of the first graph for each line are, RSI 10%, 20%, 30% etc?

In the second graph why is there a (un-plotted) 120 value in the second graph x axis?

“This chart reveals that the ES has primarily been a mean reverting market over a couple days.” Could you elaborate?

“RsiEntryLevel(0);

If Rsi(Close,2) >= RsiLevel-20 and Rsi(Close,2) < RsiLevel then"

Could you explain this code please and the negative 20?

So, days held = 0, is classified as selling the next day to produce returns?

I wonder what the results of using a superior oscillator like Ehler's Universal Supersmoother Oscillator and optimising the bandedge and thresholds would be?

Thanks a lot,

LikeLike

Thanks for interest. My quick reply:

* Levels are absolute values — not %

* The RSI(2) means the period is 2. That is what is used to calculate the RSI on.

* The RsiLevel-20 allows us to use one variable to establish a bound. So, it would be 0-20,20-40, etc. This is used in conjunction with step-size/steps in the optimizer.

* Yes, I believe next day close. There is also a return for the overnight which would require special case coding for close to open.

* Don’t know: you’d have to test it. But, studies like these aren’t designed for generating optimal results but rather for understanding the underlying characteristics of a given market.

LikeLike

That’s really thniking of the highest order

LikeLike