Outcome Versus Recorded Spread Join
MT4 never stores the spread that was quoted at the moment a trade opened - OrderSelect() only ever exposes whatever the live spread is right now. Reconstructing entry spread from tick history is unreliable across brokers and tick-data availability, so this script does not attempt it. Instead it joins closed trades against a spread log the trader (or a separate recording tool) kept independently, matching each trade to the nearest-in-time log row for its symbol within a configurable window, then buckets the results by spread and reports win rate and average net result per bucket. The spread log is a plain CSV file read from the sandboxed MQL4\Files folder, in the format: timestamp,symbol,spread_pips 2024.01.15 09:03:00,EURUSD,1.2 2024.01.15 09:03:05,EURUSD,1.4 The timestamp uses the same "YYYY.MM.DD HH:MM:SS" format StrToTime() accepts, and spread_pips is a plain decimal number of pips already converted from raw points - not the raw MODE_SPREAD integer. Producing this file is left to the trader: a simple EA or script that samples MarketInfo(symbol, MODE_SPREAD) on a timer and appends a CSV row is enough, and keeps the recording concern separate from the reporting concern this script handles. A trade with no log row inside the matching window is counted and reported as unmatched rather than silently dropped, so a report is never mistaken for covering more of history than it actually does. Notes and limitations Report quality depends entirely on how completely and how frequently the spread log was recorded - a sparse log widens the effective match window in practice even though InpMaxMatchSeconds stays fixed. The join is nearest-in-time, not exact; two log rows equally close in time to a trade are resolved by whichever is scanned first at an exact tie, which does not occur for a log sampled on a regular timer. This script only reads the log; it does not record one.
Script · MT4 · v1.0 · Free
About Outcome Versus Recorded Spread Join
Outcome Versus Recorded Spread Join is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Spread log file, Symbol filter and Magic filter. MQL source code included.
Files in the download: OutcomeVersusSpreadJoin.mq4, OutcomeVersusSpreadJoin.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Spread log file | SpreadLog.csv | Spread log filename, read from MQL4\Files |
| Symbol filter | Symbol filter ("" = every symbol) | |
| Magic filter | -1 | Magic number filter (-1 = every magic) |
| From date | 0 | Earliest open time (0 = all loaded history) |
| To date | 0 | Latest open time (0 = up to now) |
| Max match seconds | 300 | Max seconds between trade open and a log row to accept a match |
| Bucket width pips | 1.0 | Width of each spread bucket, in pips |
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: Alerts · MT4 Script · MQL4 Source Code