Adding candlesticks to mean reversion setup – Alvarez Quant Trading


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.

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

 

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.

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

 

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.

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.

 

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.

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.

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



Source link

Leave a Comment

Your email address will not be published. Required fields are marked *

//chooxaur.com/4/3962221