Last quarter, I decided to finally build a proper risk-adjusted performance dashboard for my EAs. Not the basic balance graph MT4 gives you by default—I wanted a clean, customizable equity curve that I could overlay with drawdown bands and monthly breakdowns. The built-in "Account History" export in MT4 is fine for a quick glance, but it tops out at 64MB of CSV data. If you're running multiple EAs across several pairs for years, that file cuts off mid-2023 and leaves you guessing.
I learned this the hard way. My GBPUSD scalper had been running since 2021, and when I tried exporting the full history via File > Save as Report, the CSV just stopped. No error message, no warning—just incomplete data.
So I rolled up my sleeves and wrote a custom MQL4 script to pull the data directly from the terminal's history database. But even then, I hit a wall: the timestamps in MT4's history center are stored in GMT, but my broker's server offset was GMT+2 during summer. If I didn't adjust for that manually, my exported equity curve would show wild spikes at rollover that didn't actually exist in real trading.
Here's what I actually did, step by step, to get it right:
Step 1: Understanding MT4's Data Storage
MT4 stores every trade in the
history folder of your terminal's installation directory. But those .hst files are binary—you can't just open them in Excel. The proper way is to loop through the OrdersHistoryTotal() function in MQL4, which gives you access to every closed order since the account was opened. The official MQL4 Reference (docs.mql4.com) covers this in the "History Access" section, but it doesn't tell you one critical thing: the OrderOpenTime() and OrderCloseTime() return server time, not your local timezone.Step 2: Building the Export Script
I wrote a simple script that iterates through all historical orders, pulls out the close time, profit, commission, and swap, then writes them to a CSV file using
FileWrite(). The key part that tripped me up was the date format. MT4 uses datetime type which is seconds since 1970, but when you export to CSV, you want something readable. I used TimeToString() with the TIME_MINUTES flag, but that gave me server time. My broker's server was set to GMT+2, and I trade from a GMT+1 location, so the daily rollover at 23:00 server time was showing as 21:00 in my local time—not the end of the trading day.Step 3: The Hidden GMT Offset Adjustment
Here's the part that isn't in any official documentation I could find. After poring over forum threads and testing for hours, I realized that MT4's
TimeCurrent() returns the broker's server time, and TimeLocal() returns your PC's time. But neither of those directly gives you the offset you need for day boundary alignment in your equity curve. I ended up using TimeGMTOffset() to get the system's GMT offset, then cross-referenced it with the broker's displayed server time in the terminal window's bottom-right corner.The brute-force solution I settled on was this: I added a manual offset variable at the top of my script, set it to the broker's GMT offset (in my case, 2 hours during summer time), and used
struct tm to shift every timestamp before writing to CSV. That way, 23:00 server time became 21:00 UTC, which aligned perfectly with my daily bars from Dukascopy's data feed. Was it elegant? No. Did it work? Absolutely.``
mql4
// At the top of the script
int brokerOffset = 2; // Broker server is GMT+2
// Inside the order loop
datetime localClose = OrderCloseTime() - brokerOffset * 3600;
string closeStr = TimeToString(localClose, TIME_DATE|TIME_MINUTES);
`
Step 4: Exporting Without the 64MB Limit
The built-in export gets truncated at 64MB because MT4 writes the entire report including the HTML header and all the formatting. By using FileOpen() with CSV mode and writing only the raw numeric data (timestamp, profit, balance), I sidestepped that limit entirely. My full history from 2021 to present came out to about 18MB—well under the cap, but only because I wasn't including all the extra bloat.
Step 5: Building the Equity Curve
Once I had the CSV with clean timestamps and balance values, I pulled it into Python and used matplotlib` to plot the curve. The important thing was making sure the day boundaries matched my external data sources. That GMT offset adjustment I made earlier? That was the difference between a smooth equity curve and one that looked like a saw blade at every daily reset.One thing I'd do differently next time: I'd store the raw tick data alongside the trade history so I could calculate slippage-adjusted equity. But that's a project for another weekend.
Reference: MQL4 Documentation – "History Access" and "Time Functions" (docs.mql4.com)
---
This article was originally published on FXEAR.com. All rights reserved.