Gap Fill EA
Overnight and weekend gaps happen because the market keeps moving while a particular feed or session is closed. A meaningful share of that distance is often retraced once trading resumes and the order book catches up with the missed price action, which is the basis for gap-fill trading: sell a gap up, buy a gap down, target the level price gapped away from. The gap is read from PERIOD_D1 open and close directly - iOpen for the new day, iClose(shift 1) for the prior day - so detection is correct regardless of the chart timeframe the EA is actually attached to, which matters because gap-fill entries are usually timed more precisely on an M15 or H1 chart than on D1 itself. Two thresholds do the real filtering. InpMinGapPips throws out gaps too small to clear the spread and the stop distance profitably. InpMaxGapPips throws out gaps large enough to be suspicious - a feed glitch, a single bad tick recorded as the day's open, or a genuine shock the size of which makes "it usually fills" far less reliable. Only one trade is attempted per gap, taken or not, and only within InpEntryWindowMinutes of the new day's open - a gap left unaddressed that long has likely already started resolving itself without the EA. Notes and limitations - Exactly one trade attempt per day, win, lose, or skip - the EA does not re-enter if the first attempt is stopped out before the gap fills. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Not every gap fills, and some fill only much later than any reasonable stop would survive. This is a documented statistical tendency, not a guaranteed outcome - size and stop distance should reflect that. - Requires at least one full prior daily bar of history to compute the gap; a freshly attached chart with no D1 history yet will not trade until that history is available. - Requires AutoTrading enabled; on MQL4 that is checked via IsTradeAllowed(), on MQL5 via TERMINAL_TRADE_ALLOWED plus ACCOUNT_TRADE_ALLOWED and ACCOUNT_TRADE_EXPERT. If trading is disabled the EA logs it and skips the entry.
Expert advisor · MT5 · v1.0 · Free
About Gap Fill EA
Gap Fill EA is an expert advisor (trading robot) for MetaTrader 5. It can size trades from your balance and risk percent. It has 11 settings, such as Min gap pips, Max gap pips and Stop loss pips. MQL source code included.
Files in the download: GapFillEa.ex5, GapFillEa.mq5, GapFillEa.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 |
|---|---|---|
| Min gap pips | 15 | Minimum open-vs-prior-close gap required to trade, in pips |
| Max gap pips | 200 | Sanity cap - gaps larger than this are skipped, not traded |
| Stop loss pips | 40 | Stop loss beyond entry, in pips |
| Entry window minutes | 30 | Minutes after the new day's open the EA still allows entry |
| 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 | 20260813 | 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: Price Action · Trading Sessions · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code