Robust Spike Fade System
A mean/standard-deviation spike filter is quietly self-defeating: one earlier large bar inflates the standard deviation, which raises the bar for what counts as "extreme" right when a real spike shows up. This EA instead measures the median and the median absolute deviation (MAD, scaled by 1.4826 for a normal-consistent estimate) of the last InpMadLookbackBars closed-bar returns. Median and MAD barely move when a handful of bars are extreme, so the current bar is judged against the window's typical behaviour rather than a threshold the spikes themselves have already corrupted. A bar qualifies as a spike only when its return is at least InpMadMultiplier MAD units from the median. A qualifying spike inside a declared news window (InpNewsWindows, a comma-separated list of HH:MM-HH:MM server-time ranges) is deliberately NOT faded - a genuine outlier during a scheduled release is exactly the kind of move that tends to keep running rather than revert, so trading it as a fade would be fighting the one case where the statistics are least likely to apply. Every trade is stopped just beyond the spike's own high or low and force-closed after InpMaxHoldingBars bars if it has not already resolved by stop or target - a fade that does not revert quickly is not the trade this system is designed to hold. Notes and limitations - News windows are a fixed, user-maintained schedule in server time, not a live economic calendar feed - they need updating as the broker's release schedule or server time offset changes. - The MAD threshold classifies the PREVIOUS closed bar's return; it cannot see intrabar detail on a lower timeframe, so a spike that formed and partly reverted within one bar on this chart's timeframe is measured only by that bar's net close-to-close return. - Only one position is held at a time; a second qualifying spike while already in a trade is ignored until the current one closes. - This fades the move; it carries the risk of any counter-trend entry during a genuine regime change that a MAD filter cannot distinguish from a temporary outlier in advance.
Expert advisor · MT5 · v1.0 · Free
About Robust Spike Fade System
Robust Spike Fade System is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It increases the lot size after a losing trade (martingale), can size trades from your balance and risk percent and has a news filter. It has 12 settings, such as Mad lookback bars, Mad multiplier and Atr period. MQL source code included.
Files in the download: RobustSpikeFadeSystem.ex5, RobustSpikeFadeSystem.mq5, RobustSpikeFadeSystem.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 |
|---|---|---|
| Mad lookback bars | 60 | Bars used to measure the median and MAD of bar returns |
| Mad multiplier | 4.0 | A bar qualifies as a spike when |return - median| exceeds this many MAD units |
| Atr period | 14 | ATR period, used for the stop distance |
| Stop atr multiple | 1.5 | Stop beyond the spike extreme, in ATR multiples |
| Take atr multiple | 2.0 | Take-profit distance, in ATR multiples (0 = none, time exit only) |
| Max holding bars | 12 | Force-close a fade if it has not resolved within this many bars |
| News windows | 08:25-08:35,12:25-12:35,14:25-14:35 | Comma-separated HH:MM-HH:MM server-time windows to avoid, blank = none |
| Risk percent | 0.75 | Risk per trade, percent of equity |
| Magic number | 20260905 | 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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: News Trading · Martingale · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code