Forex
EA

EA: Envelopes Reversal Expert Advisor

Last updated 2026-07-17

An Expert Advisor (EA) is different from every other download on this site — an indicator only plots or alerts, while an EA actually sends orders on your behalf. This free EA trades a mean-reversion strategy built entirely around Envelopes: it opens a trade the moment a completed bar's close reaches one of the two fixed-percentage bands, with no second signal and no requirement that price already be turning back, then manages its Stop Loss, Take Profit, and position size automatically with the same risk stack used by every other EA on this site.

How the Strategy Works

Envelopes plots two bands a fixed percentage above and below a moving average — this EA runs the calculation with a 20-period moving average (MAPeriod), a Simple Moving Average method (MAMethod), no forward or backward shift (MAShift), applied to the Close price (AppliedPrice), and a Deviation of 0.1%, meaning the upper band sits 0.1% above the moving average and the lower band sits 0.1% below it. On every newly completed bar, the EA compares that bar's close against both bands: if the close sits at or below the lower band, it reads that as price having stretched further below its average than the deviation setting normally allows, and opens a BUY expecting a snap back toward the average. If the close sits at or above the upper band, it opens a SELL on the mirrored logic.

The detail worth pausing on is what this EA does not wait for. The site's RSI reversal EA only fires once RSI crosses back out of an extreme zone — the touch itself isn't enough, the EA waits for evidence the move has already started to unwind. This EA does the opposite: the band touch itself is the entire signal. It doesn't check whether the next bar closed back inside the bands, and it doesn't require a rejection candle or any other confirmation that the stretch is over. That makes it structurally simpler and faster to react — it can catch the very first bar of a genuine reversal, before a confirmation-based system would even have a signal yet — but it also means it has no built-in defense against a close that keeps closing beyond the band bar after bar, which the "Word of Caution" section below covers in detail.

Stop Loss, Take Profit, and Position Sizing

BUYTake Profit (TP)Stop Loss (SL)Upper / Lower envelope
Entry conditions: BUY when price closes at or below the lower band — SELL when price closes at or above the upper band — SL and TP are placed automatically from ATR

Stop Loss is sized from ATR rather than a fixed pip distance: SL distance = ATR (14-period, ATRPeriod) × ATRMultiplier (default 2.0). A volatile pair or session automatically gets a wider stop, and a calm one gets a tighter stop, so the stop always reflects current market conditions rather than an arbitrary constant that's too tight on some pairs and too loose on others. Take Profit is then set as a multiple of that same Stop Loss distance — TP distance = SL distance × RiskRewardRatio (default 2.0) — keeping every trade's risk and reward in a fixed, known proportion regardless of how wide or narrow the ATR-based stop happens to be on a given entry.

Position size is calculated with the exact worked-example method from Risk Management Basics: RiskPercent of account balance (default 1.0%) divided by the Stop Loss distance, converted through the symbol's tick value and normalized to the broker's minimum lot, maximum lot, and lot step. A wider ATR-based stop produces a smaller lot size, and a tighter stop produces a larger one, so the dollar risk per trade stays roughly consistent even though the stop distance itself changes from trade to trade. A UseFixedLot input paired with FixedLotSize is available as an escape hatch for traders who'd rather trade a constant lot size and ignore the risk-based calculation entirely.

Entry Conditions

  • BUY — the most recently completed bar's close is at or below the lower Envelopes band.
  • SELL — the most recently completed bar's close is at or above the upper Envelopes band.

Three safety mechanics sit underneath that signal. The EA evaluates entry conditions once per new bar only, tracked against the timestamp of the current bar's open, never on every incoming tick — without this, a close that stays beyond the band for several ticks in a row could otherwise trigger the same signal repeatedly within one candle. It opens one position at a time, counting existing positions filtered by symbol and its own magic number before considering any new entry, so it never pyramids into the same setup. Every order it places is tagged with MagicNumber (default 20260725), so its position-counting and management logic never touches trades opened manually or by a different EA on the same account. Before opening anything, it also checks the current spread against MaxSpreadPoints (default 30) and skips the entry entirely if the market is too illiquid at that moment.

Parameters

  • MAPeriod (default 20) — the moving average period the Envelopes bands are centered on; shorter periods make the centerline (and therefore the bands) more reactive to recent price.
  • MAMethod (default SMA) — the moving average calculation method used for the centerline.
  • MAShift (default 0) — forward/backward shift applied to the moving average; left at 0 for a centerline that sits directly under the current bars.
  • AppliedPrice (default Close) — which price series feeds the moving average calculation.
  • Deviation (default 0.1) — the fixed percentage the upper and lower bands sit above and below the moving average.
  • ATRPeriod (default 14) — the lookback period used to calculate ATR for the Stop Loss distance.
  • ATRMultiplier (default 2.0) — Stop Loss distance = ATR × this multiplier.
  • RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance × this ratio.
  • RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size against the ATR-based Stop Loss distance. Ignored if UseFixedLot is enabled.
  • UseFixedLot (default false) — when enabled, trades a constant lot size instead of calculating one from RiskPercent.
  • FixedLotSize (default 0.01) — the lot size used when UseFixedLot is enabled.
  • MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, the same concern covered in Spread and Slippage.
  • EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.
  • MagicNumber (default 20260725) — tags every order this EA places so its position-counting and management logic never touches trades opened manually or by a different EA.

Fixed-Percentage Bands vs. Standard-Deviation Bands: What It Means for This EA

The site's own Envelopes lesson explains the core mechanical difference between Envelopes and Bollinger Bands: Bollinger Bands widen and narrow automatically with volatility because they're built from standard deviation, while Envelopes bands stay a constant percentage from the moving average no matter what the market is doing. For a manual trader that's mostly a matter of taste. For an automated EA, it has a concrete, practical consequence worth spelling out.

Because the 0.1% offset never changes on its own, how often this EA's entry condition fires is entirely a function of how volatile the market currently is relative to that fixed number. During a quiet week, price may barely stretch 0.1% away from its 20-period average, so the EA sits idle for long stretches. During a genuinely volatile week — a news event, a session overlap, a breakout — price can blow through 0.1% repeatedly within a short span, and the EA can end up opening several trades in quick succession, right at the moment spreads are typically widest and price is least predictable. A hypothetical version of this EA built on Bollinger Bands instead would see its band width expand alongside that same volatility spike, which would keep the touch frequency more stable across calm and chaotic conditions, even though the ATR-based Stop Loss already adapts to volatility either way. That's the tradeoff this EA accepts in exchange for a simpler, more transparent band calculation: the entry signal itself doesn't self-adjust, only the risk management around it does — which is exactly why the Deviation input exists as something worth revisiting per pair and per timeframe rather than leaving at its default everywhere.

Installation and Setup

EAs install into a different folder than indicators — this is the step people miss most often.

  1. Download the file below for your platform.
  2. Open MetaTrader → click FileOpen Data Folder.
  3. Place the file in MQL4/Experts (MetaTrader 4) or MQL5/Experts (MetaTrader 5) — not the Indicators folder.
  4. Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
  5. Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA will not place any trades while this is off, even if it's attached to a chart.
  6. Review and adjust the input parameters in the EA's settings dialog before confirming.

A Word of Caution

Test on a demo account first, across different market conditions, before risking real money — past performance, in backtests or live, never guarantees future results. No strategy, automated or manual, wins every trade, and this EA can and will lose money on individual trades. Because it enters on the band touch itself rather than waiting for a confirmed bounce, it is especially exposed to strong trending or breakout markets: price can close beyond a band and simply keep going, riding along or outside that band for many bars in a row without ever reverting toward the moving average, and each fresh close beyond the band can look — mechanically — exactly like the setup the EA is designed to trade. There is no trend-strength or momentum filter built in to sit those periods out. Consider pairing it with a read of trend vs range or an ADX filter before enabling it on a live account, and favor pairs or sessions where price genuinely oscillates rather than trends persistently. Both files are source code — open and review them fully, and understand what every parameter does, before using it. This content is general education, not personalized investment advice.

Download the EA

How to Install — MetaTrader 4

  1. Download the envelopes-reversal-ea.mq4 file below.
  2. Open MetaTrader 4 → click FileOpen Data Folder.
  3. Place the file in the MQL4/Experts folder.
  4. Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.

How to Install — MetaTrader 5

  1. Download the envelopes-reversal-ea.mq5 file below.
  2. Open MetaTrader 5 → click FileOpen Data Folder.
  3. Place the file in the MQL5/Experts folder.
  4. Restart MetaTrader 5, then drag the EA from the Navigator window onto the chart.

Both files are source code — open and review the full code before using it, for your own safety.

Download envelopes-reversal-ea.mq4

For MetaTrader 4 — this is source code (.mq4), open and review it fully before using it.

Download File

Download envelopes-reversal-ea.mq5

For MetaTrader 5 — this is source code (.mq5), open and review it fully before using it.

Download File