Market Data Fuzzer
Every indicator or EA helper that processes Close[], a CopyRates() array or a Bid/Ask pair is implicitly trusting the feed: price is positive, ask is at or above bid, and consecutive bars do not jump by an unreasonable multiple of the normal range. Real broker feeds violate every one of those assumptions occasionally - a genuine bad tick, a feed-aggregation glitch producing a crossed book, a reconnect-after-outage gap, a thin-liquidity session open - and code tested only against clean historical data has never actually been exercised against any of them. This header generates the four failure shapes that matter in practice: NaN-adjacent - a genuine IEEE-754 NaN (via MathSqrt of a negative number, which MQL4's double arithmetic propagates rather than trapping), planted in a rotating field across the sequence so a handler that only checks one field is still exposed. Zero price - every price field 0.0, the shape a dead symbol or a pre-market gap in feed state produces, which breaks any calculation that divides by close or computes a percentage move. Negative spread - ask below bid, a physically impossible but real- world-observed crossed-book condition, which silently inverts the sign of a naive spread=ask-bid check meant to reject too-wide spreads. Huge gap - one bar-to-bar jump of a large configurable multiple of the normal step, in a random direction, simulating a flash move or a missed-bars reconnect. MQL4 has no function-pointer or generic-callback mechanism, so this header cannot "feed a sequence into a handler" as a single call the way the project brief's phrasing might suggest - there is no first- class way to pass an arbitrary function in MQL4. What it does instead, and what the demo shows, is generate the pathological sequence as data; the calling test code then runs it through its own handler in a plain loop, exactly as MarketDataFuzzerDemo.mq4 (or MarketDataFuzzerDemo.mq5 for the native MQL5 build) does with a NAIVE handler (no checks, to show what breaks) and a HARDENED one (validates first, to show the fix) side by side. Notes and limitations - No generic callback mechanism - MQL4 cannot pass a function pointer, so this header generates data only; wiring the generated sequence into your own handler is a plain loop you write, as the demo shows. - MathSqrt(-1.0) is used to produce a genuine NaN. This is confirmed behaviour in this MetaEditor build; if a future build changes double arithmetic to trap instead of propagate, the NaN-adjacent scenario would need revisiting - the other three scenarios do not depend on this and are unaffected either way. - The huge-gap scenario's direction is randomised with MathRand() and is not reseeded by this header - seed it yourself (MathSrand) before calling if a repeatable test run is needed. - These are synthetic, in-memory sequences only - nothing here talks to a real symbol, the terminal's history, or the Strategy Tester. Feed the generated arrays to your own handler function directly. - Not exhaustive: this covers four specific, commonly-missed failure shapes, not a general property-based fuzzer that explores arbitrary malformed input space.
Script · MT4 · v1.0 · Free
About Market Data Fuzzer
Market Data Fuzzer is a script for MetaTrader 4. It has 1 setting, such as Sequence length. MQL source code included.
Files in the download: MarketDataFuzzer.mqh, MarketDataFuzzer.txt, MarketDataFuzzerDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Sequence length | 20 | Number of bars/ticks generated per scenario |
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 → Scripts.
- 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 script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code