Stale Quote Execution Gate
A feed outage or a broker-side symbol freeze does not always drop the terminal connection. MarketInfo(symbol, MODE_TIME) can keep reporting the same timestamp for minutes while the terminal otherwise looks perfectly normal - no disconnect banner, no obvious sign anything is wrong. An EA that sends an order during that stretch is trading against a price that is no longer real. This EA tracks quote age for one or more watched symbols - MarketInfo's own last-quote-time minus the current server time - and closes a per-symbol "gate" the moment that age reaches a configured threshold, reopening it the moment fresh quotes resume. The gate state is published through a global variable per symbol (GlobalVariableSet), named by prefix + symbol, that any other EA's own trading logic can read before its own OrderSend call: treat a value of 1.0 as "fresh, order allowed" and 0.0 (or the variable simply not existing) as "stale, hold off." An optional self-test (off by default) demonstrates the mechanism directly: on a timer, it attempts a minimal-lot order on a chosen symbol only when that symbol's own gate is open, and skips with a logged reason when the gate is closed - proof the check genuinely blocks rather than just reporting a number nobody acts on. Notes and limitations The published gate is advisory - it does nothing on its own unless another EA's own order- sending code actually reads it. This EA cannot force a third-party strategy to respect it. Quote-age staleness detection depends entirely on MarketInfo(symbol, MODE_TIME) being reliable on your broker's feed; some brokers batch or delay quote timestamps in ways that could make a genuinely live feed look momentarily stale. Watch the Experts log for a period before relying on this in place of manual judgement. On OnDeinit, the published global variables are deleted rather than left at their last value, so a downstream EA reading a missing variable should treat that the same as "gate closed" - this is stated so nobody assumes a missing variable means "nothing wrong." The self-test, when enabled, sends and immediately closes a real minimal-lot order - spread and slippage cost real money on every attempt.
Expert advisor · MT4 · v1.0 · Free
About Stale Quote Execution Gate
Stale Quote Execution Gate is an expert advisor (trading robot) for MetaTrader 4. It has 9 settings, such as Watch symbols, Stale after seconds and Gate global var prefix. MQL source code included.
Files in the download: StaleQuoteExecutionGate.ex4, StaleQuoteExecutionGate.mq4, StaleQuoteExecutionGate.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 |
|---|---|---|
| Watch symbols | Comma-separated symbols to watch, "" = the attached chart's symbol only | |
| Stale after seconds | 20 | Quote age, seconds, at or beyond which the gate closes |
| Gate global var prefix | StaleQuoteGate_ | Global variable name prefix: prefix + symbol, 1.0 open / 0.0 closed |
| Alert on close | true | Pop a terminal Alert() the moment the gate closes for any watched symbol |
| Enable self test | false | Demonstrate the gate with a minimal-lot order attempt, off by default |
| Self test symbol | Symbol for the self-test order, "" = attached chart's symbol | |
| Self test every minutes | 30 | Minutes between self-test attempts when enabled |
| Self test magic number | 24105001 | Magic number that tells this EA's orders apart |
| Poll seconds | 2 | How often quote ages are re-checked |
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: MT4 Expert Advisor · MQL4 Source Code