Loading…

Statement HTML Importer

MetaTrader's own "Save as Report" produces an HTML file, not a CSV, and that HTML has no class names or ids to key off - every section is a plain table of <tr><td> rows with no other markup hook. This script parses that exact layout: it finds the closed-trades table by its bold caption cell, whose text is "Closed Transactions:" in every standard MT4 statement this was checked against, then reads the header row immediately below the caption to work out which column is which by name (Ticket, Open Time, Type, Size, Item, Price, S / L, T / P, Close Time, Price, Commission, Taxes, Swap, Profit) rather than assuming a fixed column position. A broker whose statement template adds or reorders a column is still read correctly this way, instead of silently pulling the wrong cell into the wrong field. Reading stops at the first row whose leading cell is not a plain positive integer - the "Closed P/L:" totals row every statement carries directly after its last trade row. Since "Price" appears twice in the header (open price, then close price), the first occurrence after the Item column is treated as the open price and the next one as the close price, following their left-to-right document order rather than string-matching an ambiguous name. The output is one clean row per closed trade with the same fields the statement itself carried, ready to open in a spreadsheet or feed into another tool - no manual retyping, and no risk of a transcription error on a long statement. Notes and limitations - Depends on the standard MT4 statement HTML layout produced by "Save as Report" - a bold "Closed Transactions:" caption followed by a header row and then one row per closed trade, ending at the "Closed P/L:" totals row. A statement generated by a third-party reporting tool, or a heavily re-skinned broker template, may not match this layout and will be reported as unparseable rather than guessed at. - Only the closed-transactions table is parsed. Open positions and working (pending) orders, which appear in earlier tables of the same file, are not exported by this script. - Commission, taxes and swap columns are written as empty strings if the statement's header does not include them - some broker templates omit one or more of these columns entirely, and this script does not invent a value for a column that was never there. - Numeric and date fields are copied through as plain text exactly as the statement wrote them (locale-dependent date/number formatting included); this script does not reformat or reparse them.

Script · MT5 · v1.0 · Free

About Statement HTML Importer

Statement HTML Importer is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Statement file name and Output file name. MQL source code included.

Files in the download: StatementHtmlImporter.ex5, StatementHtmlImporter.mq5, StatementHtmlImporter.txt.

Settings

SettingDefaultWhat it does
Statement file namestatement.htmSaved MT5 statement, from MQL5\Files
Output file namestatement_closed_trades.csvClean CSV written on success

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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 · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria