Loading…

Export Equity Curve To CSV

"Export my equity curve" is usually asked for a chart of account value over time. The trouble is that MetaTrader's history pool - the record this script and everything like it reads from - only contains closed events: closed trades, deposits, withdrawals, credits and adjustments. Floating profit and loss on positions that are still open is never in there. Anything that calls itself an equity curve while reading only the history pool is actually producing a balance curve, and the naive version of this script ships under the wrong name and lets the user assume it is something it is not. This script is honest about what it is. It reconstructs the running BALANCE - not equity - from every closed trade and every balance operation (deposit, withdrawal, credit) it can find, in time order, and writes one row per event plus, optionally, one summary row per calendar day. The header comment, the log output and this description all say plainly that floating P/L is absent, because a curve that looks complete but silently isn't is worse than one that admits the gap. The reconstruction itself is anchored, not accumulated forward from zero. Starting from today's real account balance and subtracting every event's net effect walks backward to the balance before the very first event; a forward walk from there reproduces the true balance after each one in turn. This means the file always lands on today's actual balance even if a date filter narrows what gets written to it, and a mismatch between the reconstruction and the live balance - checked at the end and reported if found - is a signal that something posted while the script was running, not evidence the maths is wrong. Broker comments can contain whatever character the chosen CSV delimiter is, and would silently shift every column after them if written raw. Every comment field is quoted per RFC 4180 whenever it contains the delimiter or a quote character, rather than only when it looks risky by eye. Notes and limitations - This is a BALANCE curve, not an equity curve. Floating profit and loss on currently open positions is never included, because it is not in the history pool this script reads from. For a live floating-equity series, a streaming EA that samples AccountEquity()/ACCOUNT_EQUITY on a timer is the correct tool, not this script. - The from/to date filter only controls which rows are written to the file. It never changes the running-balance reconstruction, which always uses the complete history so the numbers stay internally consistent. - If a trade closes or a balance operation posts while the script is still running, the final reconciliation check can report a small mismatch between the reconstructed and the live balance. That is expected, not a bug - the log message explains it. - Very long history (tens of thousands of events) will take a visible moment; progress is logged every 500 events processed. - The file is written new each run, timestamped, and previous exports from this script are never overwritten or deleted automatically.

Script · MT4 · v1.0 · Free

About Export Equity Curve To CSV

Export Equity Curve To CSV is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as From date, To date and Include daily summary rows. MQL source code included.

Files in the download: ExportEquityCurve.ex4, ExportEquityCurve.mq4, ExportEquityCurve.txt.

Settings

SettingDefaultWhat it does
From date0From date - rows only (0 = no lower bound)
To date0To date - rows only (0 = up to now)
Include daily summary rowstrueAdd one balance row per calendar day
DelimiterDelimiterCommaCSV column separator

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria