Loading…

Spread Aware Entry Timer

A single fixed "maximum acceptable spread" is wrong most of the time - too tight during a quiet Asian session, too loose right before London opens. This EA keeps a separate running average spread for each hour of the server day, smoothed with an exponential moving average per hour, so "normal" always means normal for right now, not normal in general. It works two ways, chosen with InpStandaloneMode. Left off (the default), it changes nothing about how orders are sent - it just publishes the current normal/abnormal state and the trusted hourly average through terminal global variables that another EA can poll before sending its own order. Turned on, two chart buttons let the trader arm a buy or sell directly; the order is held until the spread returns to normal for the current hour (or InpMaxWaitMinutes elapses, at which point it either sends anyway or cancels, depending on InpForceAfterTimeout), and once it fires the EA reports the spread at the moment of arming against the spread at the moment of the fill, in points, as a plain "saved" or "extra cost" figure. An hour's average is not trusted until it has accumulated InpMinSamplesBeforeTrust real samples; before that, a fixed fallback figure is used so the EA is not comparing against a single early observation. Notes and limitations - The hourly averages are learned from this chart's own observed spread over time; a freshly attached chart has no history, so the fallback figure governs every hour until enough samples accumulate. - "Normal for the hour" is relative to that hour's own recent history, not an absolute ceiling - a broker whose spreads have widened structurally across the board will see its own new baseline learned in as "normal" rather than flagged. - In standalone mode this EA sends a real market order once conditions are met; it is not a strategy, it has no entry signal of its own beyond the two chart buttons. - Statistics are stored in terminal global variables keyed by symbol; they are shared across every chart of that symbol on this terminal, and reset if the terminal's global variable pool is cleared.

Expert advisor · MT4 · v1.0 · Free

About Spread Aware Entry Timer

Spread Aware Entry Timer is an expert advisor (trading robot) for MetaTrader 4. It increases the lot size after a losing trade (martingale). It has 14 settings, such as Standalone mode, Tolerance multiplier and Ema period. MQL source code included.

Files in the download: SpreadAwareEntryTimer.ex4, SpreadAwareEntryTimer.mq4, SpreadAwareEntryTimer.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Standalone modefalsetrue = this EA gates and sends its own orders; false = publish-only
Tolerance multiplier1.3Spread counted "normal" when <= hourly average x this
Ema period20Smoothing period (in samples) for each hour's running average
Min samples before trust10Samples needed in an hour bucket before trusting its average
Fallback normal spread20.0Points treated as "normal" until an hour has enough samples
Max wait minutes30Give up waiting for normal spread after this long
Force after timeouttruetrue = send anyway at timeout; false = cancel the armed request
Lots0.10Lots for the standalone demo order
Magic number24600Magic number that tells this EA's orders apart
Stop loss pips200 = no stop
Take profit pips400 = no target
Max retries5
Retry wait ms500
Timer interval sec5

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Moving Average · Trading Sessions · Martingale · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria