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 Session Vwap Engulfing Hedge is a pure price-action, mean-reversion expert advisor (EA) for MetaTrader 5 that is built entirely by hand from raw price bars — it uses no library indicators such as moving averages, RSI, Bollinger Bands, or ATR. Its centerpiece is a session-anchored VWAP (Volume-Weighted Average Price), the running average price each bar trades at, weighted by volume. Around that VWAP it constructs its own standard-deviation bands to measure how far price has stretched from "fair value," and it combines this with three classic price-action concepts: an engulfing candle reversal pattern, a liquidity sweep of recent highs or lows, and an imbalance (Fair Value Gap) displacement filter.
The strategy is designed for liquid, intraday markets where price tends to oscillate around value — think FX majors like EUR/USD and GBP/USD, gold (XAU/USD), or an index CFD — on intraday timeframes such as M5, M15, or M30. The core idea is that when price is pushed a long way from VWAP, it becomes statistically "expensive" or "cheap" relative to the day's traded value, and the final stretch often runs stops at a recent swing point before snapping back toward the mean.
As a learning tool, this EA is best suited to traders who want to study how institutional-style "value" concepts (VWAP, standard-deviation bands) can be combined with retail-popular price-action triggers (engulfing bars, sweeps, Fair Value Gaps) and a reactive hedging mechanic. This is a strategy analysis, not a profit opportunity — the goal here is to understand how the logic is constructed and where it may struggle.
How It Works
The strategy stays completely flat until a clean setup appears, then manages each trade with structural stops and a reactive hedge. Entry logic is evaluated once per freshly closed bar, while hedge management runs on every tick.
Building the VWAP and bands:
- Every closed bar, the EA folds the typical price
(High + Low + Close) / 3— weighted by volume — into cumulative sums that reset at each new calendar day (the session anchor). - From those sums it derives the VWAP and the variance, then sets bands at
VWAP ± DeviationMult × standard deviation. - It waits until at least
MinSessionBarsbars have formed since the anchor before it trusts the VWAP.
The strategy signals a LONG when all of these align:
- Price is stretched below value — the recent low has touched or pierced the lower band.
- The just-closed bar sweeps support — it prints a new local low versus the prior
SweepLookbackbars (a liquidity grab). - The trigger bar is a bullish engulfing of the previous bar (it closes up and engulfs the prior bearish body).
- It shows displacement / imbalance — the bar closes above the prior high, or it leaves a bullish Fair Value Gap (a 3-bar price void).
- Its body beats the recent average body by
MomentumMult(a momentum check). - The close is still below VWAP, leaving room to revert up. The take-profit target is the VWAP itself.
The strategy signals a SHORT under the exact mirror conditions: price stretched above the upper band, a sweep of recent resistance (new local high), a bearish engulfing bar, downward displacement or a bearish Fair Value Gap, sufficient momentum, and a close still above VWAP.
Stop-loss and take-profit logic (per leg, structural):
- Stop-loss is placed beyond the swept extreme by
StopPadFracof the recent average range, then clamped to the broker's minimum stop distance. - Take-profit is the session VWAP — the mean-reversion magnet. If VWAP is too close to offer a real reward, the TP is floored to
TpFloorMult × average range. - The setup is rejected if the reward-to-risk ratio is below
MinRewardRisk.
The reactive hedge (the signature mechanic):
- While a base trade is live, if its adverse excursion reaches
HedgeTriggerFracof the base's own risk, the EA opens an opposite market position sized atHedgeMultof the base. - The hedge's take-profit sits beyond the base stop-loss, so it gains as a runaway move extends; its stop sits on the reclaim side.
- If price recovers (adverse excursion falls back below
HedgeReleaseFracof risk), the hedge is closed so it stops bleeding and the base is left to reach VWAP. - When the base finally resolves at its own stop or target, any surviving hedge is closed — the EA never leaves a naked reversed leg.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| DeviationMult | 2.00 | 1.00 | 3.50 | Standard deviations from VWAP that count as "stretched" (band half-width). |
| RangeLookback | 14 | 5 | 40 | Bars used for the average range and average body baselines. |
| SweepLookback | 10 | 3 | 40 | Window the swept extreme must be the new low/high of (liquidity-grab depth). |
| MomentumMult | 1.10 | 0.50 | 2.50 | Trigger body must be at least this multiple of the recent average body. |
| StopPadFrac | 0.50 | 0.10 | 3.00 | Base stop pad beyond the swept extreme, in units of the average range. |
| MinRewardRisk | 0.80 | 0.20 | 3.00 | Rejects setups whose reward (entry→VWAP) is below this multiple of risk. |
| TpFloorMult | 1.50 | 0.30 | 5.00 | Fallback TP distance (avg-range units) if VWAP is too close for real reward. |
| HedgeTriggerFrac | 0.70 | 0.20 | 1.50 | Adverse excursion (fraction of base risk) that arms the reactive hedge. |
| HedgeReleaseFrac | 0.30 | 0.05 | 1.00 | Adverse excursion (fraction of base risk) at/below which a live hedge is released. |
| HedgeRewardFrac | 1.00 | 0.20 | 4.00 | Hedge TP distance beyond the base SL, in fractions of base risk. |
| HedgeReclaimFrac | 0.50 | 0.10 | 2.00 | Hedge SL distance on the reclaim side, in fractions of base risk. |
| HedgeMult | 1.00 | 0.30 | 2.00 | Hedge size as a multiple of the base size. |
| MinSessionBars | 6 | 2 | 50 | Minimum closed bars since the session anchor before VWAP/bands are trusted. |
| MaxSpreadPoints | 50 | 0 | 500 | Skip new entries while spread (points) exceeds this (0 = off). |
| Lots | 0.10 | 0.01 | 1.00 | Base trade size in lots. |
| Magic | 7420 | 0 | 9,999,999 | Unique magic number to identify this EA's orders. |

Recommended Chart Settings
This strategy was designed for liquid, VWAP-respecting intraday instruments — FX majors such as EUR/USD or GBP/USD, XAU/USD (gold), or an index CFD — on the M5, M15, or M30 timeframes, where the stretch-sweep-snap rhythm around value tends to be most pronounced. Because every distance is derived from standard deviations and the average bar range, the logic adapts to any symbol or timeframe without hard-coded pip values. Results will vary considerably across different instruments, sessions, and market conditions, so treat these as a starting point for your own study rather than a fixed prescription.
Note that the reactive hedge opens an opposite market position while the base is live. This requires a hedging account; on a netting account the opposite order would simply net out the base, and the mechanic will not behave as intended.
How to Install on MetaTrader 5
- Download the
.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
Strengths of the approach. Building everything from raw bars means there are no indicator lag or repaint concerns, and the logic is transparent and auditable. Anchoring to VWAP gives the strategy an objective, volume-aware definition of "value," and requiring an engulfing bar plus a sweep plus displacement is a strict, multi-condition filter that historically reduces low-quality signals. The structural VWAP target is a logical place for a mean-reversion exit.
Known limitations. Mean reversion is, by design, the wrong stance during a strong trend day. When price stretches beyond a band and simply keeps going — a genuine breakout or news-driven move — the base trade fights the dominant direction. The hedge is meant to cap that scenario, but hedging is not a cure: it can convert one losing trade into two costs (spread, swap, and the gap between the legs), and a choppy "whipsaw" that repeatedly arms and releases the hedge may erode the account through transaction costs.
Where it may underperform. Thin liquidity, wide spreads, low-volatility ranges that never reach the bands, and erratic news periods all reduce signal quality. The strict multi-condition entry also means the EA may trade infrequently, so patience and realistic expectations matter. Always study its behavior on a demo account across many market conditions before drawing conclusions.
Risk Management Tips
- Size positions conservatively. A common educational guideline is to risk no more than 1–2% of account equity per trade. With a reactive hedge that can add a second position, account for the combined exposure of both legs, not just the base.
- Test on a demo account first. Run the EA in MT5's Strategy Tester and on a demo account across trending, ranging, and high-volatility periods before considering any live capital.
- Understand drawdown. Every strategy experiences losing streaks. Know the maximum historical drawdown you are willing to tolerate and how the hedge mechanic affects it.
- Mind the costs. Spread, commission, and swap can meaningfully affect a high-frequency, intraday, hedging system. Factor realistic costs into any evaluation.
- Verify your account type. Confirm you are on a hedging account so the hedge leg behaves as designed, and check that your broker's minimum stop distance is compatible with the strategy's structural stops.
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: SessionVwapEngulfingHedge.ex5 (3 downloads)
- Source Code: SessionVwapEngulfingHedge.mq5 (3 downloads)
- Documentation: SessionVwapEngulfingHedge.pdf (5 downloads)