Envelope Fade EA
A trending market makes price "walk the band" - close after close pinned against the outer envelope while the moving average underneath keeps climbing or falling with it. Fading the very first touch trades straight into that walk and loses repeatedly during any real trend. This implementation requires one more step: the prior bar has to have closed outside the band, and the current bar has to close back inside it, before a fade is taken. That confirms rejection rather than guessing that a touch is automatically a reversal. Stop loss and take profit are fixed pip distances, converted to points per symbol from the broker's own digit count. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the stop distance, using the symbol's tick value and tick size rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - The re-entry confirmation reduces, but does not remove, the risk of fading a genuine trend - a strong move can briefly close back inside the band and then resume outward. - Envelope width is a fixed percentage of the moving average, not volatility-adjusted, so the same setting behaves differently in calm and turbulent conditions - review it per symbol. - Signals are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Requires AutoTrading enabled and trading permitted at the terminal, account and program level; if trading is disabled the EA logs it and skips the entry. - On MQL5 netting, opening the new fade after closing the opposite position is refused outright if a foreign-magic position already sits on the symbol, rather than risk merging into it.
Expert advisor · MT4 · v1.0 · Free
About Envelope Fade EA
Envelope Fade EA is an expert advisor (trading robot) for MetaTrader 4 based on Channels & Envelopes. It can size trades from your balance and risk percent. It has 11 settings, such as Ma period, Deviation percent and Stop loss pips. MQL source code included.
Files in the download: EnvelopeFadeEa.ex4, EnvelopeFadeEa.mq4, EnvelopeFadeEa.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Ma period | 20 | Envelope basis moving average period |
| Deviation percent | 0.2 | Envelope band width, percent of the basis |
| Stop loss pips | 40 | Stop loss distance, in pips |
| Take profit pips | 60 | Take profit distance, in pips (0 = none) |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260702 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Moving Average · Channels & Envelopes · Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code