The stochastic indicator was tested and optimized against two entry/exit criteria over 12 years and in 4 markets, resulting in over 1,729 tests. After reviewing the results, one method clearly outperformed the other and had much more predicable behavior. In general the stochastic indicator appeared able to provide profitable outcomes even with fairly low strike rates. Additionally, the default settings ended in profitable outcomes (if only barely) in all but one market when tested over the two strategies. Interestingly, the overall performance and volatility of the results varied greatly when only small changes are made to either the parameters or the entry / exit criteria used.
Read on for the full stochastic review and statistics.
Introduction
The stochastic oscillator has been around for decades (since the 1950’s) and still remains a popular indicator in use today. It compares the closing price of an instrument to the instruments historical prices over a set period of time. As with most oscillators, it attempts to predict price turning points, effectively trying to call the highs and the lows of a price movement.
This Stochastic review post forms part of my series to test and compare Backtrader’s library of built-in indicators. For the series introduction, some notes on the test methodology and results summary table see here: https://backtest-rookies.com/2017/07/31/backtraders-best-forex-indicators/
Note: Results below do not reflect real world performance. As mentioned in the introduction and overview post (linked above), no commissions, leverage or margin are used during testing. The purpose of these tests are to compare the indicators to one and another where all other factors are equal. For more information on how all indicator reviews will be performed, please click on the link above.
Understanding the Stochastic Ocillator
The stochastic oscillator is measured with two lines. These lines are called %K and %D and they are calculated as follows.
%K = (Current Close – Lowest Low)/(Highest High – Lowest Low) * 100
%D = 3-day SMA of %K
You don’t have to fully understand the equation to use the indicator but it does help to have a basic idea of what it is showing you.
You may notice the %D line is actually a moving average of the %K line. That means the %D line will move slower than the %K line and as such, it gives us an opportunity for generating crossover signals for entries and exits.
To learn more about Stochastic oscillators take a look at:
- https://en.wikipedia.org/wiki/Stochastic_oscillator
- https://www.oanda.com/forex-trading/learn/technical-analysis-for-traders/stochastic/basics
Test Strategy
The stochastic indicator was tested using two slightly different methods. Both methods had the same entry criteria but different exit criteria. The first method follows the mantra that “the exit should be based on the same criteria that caused you to enter the trade.”. In other words, the exit is simply the opposite of the entry criteria. The second method aims to provide an opportunity to reverse the trade direction sooner and oscillate our positions with the indicator.
Entry
- Enter Long:
- When both the %K and %D lines are in the oversold area AND the %K line crosses above the %D line
- Enter Short
- When both the %K and %D lines are in the overbought area AND the %K line crosses below the %D line
Exit Method 1
- Exit Long:
- When both %K and %D reach the overbought area and AND the %K line crosses below the %D line
- Exit Short:
- When both the %K and %D lines are in the oversold area AND the %K line crosses above the %D line
Exit Method 2
- Exit Long:
- When both %K and %D reach the overbought area ONLY
- Enter short if the %K line crosses below the %D line whilst still in the overbought area
- Exit Short:
- When both the %K and %D lines are in the oversold area ONLY
- Enter Long if the %K line crosses above the %D line whilst still in the oversold area.
Stochastic Review – Results
Overall 1729 tests were performed across all four markets and parameter settings. Optimization was performed on each strategy for the following parameter ranges:
- Period: 4 to 30
- d_fast: 2 to 5
- d_slow: 2 to 5
A summary, gallery of charts and series of statistic tables for each test method are below. The tables give an overview of the best parameter settings for each market along with the best / worst settings across all markets.
Each gallery shows 3 different charts:
- The 12 year annual returns of the best and worst performing tests
- The PnL curves for each market when altering the Period parameter. The d_slow and d_fast parameters remain as their defaults.
- The best, worst and average strike rates across all tests.
Method 1
This method of testing proved to be quite wild. As you will see in the PnL curves below, the performance is very choppy in all markets. Only small changes to the period parameter resulted in large swings from profitability to losses.
- The most profitable test came from NZDUSD using 21,4,5 settings and had a strike rate of 46%
- However, the best overall settings based on average PnL across all markets tested is 24, 3 ,3 with an average PnL of $255.
- The default settings were profitable (but not optimal) across all markets.
- A longer period (Above 16) provided the best settings in all markets.
You can download a cope of the test results here: Stochastic Review Method 1 Results
Best settings for each market
Market | period | period_dfast | period_dslow |
---|---|---|---|
AUDUSD | 16 | 3 | 5 |
GBPUSD | 27 | 3 | 4 |
EURUSD | 25 | 3 | 2 |
NZDUSD | 21 | 4 | 5 |
Default Settings Performance (14,3,3)
Market | PnL | Strike Rate |
---|---|---|
AUDUSD | 108.69 | 32.65 |
GBPUSD | 60.43 | 30.21 |
EURUSD | 7.68 | 35.64 |
NZDUSD | 398.91 | 45.78 |
Best/worst settings on average across all markets
PnL | Param 1 | Param 2 | Param 3 | |
---|---|---|---|---|
Best | 255.3575 | 24 | 3 | 3 |
Worst | -263.02 | 20 | 3 | 4 |
Method 2
The second strategy under test contrasted the wild results of method 1. For a start, the PnL curves actually resemble a curve (sort of!) and there seems to be less sensitivity to parameter changes. In addition, the stochastic indicator tested better in certain markets than others rather than being volatile in all markets.
- This strategy is best suited to AUDUSD with consistent profits across most period parameter settings.
- In contrast, NZDUSD appeared to generally perform poorly across the board.
- Interestingly the best settings on average across all markets produce less average profit than method 1.
- The best settings for each market all had a look back period of greater than 13.
A copy of the test results data can downloaded here: Stochastic review method 2 results
Best settings for each market
Market | period | period_dfast | period_dslow |
---|---|---|---|
AUDUSD | 15 | 3 | 3 |
GBPUSD | 30 | 3 | 4 |
EURUSD | 13 | 5 | 4 |
NZDUSD | 16 | 3 | 4 |
Default settings for each market
Market | PnL | Strike Rate |
---|---|---|
AUDUSD | 472.77 | 41.36 |
GBPUSD | 28.12 | 42.65 |
EURUSD | 196.22 | 41.75 |
NZDUSD | -241.54 | 33.48 |
Best/worst settings on average across all markets
PnL | Param 1 | Param 2 | Param 3 | |
---|---|---|---|---|
Best | 212.6975 | 13 | 3 | 4 |
Worst | -154.775 | 25 | 2 | 3 |
Thanks for the excellent info! I wondered if you had done any backtesting with Stoch or other indicators on crypto i.e. BTC or ETH? Regards, Fred.
Hi Fred,
Thanks for the feedback. I have done some quick backtesting but nothing formal. I will bear this in mind when considering future posts!
Thanks again
Could you please provide sample code how to implement it?
Cheers,
Andrew