Loading…

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

SettingDefaultWhat it does
Min gap pips15Minimum open-vs-prior-close gap required to trade, in pips
Max gap pips200Sanity cap - gaps larger than this are skipped, not traded
Stop loss pips40Stop loss beyond entry, in pips
Entry window minutes30Minutes after the new day's open the EA still allows entry
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260813Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Price Action · Trading Sessions · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria