Loading…

History To MT5 Import Format

MT4 keeps one history record per closed order, with the open and close price both on it. MT5 has no such record at all - it only has deals, one per fill, and a normal round-turn trade shows up in MT5's History tab as two separate deal rows: an entry deal and an exit deal, linked by a shared order/position number. A trader who reads reports from both platforms, or who feeds a history export into MT5-shaped tooling, keeps hitting the same friction: the MT4 export simply is not shaped like the thing the other side expects. This script reads the closed-order pool the way any MT4 export does, then writes two CSV rows per order - an "in" deal at the open price and an "out" deal at the close price - using the same column names MT5's own report uses: time, deal, symbol, type, direction, volume, price, order, commission, swap, profit, comment. The deal and order numbers are synthetic (this terminal has no real MT5 deal ledger to copy from), but the shape and the column names match, so the file drops straight into anything already built to expect MT5's report layout. Commission, swap and profit are booked entirely on the exit deal, which matches how most retail brokers settle a trade in practice. If your broker splits commission across both legs of a trade, the total per trade is still correct here, but the entry/exit split will not match your statement line for line - the .txt and the source header both say so plainly rather than implying an exact broker-for-broker match. Notes and limitations MT4 only exports what the Account History tab has already loaded into this terminal - if the row count looks short, right-click that tab, choose "All History", then run the script again. The script cannot see trades the terminal itself has not cached. The "Balance" column present in a real MT5 report is deliberately left out. A correct running balance needs the full deal ledger back to the account's funding, which this terminal's order-history cache does not carry - printing a fabricated balance figure would be worse than omitting the column. Deal and order id numbers are synthetic sequence numbers generated by this script, not real MT5 identifiers - they exist only to give each row the correct shape and to link the two rows of one trade together.

Script · MT4 · v1.0 · Free

About History To MT5 Import Format

History To MT5 Import Format is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as From date, To date and Delimiter. MQL source code included.

Files in the download: HistoryToMt5Format.mq4, HistoryToMt5Format.txt.

Settings

SettingDefaultWhat it does
From date0From close time (1970.01.01 = no lower bound)
To date0To close time (1970.01.01 = up to now)
DelimiterDelimiterCommaCSV column separator

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria