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 Pivot Breakout Engulfing Hedge is a pure price-action expert advisor (EA) for MetaTrader 5 that combines three classic technical tools: floor pivot points (the R1 resistance and S1 support levels intraday desks watch closely), the engulfing candlestick pattern (a momentum candle whose body completely covers the previous candle's body), and a managed hedging mechanism. It uses no lagging indicators — no moving averages, RSI, ATR, Bollinger Bands, or VWAP — which makes it a clean case study in how raw candle structure and horizontal levels can be turned into a rules-based trading system.
The strategy is built for a specific market condition: liquid, breakout-prone instruments where price repeatedly tests pivot levels and then either breaks through with conviction or fakes out and snaps back. In plain terms, it is designed for the constant tug-of-war that happens at resistance and support. A naive breakout trader wins when a level breaks cleanly but gets repeatedly stopped out by "stop-hunt" fakeouts. This system attempts to address the second case directly by deploying an opposite hedge leg when a breakout fails, rather than simply absorbing the loss.
As a learning tool, the Pivot Breakout Engulfing Hedge is best suited to traders who already understand candlestick patterns and pivot mathematics and who want to study how breakout logic, false-break detection, and basket-level money management can be coded together. It is an intermediate-to-advanced example — the hedging component in particular requires careful study. It should be treated as an educational framework for understanding price-action automation, not as a shortcut to results.
How It Works
The strategy recalculates its levels on every closed bar and only looks for new trades when it is completely flat. Here is the logic step by step.
Level calculation (the foundation):
- Over the last
PivotLookbackclosed bars, the EA finds the highest high (H), the lowest low (L), and the most recent close (C). - It computes the classic floor pivot: PP = (H + L + C) / 3, then R1 = 2 × PP − L and S1 = 2 × PP − H.
- The pivot "range" (H − L) is used to size every buffer, stop, and target, so the strategy scales to any symbol or timeframe without hard-coded pip values.
Entry conditions (the strategy signals a trade when, while flat):
- Long setup: the just-closed candle is a bullish engulfing bar, it is strong-bodied (its body is a large fraction of its full range, filtering out weak wicky candles), the prior bar sat at or below R1, and this candle closes decisively above R1. This signals that resistance was broken with force.
- Short setup: the just-closed candle is a bearish engulfing bar, strong-bodied, the prior bar sat at or above S1, and this candle closes decisively below S1. This signals that support was broken with force.
- A spread filter (
MaxSpreadPoints) blocks new entries when trading costs are abnormally high.
Stop-loss and take-profit on the base leg:
- The base take-profit projects a measured move in the breakout direction, sized by
RewardFrac× range. - The base stop-loss is deliberately placed beyond the hedge trigger (padded by
StopFrac), so on a fakeout the hedge mechanism always engages before the base stop is hit.
The hedge (the signature mechanic):
- While the single base leg is open, the EA watches for price to travel back inside the broken level by
FalseBreakFracof the range. This is treated as confirmation that the breakout was a trap. - When that happens, the strategy opens an opposite market leg — now holding both directions — to ride the snap-back reversal toward the central pivot. The hedge leg's volume is
Lots × HedgeMult, so a heavier counter-leg can offset the trapped base leg. - The hedge has its own invalidation: if price reclaims the broken level by
ReclaimFracof the range, the reversal thesis is considered wrong and the hedge's stop is positioned accordingly.
Basket exit (the dominant exit while any position is open):
- If net floating profit across all legs reaches
BasketTpMoney, the EA closes everything — banking either the clean breakout or the hedged recovery. - If net floating loss reaches
BasketSlMoney, the EA flattens everything as a hard ceiling against a wide whipsaw that pays neither leg.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| PivotLookback | 24 | 5 | 150 | Number of closed bars whose high/low/close define the floor pivots. |
| BreakFrac | 0.03 | 0.00 | 0.50 | How far beyond R1/S1 the candle must close to confirm a break (fraction of pivot range). |
| BodyFrac | 0.55 | 0.20 | 0.95 | Minimum breakout body as a fraction of its full range — filters weak, wicky breaks. |
| FalseBreakFrac | 0.25 | 0.05 | 1.00 | Distance back inside the broken level that confirms the break failed and triggers the hedge. |
| StopFrac | 0.40 | 0.05 | 2.00 | Extra base-stop pad placed beyond the hedge trigger (fraction of range). |
| RewardFrac | 1.00 | 0.20 | 4.00 | Measured-move reward for the breakout/hedge target (fraction of range). |
| ReclaimFrac | 0.40 | 0.05 | 1.50 | Hedge invalidation pad — if the broken level is reclaimed by this much, the hedge is wrong. |
| HedgeMult | 1.50 | 0.50 | 3.00 | Hedge volume multiplier (hedge lots = Lots × HedgeMult). |
| BasketTpMoney | 25.0 | 5.0 | 2000.0 | Close the whole basket once net floating profit reaches this (account currency). |
| BasketSlMoney | 300.0 | 50.0 | 100000.0 | Flatten the whole basket once net floating loss reaches this (account currency). |
| MaxSpreadPoints | 50 | 0 | 500 | Skip new entries while spread (points) exceeds this (0 = off). |
| Lots | 0.10 | 0.01 | 1.00 | Base leg trade volume in lots. |
| Magic | 5310 | 0 | 9,999,999 | Magic number used to identify this EA's positions. |

Recommended Chart Settings
The Pivot Breakout Engulfing Hedge was designed for liquid, breakout-prone instruments such as GBP/USD, USD/JPY, or XAU/USD (gold) on the M5 or M15 timeframes, where pivot breaks and stop-hunt fakeouts alternate frequently. The pivot range automatically scales every buffer and target, so the EA can technically run on any symbol or timeframe selected at backtest time.
That flexibility is a double-edged sword: the same settings that work on one instrument may behave very differently on another. Results will vary across symbols, brokers, spreads, and market conditions, so any timeframe or symbol you choose should be studied carefully on its own before being considered.
Important: Because this EA opens simultaneous opposing legs (a true hedge), it requires a hedging account. On a netting account the two legs would net out and the hedge logic would not function as intended.
How to Install on MetaTrader 5
- Download the
PivotBreakoutEngulfingHedge.ex5file from the link below. - Copy it to your MT5
MQL5\Expertsfolder. - Restart MetaTrader 5 or refresh the Navigator panel.
- Drag the EA onto a chart matching the recommended symbol and timeframe.
- Configure the input parameters and enable Algo Trading.
What to Consider Before Using This EA
Like any strategy, the Pivot Breakout Engulfing Hedge has clear strengths and equally clear limitations, and it is worth weighing both honestly.
Strengths:
- It is pure price action, so there are no indicator lag or repaint concerns to reason about.
- Pivot levels and engulfing patterns are well-documented, widely-watched concepts, which makes the logic transparent and easy to study.
- The false-break hedge is a thoughtful attempt to handle the single biggest weakness of breakout trading — getting trapped by fakeouts.
- Range-relative sizing means no fragile pip hard-coding across symbols.
Limitations to understand:
- Hedging is complex and account-dependent. Holding both directions can cap a loss in a whipsaw, but it also means two sets of spread and potential swap costs, and the basket can sit underwater for extended periods before resolving.
- Range-bound, low-volatility markets can produce many small false breaks where neither the base nor the hedge reaches its target, leaving the basket money-management rules to decide the outcome.
- The basket stop is defined in account currency, not as a fixed percentage, so its real risk depends entirely on your account size and lot settings.
- Breakout systems historically endure choppy periods with frequent small losses between cleaner trending moves. This is normal for the style and should be expected rather than treated as a malfunction.
The honest takeaway is that this EA is a sophisticated educational example of combining pattern recognition with hedged risk control — not a set-and-forget solution. It rewards study and careful testing.
Risk Management Tips
Sound risk management matters far more than any single entry signal. As you study this strategy, keep these general principles in mind:
- Risk only a small fraction per setup. A common guideline is to risk no more than 1–2% of account equity on any single idea. With basket-level stops, calculate what
BasketSlMoneyrepresents as a percentage of your account before trading. - Always start on a demo account. Run the EA on a demo or paper account long enough to understand how it behaves through different market conditions before risking real capital.
- Understand drawdown. Every strategy experiences losing streaks. Know the largest peak-to-trough decline you are willing to tolerate, and size your positions so a normal drawdown does not threaten your account.
- Mind position sizing with the hedge. Because the hedge multiplies your exposure, your effective lot size can be larger than the base
Lotsvalue suggests. Account for the combined exposure of both legs. - Account for costs. Spread, commission, and overnight swap can meaningfully affect a scalper-style system that opens two legs. Factor these into any evaluation.
- Never trade money you cannot afford to lose, and consider consulting a qualified financial adviser about whether leveraged trading suits your circumstances.
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
- Expert Advisor: PivotBreakoutEngulfingHedge.ex5 (2 downloads)
- Source Code: PivotBreakoutEngulfingHedge.mq5 (5 downloads)
- Documentation: PivotBreakoutEngulfingHedge.pdf (3 downloads)