Blog / Strategy
Strategy

Cup Handle Breakout

Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.

What Is This Strategy?

The Cup Handle Breakout is an automated pattern-recognition strategy built around one of the most famous chart formations in technical analysis: William O'Neil's cup-and-handle. Rather than relying on a single oscillator, it reads the geometry of price — a rounded base (the "cup") followed by a small, shallow drift-back consolidation (the "handle") — and uses an Exponential Moving Average (EMA) as a trend filter and the Average True Range (ATR) as its volatility yardstick. It is a breakout continuation strategy, meaning it looks to enter in the direction of the prevailing trend the moment price decisively clears a well-defined resistance level.

The cup-and-handle pattern describes a market that sells off in a smooth, saucer-shaped curve, recovers back to roughly the same level it left from, and then pauses in a tight, shallow pullback just below that recovered high (the "rim"). When price finally pushes through the rim, the theory holds that the accumulation built up during the base releases into a measured advance. This strategy encodes that story into strict, testable rules and trades it symmetrically — a normal rounded-bottom cup for long trades, and an inverted rounded-top cup for shorts.

As a learning tool, the Cup Handle Breakout is well suited to traders who want to understand how a subjective, hand-drawn chart pattern can be translated into objective, quantifiable conditions. It is designed for liquid markets — a major forex pair or an index — on intraday-to-swing timeframes such as M15 through H4. It is best viewed as a study in pattern structure and disciplined risk placement, not as a shortcut to returns.

How It Works

The strategy processes each freshly closed bar (it does not act on the still-forming bar, which avoids repainting). It measures a cup over the most recent CupBars bars before the handle, splits that window into equal left, middle, and right thirds, and then validates the handle and the breakout bar. Here is what the strategy checks, in plain English:

When all three groups of conditions align, the strategy signals an entry and manages the position as follows:

Only one position is held at a time, and the logic is fully symmetric between long and short setups.

cup and handle breakout EA
Illustrative example of the strategy’s entry and exit logic — not real trading results.

Strategy Parameters

Parameter Default Min Max Description
CupBars 30 12 60 Length of the rounded-base region (the cup), split internally into three equal thirds.
HandleBars 6 3 15 Length of the shallow consolidation that hugs the rim (the handle).
MinDepthAtr 1.50 0.50 5.00 Minimum cup depth in ATRs; rejects flat "cups" that are really noise.
RimTolAtr 1.00 0.25 3.00 Maximum height difference between the two rims, in ATRs (rim symmetry / level base).
HandleMaxDepth 0.50 0.20 0.80 Maximum fraction of the cup depth the handle may retrace (a shallow handle).
BreakBufferAtr 0.10 0.00 1.00 Decisive-break margin; the breakout close must clear the rim by this × ATR.
TrendPeriod 100 20 250 Trend-context EMA period; breaks are taken only with the trend (continuation filter).
AtrPeriod 14 7 28 Averaging period for the ATR volatility measure.
StopBufferAtr 0.25 0.00 1.50 Extra ATR buffer placed beyond the handle extreme for the structural stop.
RewardRisk 2.00 0.50 6.00 Take-profit as a multiple of the (tight) stop distance.
BreakevenAtr 1.00 0.00 3.00 Pull the stop to breakeven after price runs this × ATR in favour.
Lots 0.10 0.01 1.00 Order volume (position size in lots).
Magic 7314 0 9,999,999 Magic number used to identify this EA's trades.
cup and handle breakout EA — MQL5 source code

Recommended Chart Settings

The Cup Handle Breakout was designed to run on a single primary timeframe and suits a liquid FX major or an index. Practical timeframes for observing the pattern are M15 to H4 — long enough for a cup to form with real structure, short enough to generate a reasonable number of setups for study. The strategy is timeframe-agnostic by design, so the symbol and period are chosen at backtest time.

Because the cup depth, rim tolerance, break buffer, and stop distance are all scaled by ATR, the strategy adapts automatically to different volatility environments. Even so, results will vary considerably across symbols, sessions, and market regimes. Always test any configuration on your chosen instrument and timeframe before drawing conclusions.

How to Install on MetaTrader 5

What to Consider Before Using This EA

Strengths of this approach. The cup-and-handle is a widely studied, intuitive pattern, and encoding it into strict rules removes the subjectivity of drawing curves by hand. The structural stop just below the handle is a genuine strength: because a valid handle is shallow and hugs the rim, the invalidation level is close to entry, which keeps individual losses small and well-defined. Layering a trend filter, a failed-breakout exit, and a breakeven ratchet on top of that gives the strategy several independent ways to limit damage on a trade that does not work.

Known limitations. Breakout strategies are, by nature, vulnerable to false breaks — price clears the rim, triggers entry, then reverses. The buffer, the first-close requirement, and the failed-breakout exit are all attempts to filter these, but no filter eliminates them. In choppy, range-bound conditions the strategy may take a series of small losses as breakouts fail to follow through. Because it demands a fairly specific geometric shape, valid setups can also be infrequent, which means fewer trades and a longer path to a statistically meaningful sample.

Where it may underperform. Very quiet, low-volatility markets can struggle to produce cups that clear the MinDepthAtr threshold, while violent, gapping conditions can invalidate the neat rim symmetry the pattern relies on. The trend filter helps keep trades aligned with the broader move, but a sharply reversing market can whipsaw both long and short setups. Treat this EA as a framework for studying breakout behaviour rather than a finished, all-weather system.

Risk Management Tips

Sound risk management matters more than any single entry pattern. Consider these general principles as you study this strategy:

Risk Warning

Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.

Downloads

← Back to Blog