Do candlestick patterns work on their own? A systematic FX back-test using Python.
Approaching candlesticks in a systematic way.
Throughout the huge field of pattern recognition trading, we find some very popular technical patterns that always come up in every technical analysis class, but do they really work? That is, on their own. Remember that, when we say a bullish candle, we refer to a green-colored (or a white one) one and the same thing goes with bearish candles (red or black body).
INTRODUCTION TO CANDLESTICK PATTERNS
Dark-cloud

This is a bearish pattern formed from two candles. The first candle is a bullish candle while the next one is bearish. Typically, the opening price of the bearish candle is above the closing price of the previous candle and it should close around its body. The greater the penetration of the bearish candle, the greater the probability of a top to occur.
Piercing Pattern

This is the counterpart of the dark-cloud. It is a bullish pattern. We see this pattern in a falling market, the first candle is bearish and the second one has to be bullish. Normally the second (bullish) candle opens lower than the first candle and should close at around half the length of the previous candle. This strikes a resembles with the bullish engulfing pattern, except that, with the latter, the body has to completely cover the previous candle’s body.
The morning star

The morning star is a bullish reversal pattern, thus occurring at the bottom of the market. It is composed of three candlesticks:
- The first candle should have a big body and should be bearish.
- The second candle has a small body that does not touch the first candle’s body.
- The third candle should be bullish and should have a body that is inside the first candle’s body.
The evening star

This is the counterpart of the morning star, and it’s a bearish reversal pattern. Basically, it has the same steps as the morning star:
- The first candle should have a big body and should be bullish.
- The second candle has a small body that does not touch the first candle’s body.
- The third candle should be bearish and should have a body that is inside the first candle’s body.
Sometimes the second candle can be a doji and it is perfectly fine to use it the same way as a morning or evening star. We call this pattern a doji star. When we say the body of the candle should not touch the previous candle’s body, we mean a gap. Gaps are discontinuations in prices that occur due to sudden strengths of movement or a lack of liquidity.
The Harami

The Harami which means pregnant in Japanese is a two-candle pattern. It has a relatively small body which follows a full body candle, that is why it’s called a Harami.
Three black crows and Three white soldiers
The three black crows’ pattern is a pattern composed of three consecutive bearish candles that typically have their openings within the prior session’s body (and not tails). The three white soldiers’ pattern is the counterpart of the three black crows. It is therefore a bullish pattern.


Gaps

Gaps are discontinuations between prices and there is a belief that they have to be filled at some point in time. They are very valuable and have many types. A common gap is the one that occurs in ranging market and typically gets filled. A breakout gap signals a new trend and a runaway gap reinforces that trend.
Tasuki

The Tasuki is pattern formed by two candles that gap higher or lower. The color of the candles does not matter. What we should know is that this is a continuation pattern.
The Tri-Star

A basic and interesting candlestick pattern is the doji. It signals market neutral conditions or confusion. If a market is trending upwards and a doji appears, it could signal a correction or even a reversal. It’s simply when the opening price equals the closing price which results in a ‘+’ candlestick shape. The Tri-Star is probably the rarest pattern of all. It is formed by three consecutive doji lines in a top or bottom. The middle doji has to be the either the highest at a top or the lowest at a bottom.
Tower tops and bottoms


A tower top occurs when there is an uptrend going and we notice the bodies of candles getting smaller and ranging until we see a big bearish candle that might start new trend.
A tower bottom occurs when the there is a downtrend going and we notice the bodies of candles getting smaller and ranging until we see a big bullish candle that might start a new trend.
BACK-TESTING SOME OF THE PATTERNS
The below back-tests are on the GBPUSD pair hourly time frame using a 1 pip transaction cost, and a 7-hour holding period. The dataset is of the OHLC type.
THE DOJI
Main idea: A doji is a sign of indifference and as presented, it is when the open price equals the closing price thus implying the current trend may have come to an end as the other party is regaining control. We will see however the results if we buy or sell when we have a doji pattern.
# Key conditionsfor i in range(len(Data)): if Data[i, 3] == Data[i, 0] and Data[i, 3] < Data[i — trend, 3]: Data[i + 1, 4] = 1for i in range(len(Data)): if Data[i, 3] == Data[i, 0] and Data[i, 3] > Data[i — trend, 3]: Data[i + 1, 5] = -1# Position triggerfor i in range(len(Data)): if Data[i, 4] == 1: Data[i, 6] = 1 if Data[i, 5] == -1: Data[i, 7] = -1
The next graph shows the equity curve from the strategy and the results followed by the signals chart to give us a visual idea on the frequency.



THREE BLACK CROWS & THREE WHITE KNIGHTS
Main idea: This is a three-candle pattern that is characterized by its momentum. The three black crows’ pattern is when we witness three big-bodied bearish candles giving an expectation of a continuation while the three white knights pattern is when we witness three big-bodied bullish candles giving an expectation of a continuation. The way to do this is to initiate the order on the open of the next price bar after the pattern has been locked. The big-bodied characteristic will not be tested in the below code but it is fairly easy to code a condition that requires a minimum body range of the candles to validate the pattern. For example, a minimum of 10 pips successively.
# Key conditions
for i in range(len(Data)): if Data[i, 3] > Data[i, 0] and Data[i — 1, 3] > Data[i — 1, 0] and \ Data[i — 2, 3] > Data[i — 2, 0]: Data[i + 1, 4] = 1for i in range(len(Data)): if Data[i, 3] < Data[i, 0] and Data[i — 1, 3] < Data[i — 1, 0] and \ Data[i — 2, 3] < Data[i — 2, 0]: Data[i + 1, 5] = -1# Position triggerfor i in range(len(Data)): if Data[i, 4] == 1: Data[i, 6] = 1 if Data[i, 5] == -1: Data[i, 7] = -1
The next graph shows the equity curve from the strategy and the results followed by the signals chart to give us a visual idea on the frequency.



DARK CLOUD & PIERCING PATTERN
Main idea: Let’s review its definition from the first section. The dark cloud is a bearish pattern formed from two candles. The first candle is a bullish candle while the next one is bearish. Typically, the opening price of the bearish candle is above the closing price of the previous candle and it should close around its body. The piercing pattern is the inverse of the dark cloud and is a bullish pattern. The first candle is a bearish candle while the next one is bullish. Typically, the opening price of the bullish candle is below the closing price of the previous candle and it should close around its body. Let’s see the results of applying the below code for the two patterns.
# Key conditions
for i in range(len(Data)): if Data[i, 0] < Data[i — 1, 3] and Data[i, 3] > Data[i — 1, 3] and \ Data[i, 3] < Data[i — 1, 0]: Data[i + 1, 4] = 1for i in range(len(Data)): if Data[i, 0] > Data[i — 1, 3] and Data[i, 3] < Data[i — 1, 3] and \ Data[i, 3] > Data[i — 1, 0]: Data[i + 1, 5] = -1# Position triggerfor i in range(len(Data)): if Data[i, 4] == 1: Data[i, 6] = 1 if Data[i, 5] == -1: Data[i, 7] = -1
The next graph shows the equity curve from the strategy and the results followed by the signals chart to give us a visual idea on the frequency.



MORNING & EVENING STARS
Main idea: The morning star is a bullish reversal pattern typically occurring at the bottom of the market and is composed of three candles while the evening star is a bearish reversal pattern typically occurring at the bottom of the market and is composed of three candles as well. Even before back-testing them, if we take a look at the graphical illustration in the first section, we can already conclude that it is a rare pattern. Focus on the number of trades and compare it to the other candlestick patterns strategies.
# Key conditions
for i in range(len(Data)): if Data[i — 1, 0] == Data[i — 1, 3] and \ Data[i — 2, 3] < Data[i — 2, 0] and \ Data[i, 3] > Data[i, 0] and \ Data[i — 1, 0] < Data[i — 2, 3] and \ Data[i — 1, 0] < Data[i, 0]: Data[i + 1, 4] = 1for i in range(len(Data)): if Data[i — 1, 0] == Data[i — 1, 3] and \ Data[i — 2, 3] > Data[i — 2, 0] and \ Data[i, 3] < Data[i, 0] and \ Data[i — 1, 0] > Data[i — 2, 3] and \ Data[i — 1, 0] > Data[i, 0]: Data[i + 1, 5] = -1# Position triggerfor i in range(len(Data)): if Data[i, 4] == 1: Data[i, 6] = 1 if Data[i, 5] == -1: Data[i, 7] = -1
The next graph shows the equity curve from the strategy and the results followed by the signals chart to give us a visual idea on the frequency.



In conclusion, it is clear that candlestick patterns do not work on their own and need other combinations of indicators to enhance the signals.
