Summary: Exporting MT4 account history for equity curve analysis requires more than the default save function. This tutorial provides a practical scripting solution to generate clean CSV data with timestamps and floating equity.




I've been keeping a detailed equity curve of my own trading for the past two years. Not the one MT4 shows you on the screen, but a proper one I can pull into Python or Excel to run my own drawdown and Sharpe ratio calculations. The default "Save as Report" function in MT4 gives you an HTML file, which is useless if you want to crunch numbers outside the terminal. And the "Account History" export via right-click only gives you the closed trades, not the floating equity at each point in time.

That's the gap. You can export closed P&L easily, but if you want to plot a proper equity curve that shows your account value fluctuating throughout the day including open positions, the default MT4 tools won't get you there. I ran into this wall about six months ago when I was trying to reconcile my monthly performance for a prop firm application. They wanted a time-stamped equity curve, not just a statement.

Here's the workaround I settled on after testing three different approaches. The first was using the built-in "Journal" export, but that's just text. The second was a third-party MT4 history exporter from the market, but it cost $49 and I figured this should be doable with a simple script. So I wrote my own.

The official MQL4 documentation covers the OrderSelect() and OrderHistorySelect() functions well enough. But what's not explicitly documented is the behavior of the AccountBalance() function when you're running it inside a script loop. If you call it too frequently, the terminal throttles the request. My exclusive insight here, after going through the forums and testing with a timer, is that adding a Sleep(50) between each loop iteration allows the terminal to return the correct balance without lagging the entire chart, especially during high-tick volatility. This isn't mentioned anywhere in the docs, but it's critical for getting accurate historical equity data.

The script approach I use:

  • Open the MetaEditor (F4) and create a new Script (not an EA).

  • Insert the following core logic:

  • - Loop through all historical orders using OrderHistorySelect().
    - For each closed order, capture the close time and closed profit.
    - Use OrderSelect() to check the current state if needed, but for true historical equity, I recalculate the running balance by applying each closed trade sequentially. This gives you a clean equity curve based on closed P&L, which is the standard for most performance reports.
  • Export to a CSV file using FileOpen() with the FILE_CSV|FILE_WRITE flag. Write headers: Timestamp, Balance, Equity, Closed_PL.


  • The default "History Center" export (via F2) gives you tick or M1 data for backtesting, but it doesn't include your account's P&L. That's for price data only. If you're looking for a ready-made solution, the MQL5 community has a few free scripts, but none of them handled my broker's weird prefix on symbols (e.g., "GER30." instead of "GER30"). I had to modify the symbol string handling to strip the dot suffix manually—another detail the official docs on SymbolInfoString() gloss over.

    A quick side-by-side comparison of methods:

    | Method | Data Includes | Time Stamps | Equity Curve Ready |
    | ------ | ------------- | ----------- | ------------------- |
    | Save as Report (HTML) | Yes | Yes | No (HTML format) |
    | Right-click Account History | Yes (trades only) | Yes | No (no floating equity) |
    | Custom Script (my approach) | Yes (with running balance) | Yes | Yes (CSV format) |

    Reference: MQL4 Documentation - OrderSelect, OrderHistorySelect (docs.mql4.com); MetaQuotes Help Center on Account Information (help.metaquotes.net).

    This article was originally published on FXEAR.com. All rights reserved. Unauthorized reproduction is prohibited.