Give Your EA Eyes: Automating Candlestick & Chart Patterns!

Rejected methods · 5 min

It's no secret that traders are always looking for an "edge" – that consistent statistical advantage that helps them make profitable trades. For us he

A beginner-friendly summary of the verification: “Give Your EA Eyes: Automating Candlestick & Chart Patterns!”.

Breakout entry example (XAUUSD daily, real data): buy when price breaks above the recent high.

Breakout entry example (XAUUSD daily, real data): buy when price breaks above the recent high.

It’s no secret that traders are always looking for an “edge” – that consistent statistical advantage that helps them make profitable trades. For us here, building robust algorithmic trading systems (EAs, or Expert Advisors) means constantly expanding our toolkit to quantify what many discretionary traders already use. This time, we’ve focused on bringing the classic wisdom of candlestick and chart patterns into our automated analysis!

What’s the idea?

Our goal is to create a versatile “quantification engine” that can translate common trading strategies into hard numbers. We’re strictly focusing on FX prices for now, as stock indices don’t fit our current prop trading needs. The key is that everything we build is “leak-free” – meaning our analysis never peeks into the future (no look-ahead bias), ensuring our backtests are as realistic as possible. These robust tools then become “permanent assets” for all our future research. This latest development is all about adding sophisticated detection for both individual candlestick patterns and larger chart formations. Think of it as giving our EAs eyes to see what human traders have recognized for decades.

Diving into the Patterns: Our New Engine

We’ve integrated two main new components into our btengine library: one for candlesticks and one for chart patterns.

Candlestick Patterns

Candlestick patterns are like the market’s facial expressions, offering quick visual clues about sentiment. Our new candle_patterns() function in btengine/candles.py can now automatically identify a whole range of these:

  • Doji: Indecision, a tug-of-war between buyers and sellers.
  • Hammer / Shooting Star: Reversal signals, often found at bottoms (hammer) or tops (shooting star).
  • Marubozu: Strong directional movement, either bullish or bearish, with little to no shadows.
  • Engulfing: A powerful reversal where a large candle completely covers the previous one.
  • Harami: A smaller candle contained within a larger one, often signaling slowing momentum.
  • Piercing / Dark Cloud Cover: Reversal patterns, typically bullish (piercing) or bearish (dark cloud) after a strong move.
  • Tweezer Tops / Bottoms: Two or more candles with identical highs or lows, indicating a strong resistance or support level.
  • Morning / Evening Star: Three-candle reversal patterns, signalling a shift from bearish to bullish (morning) or bullish to bearish (evening). On top of detecting these, we’ve also implemented bull_score and bear_score to give us a numerical measure of bullish or bearish strength, helping us quantify the market’s mood even further.

Classic Chart Patterns

Beyond individual candles, price charts often form larger, recognizable shapes that hint at future moves. Our chart_patterns() function in btengine/chartpatterns.py now specifically looks for:

  • Double Tops and Double Bottoms: These “M” and “W” shapes signal potential reversals after two failed attempts to break a key resistance or support level.
  • Head & Shoulders (and Inverse H&S): A classic reversal pattern with three peaks (or troughs), where the middle one is the highest (or lowest). We detect these from “confirmed swings” – meaning we wait for clear, established price moves – and generate a signal when the “neckline” (the support/resistance connecting the pattern’s lows/highs) is broken. We’re also looking ahead to add more sophisticated patterns like Harmonic patterns (Gartley, Bat, Butterfly, based on Fibonacci ratios) to our backlog.

Our Growing Toolkit

These new additions are just the latest pieces in our ever-expanding analytical toolkit. Our full suite of quantification engines now includes:

  • A wide range of indicators (like moving averages, RSI, MACD).
  • Levels (identifying important horizontal support and resistance zones).
  • Channels (detecting upward or downward trending diagonal boundaries).
  • Dow structure (analyzing market trends based on higher highs/lows or lower highs/lows).
  • Profile (examining price distribution, like volume profiles).
  • Pivots (key price levels often used for support/resistance).
  • Fibonacci retracement and extension levels.
  • The newly added Candles and Chart Patterns.
  • Regime (identifying the current market environment, e.g., trending, ranging). In other words, we’re building a comprehensive set of tools that allows us to rigorously backtest any discretionary trading method you can imagine, bringing a scientific approach to classic trading wisdom.

What I Learned (and What We Already Knew!)

Now for the honest truth! While it’s exciting to have these powerful pattern detection capabilities, our previous research (specifically Studies 73-79) has shown something very important: when it comes to finding an “edge” in FX trends, simply using these patterns on their own might not be enough. Our past findings indicated that when we tried to filter these various tools within an FX trend framework, only swing-level analysis – looking at the significant highs and lows of price movement – consistently generated a positive edge. Other approaches, or using tools without this specific context, tended to be “so-so” or even “bad” (△〜✕ in our notes). We anticipate that these new candlestick and chart patterns will likely follow a similar pattern. They are fantastic visual cues for human traders, but as standalone signals for an EA, they might not immediately yield consistent profits in a trending FX market without further filtering. So, why build them then? Because this project is all about strengthening our foundation! These patterns are crucial building blocks. By accurately identifying them, we can now move on to test more sophisticated hypotheses. For example, we can combine a specific candlestick pattern only when the market is in a particular trend regime, and when it’s at a key swing level. This allows us to explore complex, multi-factor strategies that were impossible to backtest before. This isn’t about finding a magic pattern that guarantees profits overnight. It’s about building the robust, leak-free tools that will allow us to uncover true, verifiable edges in the future. It’s all about making our research capabilities stronger for whatever comes next!

How this connects

This verification builds on earlier ones (what failed before and what I tried this time, comparisons between approaches).

Code to reproduce

You can reproduce this with the following scripts (see repo).

  • btengine/candles.py
  • btengine/chartpatterns.py