In this article we will be backtesting some well-known candlestick patterns on the S&P 500 ETF (SPY). Which patterns are profitable and how significant are the results when compared with the overall market performance? Also, a simple code will show you how to create a candlestick pattern the world hasn`t seen yet 😉
Simple Example: Hammer and Bullish Engulfing Pattern
Candlestick patterns were developed in the 18th century in Japan and were introduced to the West by Steve Nison. The majority of technical analysts around the world rely on the Japanese charting technique and use candlestick patterns as a part of their market studies. For this article we picked some of the most widely used patterns such as Hammer, Morning Star, Engulfing or Piercing Line. If you want to learn more patterns, please check out this overview at ThePatternSite.com. As an example, figure 1 shows two famous candlestick patterns marked in yellow: On the left chart you can see a Hammer pattern, on the right there is a Bullish Engulfing. Both patterns have triggered a long entry signal the next day.
Can we exploit Candlestick Patterns systematically?
Instead of relying on old books and gut feelings our goal is to verify the effectiveness of these patterns. Only a precise back test can give us the answers to this, so let`s jump into the test procedure. For our backtest we use daily bars from March 1993 to June 2018. The simulation is processed for each pattern independently: If one of our patterns is found, the entry is executed on the next day`s open price. Each signal is traded with 100.000 USD. Because candlestick patterns are a short-term timing instrument, we decide to backtest all patterns with a holding time from 1 to 10 days. All results are displayed in percentage terms, trading costs are not included.
Backtest Results for S&P 500 ETF
Let us take a look at the back test results now. In the first run, no trend filter is applied. Any existing pattern is traded whether the market is in an uptrend or down trend. In order to compare the performance with the market itself, we calculated the average daily return during the back test time period. It is around +0.03% per day. Consequently, the performance of a candlestick pattern should be significantly higher than the benchmark performance. The figure below shows the percentage results for each pattern:
- The simple Big Black Candle pattern delivers profitable results across all holding periods when traded long; with more than 600 trades, this pattern occurred very often
- The Bullish Harami long pattern generates significant profits too; with nearly 200 trades it also occurred frequently
- The Inverted Hammer has the highest average performance of all patterns tested, but it only had 54 trades during the back test period
- The Piercing Line patterns delivers profitable results when the position is held between 3 and 7 days, but the sample size was very small (just 19 trades)
- The Morning Star long pattern was not profitable
Long patterns (except Morning Star) delivered positive results, especially when held for multiple days. Due to the existing upward drift in the equity markets, short patterns should have had a hard time to generate profits in the short-term perspective. But what does the backtest say? Indeed, all tested short patterns generated negative results
How about a Trend Filter – does it help?
Let us apply a 20-day-EMA to the back test and compare again. For example, a Hammer pattern would only be traded if it occurs below the 20-day-EMA. As you can see on the chart below, the amount of trades has decreased and the profitability of all long patterns has been improved.
Without the trend filter, only the Inverted Hammer pattern scratched the 1-percent-mark. Now, after implementing a simple trend filter, nearly four patterns generate profits near the 1-percent-mark, when held for multiple days. As expected, this improvement was achieved by a reduction in the number of unprofitable trades.
How to code your own Candlestick Pattern
Do you want to create your own candlestick pattern and backtest it on several stocks or futures? Using Equilla, this is a manageable task, even for non-programmers. The following figure shows a function at the top which defines all rules for our pattern. I call it “flexible hammer”. This function it used within my trading strategy code below, so it can be kept short and simple. For the exit, I am using a time based rule, so I am able to run statistical tests to find out how many bars the pattern delivers some edge.
And here`s an example of the flexible hammer pattern with the parameter settings you can see in the top left corner of the chart. The marked candle fulfills all rules from above, so a long entry is generated at the next market open:
- the open does not equal the close price
- the lower shadow is at least 2 times larger than the body of the candle
- the upper shadow is smaller than 0.4 times the body of the candle
- the close price is below the 20-day-EMA
Test before you trade!
As shown by the backtest, some candlestick patterns deliver excess returns and can be an entry trigger. Of course, candlestick patterns alone are no free lunch: Trading costs are the enemy of return – they simply eat up a big part of potential profits. So, before you decide trading candlestick patterns, you should validate their profitability and robustness in detail. Using a professional software and high-quality data allows you to do this across different time frames, instruments including several stop and target logics.
Tradesignal® is a registered trademark of Tradesignal GmbH. Unauthorized use or misuse is strictly prohibited. Data by Refinitiv Eikon.