Finding The Optimal Period

Today’s topic is on finding the optimal periodicity for the RSI indicator and the techniques should apply to other sorts of indicators as well. The good news is that it won’t require any rocket science. John Ehlers has written a lot about this topic, and his articles spurred my interest in it, which frankly I had never considered. I might should note now that I have not reviewed the actual methodology that Ehlers used in any depth but my impression was that the methods were very advanced. However, I realized I could tackle this problem using just basic statistics.

Before we start analyzing specific solutions, I want to take a moment to describe what we are actually attempting to do. The question that we are trying to answer is how do we find the optimal length to use when calculating an indicator. A poor length value may result in the RSI spending too much time in either the overbought or oversold states, or failing to reach the proper levels. Obviously, the optimal lookback will change as market conditions change and therefore our methods should be adaptive and responsive to the market.

The goal is to find a metric to rank how well behaved the RSI is. A well behaved RSI is one that spends about an equal amount of time in overbought and oversold levels. During a trending market, if the RSI gets stuck into overbought conditions then that would be an example of a poorly behaved RSI. The solution thus is simply to measure the amount of time that the RSI spends in overbought and oversold conditions. My original inspiration came from the idea of a histogram. We simply add 1 for every bar that the RSI is above our threshold and subtract 1 for every bar that the RSI is below our threshold. The absolute value of the resulting summation is our error metric, which we seek to minimize.

Key Concept: Sum the amount of time that the RSI spends above 50 and below 50, and take the difference. The absolute value of the difference is our error metric, which we seek to minimize.

Finding The Optimal Period

Next, we will simply compute our error metric for every RSI length in our search space, and select the RSI with the minimum error. In this example, I searched from RSI(2) to RSI(14). There is one more consideration which is determining our lookback. Too short of a lookback will lack statistical relevance while too long of a lookback will defeat the benefits of adaptation. Some manual trial and error were used before I settled on a lookback of 90 days.


We conducted the test using the S&P 500 Emini and have selected the long only RSI(2) with standard 30/70 overbought/sold thresholds as our baseline. The results are below:

RSI(2) Simple vs RSI(2..14) 50/50

RSI(2) Simple vs RSI(2..14) 50/50- Finding The Optimal Period

While the results are not too different, we do see our profit factor and average profit per trade has improved. The net profit is slightly reduced and the drawdown is slightly higher but essentially similar.

Tightening The Threshold

We can get better results by making our threshold more restrictive. Instead of using the median line, we can use the amount of time that our indicator spends in actual overbought and oversold levels. This makes some sense as the overbought/sold conditions are what’s really important. We use the same technique but now we try to balance the amount of time we spend below 30 and above 70. We see significantly better results. The results improve even more when we try to balance the extreme overbought/oversold conditions using 20/80 as our thresholds: notice that we do not change our actual buy/sell conditions.

RSI(2..14) 30/70 vs RSI(2..14) 20/80

Final Analysis & Summary

Both the 30/70 and 20/80 optimization thresholds show significant improvement in the profit per trade over the baseline, fewer trades, and higher profit factor. This suggests that our RSI optimizations are improving trade quality significantly and suggests that our indicators are better synchronized to the more dominant cyclical structure of the market. While the net profits are not quite as strong, the strong increase in average profit per trade is especially appealing.

It appears that we can find significant cyclical structure in the markets using simple statistical techniques. However, we did have to use some trial and error in determining the lookback to calculate our statistics over, and that may be one area for improvement.

–Curtis White from Beyond Back Testing

About the Author Curtis White

Curtis is a market enthusiast and programmer who enjoys predicting markets, developing trading systems, and tape reading. He offers a blog at where he shares his original ideas for developing and enhancing trading systems. He is a creative,synthesis thinker who likes to combine ideas and techniques from a broad palette. One of his core goals is the creation of graybox systems, software, and decision support tools for enhancing the capabilities of high performance discretionary traders.