If you've ever needed to pull your trade history out of MetaTrader 5 for tax filing, journal analysis, or a custom performance dashboard, you've probably hit the wall of the built‑in export function. It gives you a fixed set of columns – no way to add something like a custom profit factor, a trade's R‑multiple, or the time zone you're in. You can work around it, but it takes a few tricks. This guide covers exactly how to export MT5 trade reports, customize the fields you actually need, and even automate the whole process with a small MQL5 script so you never have to click "Export" manually again. I'll walk through the standard export path first, then show you how to extend it, and finally give you a ready‑to‑use automation script that handles edge cases like partial closes and swaps.
What You'll Learn and Why It Matters
By the end of this article you will be able to:
- Export your full trade history from MT5 using the built‑in tool.
- Customize which fields appear in your exported CSV or HTML report.
- Write a simple MQL5 script to export trades automatically on a schedule.
- Avoid common pitfalls like missing orders, wrong time frames, and encoding issues.
Traders who keep a proper trade journal consistently outperform those who don't. But manual copy‑pasting from the terminal is error‑prone and slow. Automating the export gives you clean, timestamped data you can feed into Excel, Google Sheets, or a dedicated journaling tool. It's one of those "set it and forget it" improvements that saves you hours each month. I've seen traders spend 20 minutes every Friday manually copying trade data – that's 16 hours a year you could spend on actual analysis.
Prerequisites
Before we start, make sure you have:
- MetaTrader 5 installed (version 4000 or later – check via Help > About). The steps are identical for MT4, but the menu text differs slightly (MT4 calls it "Account History").
- A live or demo account with at least a few closed trades in the history. If your account is brand new, place a couple of demo trades first.
- MetaEditor (comes with MT5) – you'll need it for the automation script. It's usually in Tools > MetaQuotes Language Editor or under
%ProgramFiles%\MetaTrader 5\MetaEditor.exe. - Basic familiarity with the Navigator panel and the Toolbox (where the Journal and Trade tabs live).
No programming experience is strictly required for the first half of this guide. The automation section assumes you can copy‑paste code and compile it – I'll explain every step so you know what's happening under the hood.
Step‑by‑Step: Exporting a Standard MT5 Trade Report
Let's start with the built‑in export. This works for any account type and doesn't require any custom code. Most traders use this method at least once before realizing they need more control.
Step 1: Open the Account History Tab
In MT5, press Ctrl+T to open the Toolbox at the bottom. Click the Trade tab, then the History sub‑tab. You'll see a list of all closed trades for the currently selected account. If the list is empty, right‑click inside the History tab and choose Custom Period… – set a date range that covers your trades. I usually set it to "All History" to avoid missing anything, but you can narrow it down to a specific month.
Step 2: Select Trades to Export
You can export the entire visible history or a subset. Hold Ctrl and click individual trades, or press Ctrl+A to select all. Right‑click on any selected trade and choose Save as Report. A dialog titled Save Report appears. One thing that trips people up: if you have pending orders in your history, those won't be selected unless you specifically include them – the default filter only shows closed positions. To include pending orders, right‑click the History tab header and check Show All Orders before selecting.
Step 3: Choose Format and Destination
In the Save Report dialog:
- File name: give it a descriptive name like "2025‑03‑MonthlyReport".
- Save as type: choose Report (*.htm) for a readable HTML file, or CSV (*.csv) if you plan to import into Excel or a database. CSV is better for automation – we'll use it later.
- Open in browser: leave unchecked unless you want to view it immediately.
Click Save. MT5 generates the file and places it in your Terminal\Reports folder by default. You can find that folder quickly by going to File > Open Data Folder > Reports. On Windows, that's typically C:\Users\YourName\AppData\Roaming\MetaQuotes\Terminal\InstanceID\Reports.
What You Get in the Default Export
Open the CSV in a text editor or Excel. You'll see columns like:
| Column | Description | Notes |
|---|---|---|
| Ticket | Unique order ID | Useful for cross‑referencing with broker statements |
| Open Time | Trade open timestamp (server time) | Always UTC+0 in MT5; adjust for your local time zone |
| Type | Buy / Sell | — |
| Volume | Trade size in lots | — |
| Symbol | Instrument traded | — |
| Price | Open price | — |
| SL / TP | Stop Loss / Take Profit levels | Empty if not set; MT5 stores them as 0 |
| Profit | Net profit in account currency | Includes swap and commission |
| Close Time | Trade close timestamp | — |
| Comment | User‑defined note | Often empty; can be set via EA or manual entry |
That's the complete set of fields MT5 gives you out of the box. Notice there's no R‑Multiple, Position Size in Units, Time in Trade, or Custom Tag. If you need those, you have to build them yourself – which is exactly what we'll do next.
Customizing Export Fields with MQL5
The built‑in exporter is rigid, but MT5 gives you full programmatic access to the order history via MQL5. You can write a script that reads every closed trade, computes whatever metrics you want, and writes the result to a CSV file with your own column headers. This is where the real power lies – you're not limited to what MT5's UI offers.
Creating a Custom Trade Export Script
- Open MetaEditor (Tools > MetaQuotes Language Editor or press F4).
- Click File > New > Script, name it
CustomTradeExport, and click Create. - Replace the default code with the following:
//+------------------------------------------------------------------+
//| CustomTradeExport.mq5 |
//| Generated for tradingbotmaker.com |
//+------------------------------------------------------------------+
#property copyright "tradingbotmaker.com"
#property version "1.00"
#property script_show_inputs
input string ExportFileName = "CustomTradeReport.csv"; // Output file name
input bool IncludeHeader = true; // Write column headers
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
string folder = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Files\\";
string filePath = folder + ExportFileName;
int handle = FileOpen(filePath, FILE_WRITE|FILE_CSV|FILE_ANSI, ",");
if(handle == INVALID_HANDLE)
{
Print("Failed to open file: ", filePath, " error ", GetLastError());
return;
}
// --- Custom column headers ---
if(IncludeHeader)
{
string header = "Ticket,Open Time,Close Time,Symbol,Type,Volume,Open Price,"
"Close Price,Stop Loss,Take Profit,Profit (USD),Swap,"
"Commission,R-Multiple,Time In Hours";
FileWrite(handle, header);
}
// --- Iterate through all closed trades ---
HistorySelect(0, TimeCurrent()); // from start of time to now
int total = HistoryDealsTotal();
for(int i = 0; i < total; i++)
{
ulong ticket = HistoryDealGetTicket(i);
if(ticket == 0) continue;
// Basic fields
string symbol = HistoryDealGetString(ticket, DEAL_SYMBOL);
double volume = HistoryDealGetDouble(ticket, DEAL_VOLUME);
double price = HistoryDealGetDouble(ticket, DEAL_PRICE);
double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);
double swap = HistoryDealGetDouble(ticket, DEAL_SWAP);
double commission = HistoryDealGetDouble(ticket, DEAL_COMMISSION);
double sl = HistoryDealGetDouble(ticket, DEAL_SL);
double tp = HistoryDealGetDouble(ticket, DEAL_TP);
long type = HistoryDealGetInteger(t





