Japanese candlestick patterns are useful because they allow traders to quickly visualise price action in the market. There are many different patterns and many different opinions on their effectiveness.
In this article we will look at a trading system that attempts to dynamically select the best performing candlestick pattern from the previous six months and trade that pattern for the next month. Amibroker formula will also be provided.
The idea of this trading strategy is to find the most profitable candlestick pattern over a six month period (in-sample) and then trade that pattern for the next month (out-of-sample).
We then step forward a month and repeat the process so that we are always selecting the most profitable candlestick pattern from the prior six month period.
The idea is that we are attempting to stay in sync with the market and only trade the best price action pattern.
For example, let’s say we backtest Apple stock between 1-January 2000 and 1-July 2000 and we find that the best performing candlestick was the hammer.
We will then select the hammer as our buy rule and run the backtest between 1-July 2000 and 1-August 2000 (one month on).
After this is done, we will shift the in-sample one month forward and repeat the process.
So we move the in-sample backtest forward to 1-February 2000 – 1-August 2000. Then we backtest the best performing candlestick from that period on the next out-of-sample segment. Which would be between 1-August 2000 – 1-September 2000.
This process is also known as walk-forward optimisation and it is a good method to counter the problem of curve fitting.
For this test, we will be optimising on four of the most popular candlestick patterns; bullish engulfing, bearish engulfing, piercing line and hammer.
We will use VarGet and the Optimize function in Amibroker to cycle through each of the candlestick patterns during the in-sample. The walk forward function will be used to process the simulation using profit factor as our target.
The formulas for the individual candlestick patterns is taken from Candlestick Analysis For Professional Traders where I analyse the performance of over 25 patterns.
The code we will use for this test is shown next:
Backtest – SPY
In order to test this trading idea we will run a walk forward optimization on SPY between 1/2000 – 1/2017. SPY is a highly liquid ETF that tracks the S&P 500 so is ideal for our analysis.
Entries will be placed on the open following the candlestick pattern and exited on the same day close. Commissions will be set at $0.01 per share and we will use a fully invested starting capital of $100,000.
The following statistics and equity curve show the concatenated results from the walk forward test:
- Net Profit: $18,225.97
- Annual Return: 1.01%
- Maximum Drawdown: -5.43%
- Risk Adjusted Return: 38.25%
- CAR/MDD: 0.19
- Win Rate: 56.14%
- Profit Factor: 1.47
- # Trades: 114
- Exposure: 2.65%
As you can see, the simulation was profitable and risk-adjusted returns were not too bad at 38.25%. However, the total return is not good and most of the strong performance came between 2000-2005.
The next chart shows how the candlestick pattern changed throughout the simulation:
The first few months the best performing pattern was the bearish engulfing pattern. It then changed to bullish engulfing before changing again to the hammer. Piercing line was a not a strong pattern and not used until 2003.
Backtest – E-Mini S&P 500
We will now go through the same process but this time we will test the E-Mini S&P 500 futures contract.
Once again, we will run a walk forward optimisation between 1/2000 – 1/2017 and hold trades for one bar. Commissions will be set at $20 round trip and position size will be one contract. We will also use a fixed stop loss of ATR(1)*3.
The following stats and equity curve show the results of the walk forward this time on the E-Mini S&P 500 future:
- Net Profit: $6925
- Annual Return: 0.40%
- Maximum Drawdown: -9.25%
- Risk Adjusted Return: 196.66%
- CAR/MDD: 0.04
- Win Rate: 53.53%
- Profit Factor: 1.16
- # Trades: 170
- Exposure: 0.21%
As you can see, the simulation was profitable overall and produced a net profit of $6925. Risk adjusted returns were OK and exposure was very low.
Everything else was mediocre and you wouldn’t want to trade this without significant improvements.
Thoughts & Observations
In this article we created a trading strategy that dynamically selects the best candlestick pattern from the previous six months and trades it the following month.
We saw that when applied to the SPY ETF and E-Mini S&P 500 future, the results were profitable but not desirable.
I must tell you that I spent a fair amount of time on this. I tested quite a few ideas and different markets without much success and I got the feeling I was wasting my time.
A big problem here is getting a large enough sample size to make the results reliable. Some candlestick patterns are quite rare on daily charts and this is why we only used the four most common patterns.
It might be better to apply this strategy to intraday data instead. With intraday data we will be able to gather a lot more signals and increase the sample size.
Overall, the results were not very good but the idea (dynamic selection) could still be very useful.
Instead of optimising candlestick patterns, we could cycle through different trade setups, different indicators, correlation values etc.
There are numerous possibilities that can be looked at and incorporated using the Amibroker formula shown above. Try it out for yourself!
Thank You For Reading
Joe Marwood is an independent trader and the founder of Decoding Markets. He worked as a professional futures trader and has a passion for investing and building mechanical trading strategies. If you are interested in more quantitative trading strategies, investing ideas and tutorials make sure to check out our program Marwood Research.
This post expresses the opinions of the writer and is for information or entertainment purposes only. It is not a recommendation or personalised investment advice. Joe Marwood is not a registered financial advisor or certified analyst. The reader agrees to assume all risk resulting from the application of any of the information provided. Past performance, historical or simulated results are not a reliable indicator of future returns and may not account for real world settings. Financial trading is full of risk and margin trading can lead to financial losses totalling more than what is in your investment account. We take care to present accurate analysis but mistakes in backtesting and presenting of analysis regularly occur. Please read the Full disclaimer.
Thank you to everyone who takes the time to leave a comment. Your feedback, constructive criticism and identification of mistakes is welcome. In order to concentrate on work I may not have time to respond to all comments.