Engineering note · Trade history imports
Import MT4 History into Excel Without Losing the Evidence
An MT4 history import is ready for analysis when every included row can be traced back to its export and the totals reconcile. A searchable spreadsheet is useful, but it can still omit a month, count the same trade twice or treat a deposit as trading profit. Check those boundaries before ranking currency pairs.
- 01Freeze the export
- 02Keep row identity
- 03Reconcile totals
- 04Then compare pairs
Start with a defined export, not a screenshot
In the MT4 Account History tab, select All History or a documented custom period before saving the HTML report. The official help explains that the period filter uses closing time. An export of recently closed trades therefore answers a different question from an export of trades opened during the same dates. Write down which population you intend to analyse.
Keep the original report unchanged. Give the imported data a source-file field and record when the export was made. Use a local account alias rather than spreading account identifiers across working copies. The analysis needs reliable separation between accounts, not login credentials.
Before importing every account, inspect one representative file in Excel. Depending on the Excel version, use the available HTML or data-import route, or convert the table with a reviewed importer. Check the preview rather than assuming the first detected table contains only closed trades. A report can contain separate sections for closed transactions, open trades and working orders.
Decide what one row means
Use one row per exported trade record and retain the original ticket as text. Pair it with the account alias. A ticket alone is not a sensible cross-account identity. Keep the source row number as a separate audit field so a reviewer can find the exact line without guessing from the profit value.
Classify records before creating a pivot table. Closed buy and sell records belong in the trading-results view. Deposits, withdrawals and other balance movements need their own category. Open positions belong in a separate snapshot. Mixing these categories produces a plausible total with the wrong meaning.
Do not silently discard a row because it looks unusual. Keep an exceptions sheet with the source, reason and unresolved field. Partial closures and broker-specific comments deserve review against the actual export. Do not invent a parent-trade relationship that the source does not establish.
- Identity: account alias, original ticket, source file and source row.
- Context: broker/server label, account currency, symbol and record type.
- Time: original open/close text plus the explicitly chosen parsed time convention.
- Values: lots, prices, profit, commission, swap and any separately reported charges.
Parse time and money explicitly
A timestamp without a timezone is not a UTC timestamp. Preserve the original text and document the broker-time assumption. If you later compare sessions between accounts, require an evidenced conversion rule. Do not guess daylight-saving changes from the reader’s computer clock.
Check decimal separators, negative signs and empty cells before making the columns numeric. An empty commission cell is not automatically evidence of zero commission. Mark missing data explicitly and explain whether it prevents a complete reconciliation.
Keep original symbols alongside any reporting group. A suffix can identify a different broker instrument or account setup. Map symbols with an explicit lookup that a reviewer can inspect. Unmapped symbols should remain visible instead of disappearing from the summary.
Reconcile before asking which pair performed best
First compare included record counts and date boundaries with the retained export. Then compare monetary totals for the same account, currency and population. Keep trade profit and charges separately visible. MQL4 OrderProfit returns the selected order’s profit without swap or commission; an importer using that function must handle those fields separately. Do not subtract charges twice from a report field that already includes them.
Treat a difference as a finding to explain. Common checks include duplicated imports, missing periods, open records mixed with closed ones and an incorrect interpretation of charge signs. Keep the exception beside the total. Hiding it behind a rounded chart label makes the workbook harder to trust.
Only then create a pair-level view. Show the account, currency, observation period and number of included trades alongside the result. Accounts with different deposit currencies cannot be added into one currency total without an explicit conversion policy. A comparison of past records is not evidence that the best-looking pair will keep performing that way.
Make refreshes reviewable
Keep raw input, cleaned records, exceptions and presentation on separate sheets or queries. The refresh procedure should say whether a file replaces a previous snapshot or extends it. For overlapping exports, use a documented duplicate rule based on the account and trade identity, then check for conflicting versions of the same record.
A useful handoff includes the untouched sample export, field mapping, refresh instructions and expected results for the three checks below. These are proposed acceptance tests. They have not been run against a customer account here. The scope is a reliable history import, not live-account operation, tax reporting or a recommendation about what to trade.
Three acceptance checks
Proposed tests, not executed customer results. Record actual outcomes separately.
Known complete export
Input: Import a reviewed account report for one frozen period.
Expected: Every included trade traces to one source row; counts and same-currency totals reconcile, with all excluded categories listed.
Overlapping refresh
Input: Import the same file again, then another file with overlapping history.
Expected: Previously imported records are not counted twice. Changed versions are flagged under the documented conflict rule.
Malformed input
Input: Supply a row with an invalid timestamp, missing currency or unresolved numeric format.
Expected: The row appears in exceptions with its source reference. The summary visibly reports that reconciliation is incomplete.
Sources and related guides
- MetaTrader 4: Account History and report export
- MQL4: loaded history and OrdersHistoryTotal
- MQL4: what OrderProfit includes
- Write acceptance criteria before code
- Compare broker environments
For your own brief, write the starting state, expected behavior and evidence for each case. The free Bot Blueprint gives you a place to collect those requirements.