Spread Injection Into History
The Strategy Tester, by default, charges one fixed spread on every trade for the whole run. Real spread is never flat. It widens in thin overnight hours, it widens sharply around rollover when liquidity providers step back, and it can spike on news regardless of the time of day. A strategy that trades often and was only ever tested at a cheap fixed spread can look profitable in the report and lose to costs the report never modelled. This script does not attempt to replay a real historical spread feed - very few brokers publish one, and importing tick-level bid/ask history is a different job. Instead it takes an OHLC CSV already exported from this catalogue's own export tools (or anything sharing the same six-column shape) and layers a documented, adjustable spread model onto it: a baseline spread in points, multiplied up during a configurable quiet session and again during a configurable rollover hour, with a small random jitter added so the series is not perfectly flat even within one session. Every choice is a plain input, so the model can be tuned to what a specific broker actually does rather than trusting a single assumed number. The output keeps every original column and adds two: the spread applied to that bar, in points, and an ask-side close computed from it. Feeding that into whatever cost-aware backtest or spreadsheet analysis you run outside the tester gives a considerably more honest picture of what a spread- sensitive strategy would have actually paid. Notes and limitations - The spread model is a documented approximation built from three adjustable multipliers and a jitter term, not a replay of any specific broker's real historical spread. Treat the output as "a more honest assumption" rather than "what actually happened". - Only the ask side is added. If your downstream analysis also needs a distinct bid series, the source close already serves as the bid. - Rows whose time column does not parse as a 19-character "YYYY-MM-DD HH:MM:SS" timestamp (the shape this catalogue's own exports use) are skipped and counted, not guessed at. - Column splitting is a plain delimiter split. A source field that itself contains the delimiter would be misread; this catalogue's own CSV exports never produce one. - Rollover time varies by broker and by symbol (triple-swap days shift it further still); InpRolloverHour is a single fixed hour and does not model that variation.
Script · MT4 · v1.0 · Free
About Spread Injection Into History
Spread Injection Into History is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 12 settings, such as Input filename, Delimiter and Reference symbol. MQL source code included.
Files in the download: SpreadInjectionIntoHistory.ex4, SpreadInjectionIntoHistory.mq4, SpreadInjectionIntoHistory.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Input filename | Source OHLC CSV (time,open,high,low,close,tick_volume), in MQL4\Files | |
| Delimiter | DelimiterComma | Delimiter used by both the source and the output |
| Reference symbol | Symbol whose point size/digits are used ("" = this chart's symbol) | |
| Base spread points | 20.0 | Baseline spread, in points, during normal hours |
| Quiet hour start | 22 | Quiet session start hour, server time (0-23) |
| Quiet hour end | 2 | Quiet session end hour, server time (0-23, exclusive) |
| Quiet session multiplier | 2.0 | Spread multiplier during the quiet session |
| Rollover hour | 23 | Server hour when rollover widening is applied |
| Rollover multiplier | 3.0 | Spread multiplier during the rollover hour |
| Random jitter points | 3.0 | Random +/- jitter added to every bar's spread |
| Min spread points | 5.0 | Floor - spread never reported below this |
| Random seed | 0 | 0 = a different jitter pattern every run |
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: News Trading · Alerts · MT4 Script · MQL4 Source Code