Stochastic Trading Strategies – (Backtest, Indicator, Settings, Rules, and example)
The stochastic indicator is a standard indicator in any trading platform, but we rarely see it published or used in any Stochastic trading strategies. Compared to the RSI, stochastics seems much less popular. Is that because it’s less useful, or is this a hidden gem?
The stochastic indicator does work in a stochastic trading strategy. It performs quite well as a mean-reversion tool for stock indices.

In this article, we explain what the stochastic indicator is, how it performs, show some stochastic trading strategies, and how stochastic compares to the more famous Relative Strength Indicator. We make a trading strategy based on the stochastic indicator.
What type of indicator is stochastics?
Stochastics is an indicator and oscillator, presumably invented by George Lane as early as the 1950s. The indicator tracks the relationship of the closing prices in relation to the highs 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 measure. Stochastics is a bit similar to the previous indicator we wrote about, the Williams %R:
The Williams %R is a pretty easy indicator to 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 mainly 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 what the stochastic indicator looks like:
The light orange line is a 5-day %K with a 3-day smoothing, while the blue line is the 5-day %D. The indicator pane above shows %D as (5,3,3). The reason why is the default settings in Amibroker:
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 particular style or strategy to work on various instruments. As you’ll experience, stochastics don’t work well on commodities, for example, while it works well in the stock market.
Stochastic trading strategies:
In this section, we tested stochastics using two trading styles: short-term mean reversion (overbought/oversold) and %K and %D crossovers. We tried only the S&P 500, and we used the ETF with the ticker code SPY as a proxy.
Short-term oversold and overbought stochastic trading strategy
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 were even close to the result of the oversold and overbought result.
What is the difference between the RSI and the stochastic indicator?
The relative strength indicator (RSI) is probably the most known and used technical indicator, and just as stochastic, the RSI oscillates between zero and 100.
The difference mainly boils down to RSI measuring the velocity of the movements, while stochastics measure 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 differ.
Is the RSI a better indicator than stochastic? We test two trading strategies
Let’s test two straightforward 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;
stochastic=MA(stochastic1,3);
Plot(stochastic,”stochastic”,colorRed,styleLine);
If we insert the indicator into the chart, it looks 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.
Conclusion: Does the stochastic indicator work?
Yes, the stochastic indicator does work, especially on short-term movements in the stock market. The stochastic trading strategies in this article show that the stochastic indicator works well. We know from previous articles that the IBS indicator 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.
FAQ stochastic trading indicator
We end the article with a few frequently asked questions:
What is a Stochastic Trading Indicator?
A stochastic trading indicator is a technical analysis tool used to identify overbought and oversold conditions in the market. It compares a security’s closing price to its price range over a certain period of time and is typically expressed as a number between 0 and 100.
It’s one of the most popular indicators, and it’s also quite useful. For a comparison, please see our ranking of the best oscillating trading indicators.
How Does a Stochastic Trading Indicator Work?
A stochastic trading indicator works by calculating the security’s closing price relative to its trading range over a certain period of time.
This calculation is expressed as a number between 0 and 100. When the indicator is above 80, the security is considered overbought and when the indicator is below 20, the security is considered oversold.
What Are the Benefits of Using a Stochastic Trading Indicator?
The main benefit of using a stochastic trading indicator is that it can help identify potential buying and selling opportunities. By providing an indication of when a security is overbought or oversold, traders can make more informed trading decisions.
However, we recommend backtesting your trading ideas unless you want to trade blind. The past is normally a good indication as long as you avoid curve fitting.
What Are the Drawbacks of Using a Stochastic Trading Indicator?
The main drawback of using a stochastic trading indicator is that it can produce false signals. The indicator is also lagging, meaning that it will only provide signals after the market has already moved.
However, false signals are part of trading. Even though the stochastic indicator produces false signals, it has proven to be pretty good at pointing out reversals in the stock market.
How Can I Use a Stochastic Trading Indicator?
The most common way to use a stochastic trading indicator is to buy when the indicator is below 20 and sell when it is above 80. Additionally, traders can look for divergences between the indicator and the price of the security to identify potential reversals. Our research indicates that divergencies are not as useful as reversals. There are too many false signals when you use the stochastic indicator as a divergence indicator.