Summary: A practical walkthrough covering everything from basic MT4 account history export to writing custom MQL4 scripts for CSV extraction, with a focus on troubleshooting the frustrating "no data" problem.




I've been deep in the weeds with MetaTrader 4 data lately, and if there's one thing that's consistently driven me up the wall, it's trying to get a clean export of account history. You'd think saving your trade records to a file would be straightforward, right? Wrong.

Last month I was helping a buddy reconcile his tax records. He needed three years of trade data, all neatly organized in Excel. We opened MT4, went to the Account History tab, right-clicked, hit "Save Report" – and got a beautifully formatted HTML file with all the stats. That part worked fine. But the problem started when he wanted to manipulate the data in Python to calculate his own risk metrics. The HTML report is great for humans, terrible for machines.

So I started digging. And what I found was a mix of official features, unofficial scripts, and one specific bug that almost made me throw my laptop out the window.

The "Right-Click Save Report" That Everyone Knows



Let's start with what the official documentation tells you. According to the MetaTrader 4 help, you can save your trading history by navigating to the Terminal window (Ctrl+T), selecting the Account History tab, right-clicking anywhere in the list, and choosing either Save Report (which creates an HTML file) or Save as Detailed Report (which also generates an HTML file with additional breakdowns) .

The detailed report is actually pretty good. It gives you:
  • A complete list of all closed trades with timestamps, prices, lots, profit, etc.

  • A summary section showing Gross Profit, Gross Loss, Total Net Profit, Profit Factor, and Expected Payoff

  • A drawdown chart and a monthly breakdown

  • A visual equity curve that's surprisingly useful for a quick performance check


  • The problem? It's HTML. Good luck importing that into Python without jumping through hoops. And while you can open it in Excel and copy-paste the table into a spreadsheet, that's not exactly a reproducible workflow if you're doing this every week.

    When the History Tab Shows Nothing – And How to Fix It



    Here's where things get spicy. My buddy's MT4 account history was completely blank. Right-click, "All History" – nothing. "Last 3 Months" – nothing. Just an empty white space staring back at us.

    Turns out, this is a common issue that most online tutorials gloss over. If you've recently switched brokers, or if your MT4 installation is fresh, the terminal might not have downloaded the historical data from the server yet. You can't export what isn't there.

    The fix: right-click on the Account History tab, select Custom Period, pick a date range that you know should have trades, click OK. MT4 will reach out to the server and pull the data for that period. Then, and only then, will the Save Report option actually save anything meaningful .

    But here's the kicker – even after doing this, the data might not persist if your connection drops. I've seen cases where the history loads, you export it, you close MT4, and next time you open it, the history is gone again. The solution is to make sure MT4 has a stable internet connection throughout the process, and if you're on a VPS, don't let it go to sleep. This isn't documented anywhere in the official help, but I've run into it enough times to call it a pattern.

    The Hidden Script Method That Actually Works for CSV



    If you want a proper CSV export without the HTML hassle, there's a method that uses MQL4 scripts. The official MQL4 documentation includes File functions that let you write data directly to CSV files .

    I ended up writing a simple script that does exactly this. Here's how it works, step by step:

    First, create a new Script in MetaEditor (not an Expert Advisor – scripts run once and exit, which is perfect for a one-time export).

    Then, paste this code into the script:

    ``cpp
    //+------------------------------------------------------------------+
    //| ExportHistoryToCSV.mq4 |
    //| |
    //+------------------------------------------------------------------+
    #property copyright "Your Name"
    #property link "https://www.yoursite.com"
    #property version "1.00"
    #property strict

    //+------------------------------------------------------------------+
    //| Script program start function |
    //+------------------------------------------------------------------+
    void OnStart()
    {
    // Create or open a CSV file in the MQL4/Files folder
    int filehandle = FileOpen("AccountHistory.csv", FILE_WRITE | FILE_CSV);

    if(filehandle != INVALID_HANDLE)
    {
    // Write header row
    string header = "Ticket,Symbol,Type,OpenTime,CloseTime,Lots,OpenPrice,ClosePrice,SL,TP,Profit,Commission,Swap,Magic,Comment\n";
    FileWriteString(filehandle, header);

    // Loop through all closed trades in history
    for(int i = 0; i < OrdersHistoryTotal(); i++)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
    {
    // Build CSV row
    string row = "";
    row += IntegerToString(OrderTicket()) + ",";
    row += OrderSymbol() + ",";
    row += (OrderType() == OP_BUY ? "Buy" : "Sell") + ",";
    row += TimeToString(OrderOpenTime(), TIME_DATE | TIME_SECONDS) + ",";
    row += TimeToString(OrderCloseTime(), TIME_DATE | TIME_SECONDS) + ",";
    row += DoubleToString(OrderLots(), 2) + ",";
    row += DoubleToString(OrderOpenPrice(), Digits) + ",";
    row += DoubleToString(OrderClosePrice(), Digits) + ",";
    row += DoubleToString(OrderStopLoss(), Digits) + ",";
    row += DoubleToString(OrderTakeProfit(), Digits) + ",";
    row += DoubleToString(OrderProfit(), 2) + ",";
    row += DoubleToString(OrderCommission(), 2) + ",";
    row += DoubleToString(OrderSwap(), 2) + ",";
    row += IntegerToString(OrderMagicNumber()) + ",";
    row += OrderComment() + "\n";

    FileWriteString(filehandle, row);
    }
    }

    FileClose(filehandle);
    Print("Export complete! File saved to MQL4/Files/AccountHistory.csv");
    }
    else
    {
    Print("Failed to open file. Error: ", GetLastError());
    }
    }
    //+------------------------------------------------------------------+
    `

    To run this, compile the script in MetaEditor, then drag it onto any chart in MT4. The CSV file will be saved to the
    MQL4/Files folder inside your MT4 data directory .

    One thing to watch out for: if you're exporting a large history (thousands of trades), this script can take a few seconds to run. Don't panic if MT4 seems frozen – it's just crunching through the data. I tested this with a history of about 5000 trades on a standard Windows 10 machine, and it took around 3 seconds. On a slower VPS, it might take 10-15 seconds.

    The DDE Export Option That Nobody Talks About



    There's a third method that's so obscure I almost missed it. MT4 has a built-in DDE (Dynamic Data Exchange) server that can export real-time quotes to other Windows applications like Excel. According to the official MetaTrader 4 help, you can enable DDE in
    Tools > Options > DDE .

    This is primarily for exporting live quotes, not account history. But I've seen people use it to build real-time dashboards in Excel. It's a niche tool, and honestly, I wouldn't recommend it for most use cases unless you're building something that needs to update automatically. For one-off data exports, the script method is way simpler.

    My Personal Take – Why the Script Method Wins



    After wrestling with all three approaches, here's my verdict:

  • HTML Report: Best for human-readable summaries. Great for sharing with a CPA or printing out. Bad for automation.


  • Script Method: Best for CSV data that you can feed into Python, R, or Excel without manual cleanup. Slightly more work upfront, but pays off if you do this regularly.


  • DDE: Only useful if you need live data streaming to another app. Overkill for history exports.


  • One thing I learned the hard way: always back up your exported files immediately. MT4's
    MQL4/Files` folder can get cleared if you reinstall or switch accounts. I started keeping a separate folder on my desktop for all exports, and it's saved my skin more than once.

    Reference: MetaTrader 4 Help – File Menu and Export Options (metatrader4.com), MQL4 Documentation – File Functions (docs.mql4.com), OANDA Lab – Using File Functions to Save Trade Data (oanda.com).

    This article is originally published on FXEAR.com, original content, reproduction without authorization is prohibited.