Last Updated on March 24, 2021 by Oddmund Groette
The stochastic indicator is a standard indicator in any trading platform, but we rarely see it published in any trading strategies. Compared to the RSI, stochastics seems much less popular. Is that because it’s less useful or is this a hidden gem?
In this article, we explain what the stochastic indicator is, how it performs, and how it compares to the more famous Relative Strength Indicator. The stochastic indicator performs quite well as a mean-reversion tool for stock indices.
What type of indicator is stochastics?
Stochastics is an indicator and oscillator, presumably invented by George Lane as early as in the 1950s. The indicator tracks the relationship of the closing prices in relation to the high and lows over a defined number of days and smooths the result by using an average. George Lane referred to stochastics as a momentum indicator. Further down in the article you find the calculation and Amibroker code which makes it more apparent what stochastics measures. Stochastics is a bit similar to the previous indicator we wrote about, the Williams %R:
The Williams %R is a pretty easy indicator to both calculate and understand, while stochastics is slightly more complex.
As a result of the formula, stochastics fluctuates between 0 to 100. Zero or low readings indicate an oversold condition, while 100 or a high reading means an overbought condition. Because of this, stochastics is mostly used as a mean-reversion tool.
What does the stochastic indicator measure?
Stochastics measure the recent strength of the stock (or whatever you are trading) and how it trades compared to the last x days. It doesn’t measure the velocity of the movement, but how it fares today compared to the lookback period’s high and low readings. If the current price is low compared to the high/low range over the preceding days, the reading is low, and vice versa.
How is the stochastic indicator calculated?
The indicator consists of two lines: a fast line which is called %K and a slow line called %D.
The %K is calculated by using an x-day lookback period. If we use a 5-day lookback period it reads like this: ( close – low(5) ) /( High(5) – low(5) ) * 100. This number is then smoothed by an average of for example 3 days.
The %D is an average of x days of the %K. The code for Amibroker further down perhaps illustrates the formula both better and easier.
The chart below shows how the stochastic indicator looks like:
How does the stochastic indicator work?
Stochastics is mainly used as an oversold or overbought indicator. This works normally well in mean-reverting asset classes like stocks. Further below we provide examples of how you can utilize the indicator.
What is the best setting for the stochastic indicator?
There are no exact settings that work all the time. What works in stocks, might not work in commodities like, for example, oil or natural gas. Different settings in different instruments don’t indicate curve fitting. You can’t expect a certain style or strategy to work on a wide range of instruments. As you’ll experience, stochastics don’t work well on commodities, for example, while it works well in the stock market.
How to use the stochastic indicator:
In this section, we tested stochastics using two trading styles: short-term mean reversion (overbought/oversold) and %K and %D crossovers. We tested only the S&P 500 and we used the ETF with the ticker code SPY as a proxy.
Short-term oversold and overbought
A short-term lookback period of two to five days works best as long as the threshold is pretty low, like for example 25. Likewise, the smoothing period must be equally low.
We tested by using %K (2,2) with an exit when today’s close is higher than yesterday’s high. Using these criteria we got this equity curve:
It’s 497 trades from 1993 until March 2021, an average of 0.58% per trade, a profit factor of 2.33, and a maximum drawdown of 19.8%. Not bad. With short lookback periods, it works well.
%K and %D crossover
We tested many types of crossovers, even with optimization, but none managed to be even close to the result of the oversold and overbought result.
What is the difference between the RSI and stochastic?
The relative strength indicator (RSI) is probably the most known and used technical indicator, and just as stochastics the RSI oscillates between zero and 100. The difference mainly boils down to RSI measuring the velocity of the movements, while stochastics measures where the stock is in relation to the low and high over the lookback period. In practice, both indicators are pretty similar. The differences between most oscillating indicators are small. Below is a 5-day stochastics %K and RSI:
As you can see, the visual differences are small. However, despite the visual similarities, the quantified results can be very different.
Is the RSI a better indicator than stochastic?
Let’s test two very simple strategies: we buy the S&P 500 when the 5-day stochastic (%K) and RSI are less than 20, and sell when it reaches 50.
Stochastics yields a CAGR of 7.37% and a profit factor of 2.09 over 251 trades. The RSI returns a CAGR of 3.63% and a profit factor of 2.02 over 106 trades (from 1993 until March 2021).
However, it’s hard to conclude anything. As always, you need to investigate the indicators yourself to make a valid comparison.
The Amibroker code for stochastic
Both the %K and the %D is included in the Amibroker platform. However, if you still want to calculate %K yourself, the code would be like this:
stochastic1=( close – llv(l,5) ) / ( hhv(h,5) – llv(l,5) ) * 100;
If we insert the indicator into the chart it looks exactly the same as the one included in Amibroker:
How to use the stochastic oscillator
In trading, you get rewarded by thinking outside the box. Obviously, there are many ways to use an indicator. You can use stochastic together with moving averages (long-term and short-term definitions of the same indicator), and support and resistance levels. The latter is a bit more complex to code, though, and is mostly used discretionary.
Stochastics works well on short-term movements in the stock market, as expected. We know from previous articles that IBS works really well on stocks, and thus it’s no surprise to see stochastic performing well. However, just like the RSI, the results can be improved by including one or more filters.
The good thing about writing articles such as these is that it forces you to do some testing. While writing this article we did some further research and by “accident” found some really promising ideas that might later turn into a Trading Edge.
Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinion – they are not suggestions to buy or sell any securities.