Quote Sanity Validator
Every live feed occasionally hands the terminal a quote that should never be acted on. Bid at or above ask for an instant during a fast market. A spread blown out to ten times normal around a news release. A price that jumped an impossible distance in a single tick because a liquidity provider dropped out and came back stale. A feed that simply stops updating for a while without the terminal necessarily telling you loudly. Code that reads Bid and Ask straight off the terminal, computes a stop distance or a spread cost or a signal from whatever it sees, and never checks for any of this will eventually compute all three from a quote that was garbage. This header names each failure mode separately, checks for it independently, and combines the results into one bitmask so a caller gets more than a single opaque "quote rejected" - it gets exactly which rule tripped, which matters when you are trying to work out afterwards whether a bad fill was your strategy's fault or the feed's. Five checks are provided: non-positive price, a crossed book, a spread wider than a configured maximum, a price spike further than a configured maximum since the previous quote, and staleness beyond a configured number of seconds. QuoteValidatorDefaultConfig derives sane spread and spike thresholds from the symbol's own current spread rather than a fixed point count, because a threshold sized for a five-digit forex pair is either far too tight for a two-digit index CFD or far too loose to ever fire on a tight major - sizing off the symbol's current spread keeps the thresholds proportionate to whatever instrument is actually being watched. Notes and limitations - The spike check needs a previous price to compare against; pass a previousBid of 0 or less on the very first call and it is skipped, never scored as a spike. - A genuinely broken quote (for example a flat 0.0 bid and ask) can and will trip several checks at once - QuoteFaultsToString lists every one of them, it does not stop at the first match. The demo's final row shows this. - Default thresholds are a starting point, not a guarantee. A symbol with unusually erratic normal spread behaviour (thin exotics, some indices around the open) may need maxSpreadPoints and maxSpikePoints widened by hand rather than relying on the automatic defaults. - Staleness is judged purely by elapsed time between quoteTime and nowTime as the caller supplies them; the header has no independent notion of what a broker's normal tick cadence should be. - Pure computation, no chart or trade calls beyond the one spread lookup in QuoteValidatorDefaultConfig - safe to call from a script, indicator or expert with no other side effects.
Script · MT5 · v1.0 · Free
About Quote Sanity Validator
Quote Sanity Validator is a script for MetaTrader 5. MQL source code included.
Files in the download: QuoteSanityValidator.mq5.mqh, QuoteSanityValidator.txt, QuoteSanityValidatorDemo.ex5, QuoteSanityValidatorDemo.mq5.
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: News Trading · MT5 Script · MQL5 Source Code