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 Anchor Engulfing Hedge is a pure price-action Expert Advisor (EA) for MetaTrader 5 that combines classic floor pivot points with the engulfing candlestick pattern in a counter-trend, or "fade," trading style. It uses no technical indicators at all — no moving averages, no oscillators, no momentum tools. Instead, every decision is built from raw price: the prior day's high, low, and close, and the shape of the two most recently completed candles.
Floor pivots are a set of horizontal reference levels — the Pivot Point (PP), two resistance levels (R1, R2), and two support levels (S1, S2) — calculated from the previous trading day's range. Many traders watch these levels because price often reacts to them, either bouncing away or breaking through. An engulfing candle is a two-bar reversal pattern in which a candle fully "engulfs" the body of the one before it, often signalling that momentum has shifted. This strategy waits for both signals to line up at the same place: an engulfing candle forming right at a pivot level.
This EA is best suited to traders who are studying how support and resistance interacts with candlestick reversals, and who want a transparent, rules-based example to dissect. Because it is a learning tool rather than a turnkey solution, it is most valuable to those comfortable running backtests, reading the logic, and experimenting on a demo account. Treat it as a structured case study in mean-reversion and breakout mechanics, not as a shortcut.
How It Works
The strategy runs entirely on your chart's primary timeframe and rebuilds the daily pivots itself by aggregating bars and detecting the calendar-date rollover. Here is the full sequence of logic:
- Pivot calculation: At the start of each new calendar day, the EA finalizes the day that just ended and computes the classic floor pivots from that day's high (H), low (L), and close (C): PP = (H + L + C) / 3, R1 = 2·PP − L, S1 = 2·PP − H, R2 = PP + (H − L), and S2 = PP − (H − L). The prior day's range (H − L) is stored and used to scale every distance-based threshold.
- Bar gating: The EA acts only once per fully completed bar, not on every tick, so signals are based on closed candles and remain stable.
- Bullish reversal (BUY) signal: The strategy signals a long "fade" when the most recently completed candle is a bullish engulfing candle (it closes up and engulfs the prior down candle), its low wicks into a support pivot (S1, S2, or PP) within a proximity tolerance, and it closes back above that pivot. This may indicate that sellers pushed into support and were rejected.
- Bearish reversal (SELL) signal: The mirror image. The strategy signals a short fade when a bearish engulfing candle spikes its high into a resistance pivot (R1, R2, or PP) and closes back below it.
- Stop-loss logic: For a long, the stop is placed just below the lower of the two signal candles' lows, minus a small buffer scaled from the candle's range. For a short, it sits just above the higher of the two highs, plus the buffer. The stop therefore sits just beyond the engulfing extreme — the level that, if breached, would invalidate the setup.
- Take-profit logic: The target is set at a reward-to-risk multiple of the stop distance. With the default RewardRisk of 1.6, the take-profit is placed 1.6 times further from entry than the stop, measured in price.
- The hedge — breakout continuation: After a fade is opened, the EA watches the anchored pivot. If price later closes decisively through that pivot (beyond a breakout distance scaled from the prior day's range), the original defense is considered to have failed. The strategy then opens an opposite breakout position — tagged with a separate magic number (Magic + 1) — to ride the continuation. In effect, a losing pivot fade can be converted into a breakout trade going the other way. Only one hedge is opened per setup.
- Setup expiry: Each setup carries an expiry counter (SetupExpiryBars). If the pivot is neither defended nor decisively broken within that window, the setup is simply retired and the EA looks for a fresh opportunity. New setups are only sought when no setup is active and no position with the base magic number is already open.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade size in lots for every position, including the hedge. |
| RewardRisk | 1.6 | 0.5 | 4.0 | Reward-to-risk multiple. The take-profit distance equals this value times the stop-loss distance. |
| ProximityPercent | 12.0 | 2.0 | 40.0 | How close a candle's wick must come to a pivot, expressed as a percent of the prior day's range, to count as "touching" it. |
| SlBufferPercent | 12.0 | 0.0 | 60.0 | Extra cushion added beyond the signal candle's extreme when placing the stop, as a percent of that candle's range. |
| BreakoutPercent | 18.0 | 5.0 | 60.0 | How far beyond the anchored pivot price must close to trigger the hedge, as a percent of the prior day's range. |
| SetupExpiryBars | 6 | 1 | 30 | Number of bars a setup stays active before it expires if the pivot is neither broken nor resolved. |
| EnableHedge | 1 | 0 | 1 | Toggles the breakout hedge logic. Set to 1 to enable, 0 to trade fades only. |

Recommended Chart Settings
This strategy was designed to be applied to a single chart on its primary timeframe, which it also uses to reconstruct the daily pivots. An intraday timeframe such as M15, M30, or H1 tends to align well with daily floor pivots, giving enough completed bars per day for setups to form while keeping the pivot levels meaningful. Liquid instruments with clean, well-defined daily ranges — major forex pairs such as EUR/USD or GBP/USD, or a major index CFD — are natural candidates for study because pivot levels behave more consistently when spreads are tight and ranges are orderly.
Bear in mind that pivot behaviour is not uniform across symbols or sessions. Results will vary across different market conditions, instruments, and broker feeds. Always confirm how the daily rollover and pivots are calculated on your specific broker's server time before drawing conclusions, since the "calendar day" the EA detects depends on that clock.
How to Install on MetaTrader 5
- Download the .ex5 file 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 approach, the Pivot Anchor Engulfing Hedge has clear strengths and clear limitations, and understanding both is the point of studying it.
Strengths. The logic is transparent and fully price-based, which makes it an excellent teaching example — there are no opaque indicator calculations to obscure why a trade fired. Requiring an engulfing candle and pivot proximity and a close back through the level is a multi-condition filter that screens out many low-quality signals. Defining the stop just beyond the engulfing extreme ties risk directly to the structure that would invalidate the idea. The optional hedge is a thoughtful attempt to address the classic weakness of fading: pivots sometimes break rather than hold, and the breakout conversion is designed to participate when they do.
Known limitations. Counter-trend, mean-reversion strategies tend to struggle in strong, sustained trends, where support and resistance levels are broken repeatedly rather than respected. In choppy, low-range days the pivots cluster tightly and signals may be noisy or conflicting. The hedge does not close the original losing position — it adds an opposing one — so during a clean breakout it is possible for the fade's stop to be hit while the hedge is still developing, meaning both positions carry risk simultaneously. Fixed lot sizing does not adapt to volatility or account size. And because pivots reset daily, the strategy is sensitive to how your broker defines the trading day.
Where it may underperform. Expect weaker behaviour during high-impact news spikes, illiquid sessions with wide spreads, and persistent one-directional trends. The strategy historically suits range-bound or rotational conditions far better than runaway momentum. None of this is a verdict — it is a map of where to focus your own testing.
Risk Management Tips
Sound risk management matters more than any single entry rule. Keep these general principles in mind as you study this EA:
- Risk a small, fixed fraction per trade. A common guideline is to risk no more than 1–2% of account equity on any single position. Because this EA uses a fixed lot size, you may need to adjust the Lots value to your account so the stop distance translates into an acceptable monetary risk.
- Account for the hedge. Remember that the breakout hedge can mean two positions are open at once. Size your risk with that combined exposure in mind, not just a single trade.
- Always demo first. Run the strategy on a demo account across many different market conditions before considering any live use, so you understand its behaviour and rhythm.
- Understand drawdown. Every strategy has losing streaks. Review the maximum historical drawdown in your own backtests and ask whether you could tolerate it emotionally and financially.
- Respect leverage. Leverage magnifies both gains and losses. Use it conservatively and never commit capital you cannot afford to lose.
- Keep records. Journaling each setup, hedge, and outcome turns the EA from a black box into a genuine learning tool.
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: PivotAnchorEngulfingHedge.ex5 (3 downloads)
- Source Code: PivotAnchorEngulfingHedge.mq5 (4 downloads)
- Documentation: PivotAnchorEngulfingHedge.pdf (3 downloads)