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
| Setting | Default | What it does |
|---|---|---|
| Standalone mode | false | true = this EA gates and sends its own orders; false = publish-only |
| Tolerance multiplier | 1.3 | Spread counted "normal" when <= hourly average x this |
| Ema period | 20 | Smoothing period (in samples) for each hour's running average |
| Min samples before trust | 10 | Samples needed in an hour bucket before trusting its average |
| Fallback normal spread | 20.0 | Points treated as "normal" until an hour has enough samples |
| Max wait minutes | 30 | Give up waiting for normal spread after this long |
| Force after timeout | true | true = send anyway at timeout; false = cancel the armed request |
| Lots | 0.10 | Lots for the standalone demo order |
| Magic number | 24600 | Magic number that tells this EA's orders apart |
| Stop loss pips | 20 | 0 = no stop |
| Take profit pips | 40 | 0 = no target |
| Max retries | 5 | |
| Retry wait ms | 500 | |
| Timer interval sec | 5 |
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 · Trading Sessions · Martingale · MT4 Expert Advisor · MQL4 Source Code