Detailed Trade History Exporter
A trade's net profit is not the "Profit" figure alone - swap and commission belong to the same trade and are routinely left out of simpler exporters, which understates or overstates the real result depending on the account. Magic number and comment are just as often dropped, which makes it impossible to later tell one EA's trades apart from another's, or from a manual click, once several strategies have shared the same account. This EA writes one CSV row per closed trade: ticket, symbol, type, lots, open/close time and price, stop-loss and take-profit, commission, swap, profit, a NetResult column that adds all three together, holding duration in minutes, magic number and the trade's comment. The file is rewritten from scratch on every export rather than appended to, so it always reflects the complete current history instead of accumulating duplicate rows across repeated runs. History is read forward, not backward, on both platforms - the "always iterate backwards" rule used everywhere else in this catalogue exists because closing an order re-indexes the live pool underneath a forward loop; reading closed history changes nothing in any pool, so there is nothing to re-index and that trap simply does not apply here. Notes and limitations - Only closed market trades are exported by default; enable InpIncludeCancelled to also capture pending orders that never filled. - The file is overwritten on every export, not appended - point external tooling at the latest file rather than expecting row history across runs. - Duration is measured from open time to close time in minutes and is always 0 for cancelled/expired pending orders, since they never held a position. - Depends on the terminal's local trade history; a history depth limited by the broker or the terminal's history settings will limit what is available to export. - Non-trade history entries (balance operations, credits, corrections, dividends and similar) are excluded on both platforms - MQL4's history pool never contained these either, so the row set stays equivalent.
Expert advisor · MT4 · v1.0 · Free
About Detailed Trade History Exporter
Detailed Trade History Exporter is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as File name, Magic filter and Include cancelled. MQL source code included.
Files in the download: DetailedTradeHistoryExporter.ex4, DetailedTradeHistoryExporter.mq4, DetailedTradeHistoryExporter.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| File name | DetailedTradeHistoryExporter.csv | Output file, written under MQL4\Files\ |
| Magic filter | 0 | Only export this magic number (0 = export every magic number) |
| Include cancelled | false | Include deleted/expired pending orders (no fill) in the export |
| Export interval minutes | 0 | Re-export automatically every N minutes (0 = only at start/removal) |
| Export on removal | true | Export once more when the EA is removed from the chart |
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: Alerts · MT4 Expert Advisor · MQL4 Source Code