Adding candlesticks to mean reversion setup

My preferred chart style is a candlestick chart but I have never investigated candlestick formations to see if they can help provide an edge in my trading. I recently ran into this blog post, Do Candlesticks Work? A Quantitative Test Of 23 Candlestick Formations, where he did his own investigation. Even better he shared the code for the formations in AmiBroker which would make it a lot easier. You can get my version of the code below.

Using the mean reversion strategy from my previous post, I wanted to know if any of the candlestick formations could improve the results.

The Strategy

To start with, I am looking at all trades that trigger. This will not be a portfolio test because this is how the initial research in the article was done. The method of testing all trades is quite common but I rarely do it this way. It is not my preferred way of testing an idea like this which I will cover on why in the next blog post.

Setup Rules

  • Stock is a member or was a member of the Russell 3000
  • The Dollar Volume of the stock is greater than $500,000
  • Close is above $1
  • Close is above the 200-day moving average
  • The 2-period RSI is below 5

Place limit orders 4% below close for the next day. Buy $1000 worth of stock.

Sell Rule

  • The 2-period RSI closes above 70, exit on the next open
  • If in position after 10 trading days, exit on the next open

 

Base Results

With 19,419 trades we have a large universe to test the candle patterns on. I am looking for an improvement on the 1.12% avg p/l per trade.

Candlestick Patterns

I borrowed the code from the blog post. This list includes both bullish and bearish candle setups. I tested both because who knows which patterns will work. The code identifies these 23 patterns:

  • Bullish Engulfing
  • Bearish Engulfing
  • Piercing Line
  • Hammer
  • Hanging Man
  • Inverted Hammer
  • Shooting Star
  • Black Spinning Top
  • White Spinning Top
  • Bearish Abandoned baby
  • Bearish Evening Doji Star
  • Dark Cloud Cover
  • Three Outside Down Pattern
  • Bullish Abandoned Baby
  • Bullish Morning Doji Star
  • Three Outside Up Pattern
  • Bullish Harami
  • Three Inside Up pattern
  • Bearish Harami
  • Three Inside Down Pattern
  • Three White Soldiers
  • Dark Cloud Cover
  • Three Back Crows

 

Change to Strategy

My first test was having the candle pattern occur on the setup bar. An issue with this was that most patterns rarely showed up on the setup bar. I then changed the code that the pattern had to occur in any of the last three bars.

Signal Bar Results

The pattern that triggered the most was “Inverted Hammer” but those reduced the avg. p/l to .95

Only two patterns improved the results significantly, “Black Spinning Top” and “Three Outside Down Pattern” to 1.54 and 1.30 avg % p/l respectively. But the number of trades was dramatically reduced.

 

Avoiding a pattern

Instead of looking for a pattern within three bars of the setup, what if we avoid a pattern? For example, we do not want an “Inverted Hammer” happening in the last three bars of the setup.

Only two patterns, “Inverted Hammer” and “Bearish Engulfing” improve the avg. %p/l by 5% or more which is not very much.

Spreadsheet

Fill in the form below to get the spreadsheet with all the data. Also included is the AmiBroker code for these patterns that you can use in your code. The code is a sample and is not the code used for this post.

Final Thoughts

Looking for confirming candles of “Black Spinning Top” or “Three Outside Down Pattern” improved the results but they did not happen that often. A common thought is why don’t you add a rule that it can be any of the patterns that improved results. The potential problem is you have to be careful of crossing the over-fitting line. By already testing 23 patterns, we may have already crossed that line.

While avoiding “Inverted Hammer” or “Bearish Engulfing” gave us lots of trades but the improvement was small.

What this type of ‘all trades’ test does not tell us is do these patterns help our portfolio results. That is what I care about since that is how I trade. In the next blog post, I will run this analysis again but at the portfolio level. Will this give the same results as seen here? Or something different?

Backtesting platform used: AmiBroker. Data provider: Norgate Data (referral link)

Good quant trading,

Fill in for free spreadsheet:

spreadsheeticon

 
Visited 53 times, 1 visit(s) today

Click Here to Leave a Comment Below

Adrian Reid - March 3, 2021 Reply

Interesting post Cesar, thank you. I have also found little value in most candlestick patterns commonly spoken about. I wonder whether they have more value used within a certain chart’s behavioural context… but I have looked at this several times and also not found anything useful.

In fact in my testing on stocks I have found that many of the commonly used ‘Bullish’ candlestick patterns actually have some bearish predictive value in the short term… and many supposedly ‘Bearish’ candlestick patterns actually have bullish predictive value.

In some markets the best ‘pattern’ I found in my own work was “Three Black Crows”… a fancy name for three down days in a row… this is supposed to be bearish but is in many cases a not terrible long side mean reversion entry.

As always this supports our use of Backtesting to validate market assumptions and briefs and supports the idea that the opposite of what the masses believe is what actually works.

Thanks for an interesting post – well done.

Adrian

    Cesar Alvarez - March 4, 2021 Reply

    This is more first extensive testing of candlesticks I have done. In the past, I have tried a pattern here and there with no success. It should be interesting to see what the portfolio testing looks like in the next blog post.

Kevin Conway - March 4, 2021 Reply

Thank you for the interesting post.
During the first lockdown here, I got bored and started a $100 accumulator using an evening scan (code below)
The general rules were:
Buy one name at EOD, sell the following EOD.
All in the next EOD, etc, etc.

The code below generates a variation of the piercing pattern with an emphasis on the close being near the high of the day. The list would be reasonably small and easy to to through in a few minutes.
I found that the most successful trades were from setups that had had a previous run up, then a very continuous decline over a few days. This was visualised by a rapid, almost straight line decline from RSI(2) > 70 to RSI(2) 1000000] and
[sma (50) > sma (200)] and
[daily close > daily open ] and
[daily close < yesterdays open] and
[daily low < yesterdays low] and
[yesterdays close [daily high – daily open] * .8]

    Cesar Alvarez - March 4, 2021 Reply

    Thanks for sharing this. Interesting strategy.

Leave a Reply: