Loading…

Export Open Orders To CSV

A snapshot of the live book in a spreadsheet is the starting point for position reviews, risk checks and record keeping, and the terminal will not give you one - the Trade tab cannot be exported. This script writes it: columns for ticket, symbol, type, volume, open price, current price, stop loss, take profit, open time, magic number, comment, swap and profit, with positions grouped first and pendings after. The details that usually go wrong in home-made exports are handled. Open times are ISO 8601 (2026-08-16 14:30:00) - sortable as text and unambiguous in any locale. Prices are formatted with each symbol's own digit count, so a EURUSD row shows five decimals and a gold row two, and no cell ever prints as 1.234500000000001. The "current price" column is the price that matters for that row: the close price for an open position (bid closes a buy, ask closes a sell) and the fill price for a pending (ask fills the buy side, bid the sell side) - one column, but always the correct side of the spread. Cells that do not apply are left empty rather than written as zero. A pending order has no swap and no profit yet; writing 0.00 there would drag down every spreadsheet average computed over the column. The same goes for a stop loss of 0 - it means "none", and the cell says so by being empty. Broker comments are the one field that can contain anything, including the delimiter itself, which would silently shift every later column of that row. Comments are therefore quoted to the CSV standard (RFC 4180) when they need it: wrapped in double quotes with inner quotes doubled. Excel and every serious CSV reader parse this correctly. The file is written with FILE_ANSI on purpose: Excel opens an ANSI CSV correctly on a double-click, while UTF-8 without a byte-order mark often comes up garbled there. Everything the script writes is plain ASCII, so nothing is lost by the choice. The delimiter is chosen from a dropdown - comma by default, semicolon for Excel in European locales that reserve the comma for decimals, or tab. An empty book still produces a file with the header row: proof the export ran and the book really was flat, which is not nothing when the file is part of a daily record. Notes and limitations - Read-only. Nothing is closed, modified or placed. - The snapshot is the book at the moment the script ran; prices in the file are stale within seconds on a live market. - The file is overwritten only in the impossible case of two runs in the same second - the timestamp is in the filename precisely so that history accumulates instead of overwriting. - Files land in the terminal's sandbox (MQL4\Files or MQL5\Files). MetaTrader scripts cannot write anywhere else on disk, by design. - Excel sometimes eats leading zeros in the magic column if you convert it to a number; import the column as text if your magics are zero-padded.

Script · MT4 · v1.0 · Free

About Export Open Orders To CSV

Export Open Orders To CSV is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Current symbol only and Delimiter. MQL source code included.

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

Settings

SettingDefaultWhat it does
Current symbol onlyfalseExport only this chart's symbol
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: Volume · Pending Orders · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria