Mid Price Series Exporter
Every bar MetaTrader 4 stores is built from Bid, not from the midpoint between Bid and Ask. That is a real, systematic bias: a bid-only series sits consistently below where actual round-turn trade prices would sit, by roughly half the spread, and that bias is not constant across symbols or sessions since spread itself is not constant. Academic microstructure work, and any cross-broker or cross-symbol comparison, generally wants the midpoint series instead. This script rebuilds it, as far as MT4's data allows. For each of the most recent InpBars bars it writes both the original Bid OHLC and a mid OHLC - mid = bid + half the spread - to the same CSV row, so nothing is hidden or silently replaced. The honest limitation is that MetaTrader 4 keeps no per-bar spread history on either platform side - only the live spread at the instant the script runs is ever available. Every exported row therefore applies that ONE live reading as a constant offset, not each bar's true historical spread. This is stated in the log output and in the CSV's own half_spread_used_points column, rather than left for the reader to discover the hard way. Anyone who has their own historical spread figures for the period can override the live reading with InpAssumedSpreadPoints. Notes and limitations - The mid-price column is a constant-offset approximation, not a true historical mid series - MT4 keeps no historical spread on either side to reconstruct it exactly. This is stated in the CSV itself, not just the documentation. - Spread genuinely varies through a session (wider around rollover and news, tighter mid-session). A single live reading applied uniformly will understate the true offset on bars from a wide-spread period and overstate it on bars from a tight-spread period. - Exports whatever history is already loaded on the chart; if fewer bars than InpBars are available, the script exports what it has rather than failing. - Symbol digits (decimal places) come from MarketInfo(symbol, MODE_DIGITS) at run time, never assumed, so 3/5-digit and JPY-style symbols are handled correctly without special-casing.
Script · MT5 · v1.0 · Free
About Mid Price Series Exporter
Mid Price Series Exporter is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Timeframe, Bars and Assumed spread points. MQL source code included.
Files in the download: MidPriceSeriesExporter.ex5, MidPriceSeriesExporter.mq5, MidPriceSeriesExporter.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Timeframe | PERIOD_CURRENT | Timeframe to export |
| Bars | 500 | Number of most recent bars to export |
| Assumed spread points | 0 | Override spread, points (0 = use current live spread) |
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: Trading Sessions · Alerts · MT5 Script · MQL5 Source Code