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).

Image for post
Image for post
Dark-cloud pattern
Image for post
Image for post
Piercing pattern
Image for post
Image for post
The morning star
  • 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.
Image for post
Image for post
The evening star
  • 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.
Image for post
Image for post
Harami
Image for post
Image for post
Three black crows
Image for post
Image for post
Three white knights
Image for post
Image for post
A gap
Image for post
Image for post
Tasuki
Image for post
Image for post
Tri-star
Image for post
Image for post
Tower top
Image for post
Image for post
Tower bottom

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.

# 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
Image for post
Image for post
Equity curve
Image for post
Image for post
Signals
Image for post
Image for post
Brief performance stats
# 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
Image for post
Image for post
Equity curve
Image for post
Image for post
Signals
Image for post
Image for post
Brief performance stats
# 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
Image for post
Image for post
Equity curve
Image for post
Image for post
Signals
Image for post
Image for post
Brief performance stats
# 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
Image for post
Image for post
Equity curve
Image for post
Image for post
Signals
Image for post
Image for post
Brief performance stats
Image for post
Image for post
https://pixabay.com/photos/chart-trading-courses-forex-1905225/

Written by

Institutional FOREX Strategist | Trader | Data Science Enthusiast. Author of the Book of Back-tests: https://www.amazon.com/dp/B089CWQWF8