Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Scripts

Export Closed Trades to CSV with a summary per magic number - script for MetaTrader 5

Northern Lights
Northern Lights
Trader and developer behind RiskDeck for MetaTrader 5, published under the Dojiwave brand. I build tools for the part of trading that decides whether an account survives: position size, stops and loss limits. Every version is tested on MetaTrader 5 demo accounts before it reaches the Market
Views:
48
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The History tab in MetaTrader 5 lists deals and orders, not trades. This script rebuilds each closed trade from its deals and writes one row per trade to a CSV file you can open in Excel, LibreOffice or Google Sheets.


Inputs

  • Period: This month, Last month, This year, All history or Custom. A trade counts in the period by its close time.
  • Custom period: From and To. A To date with no time includes that whole day.
  • Symbol: one symbol or empty for all symbols.
  • Magic number: one magic number or -1 for all trades.
  • Column separator: comma, semicolon or tab.

File 1: ClosedTrades_<login>_<period>.csv

One row per closed trade: OpenTime, CloseTime, Symbol, Type, Volume, OpenPrice, ClosePrice, StopLoss, TakeProfit, Commission, Swap, Fee, Profit, NetProfit, Magic, Comment, CloseReason, PositionTicket.

File 2: ClosedTradesByMagic_<login>_<period>.csv

One row per magic number and one row for all trades: Magic, Trades, Wins, Losses, NetProfit, GrossProfit, GrossLoss, LargestLoss, LongestLosingStreak, WinRatePct.

How to use

  1. Copy ExportClosedTrades.mq5 to the MQL5\Scripts folder and compile it in MetaEditor.
  2. Drag the script onto any chart, set the inputs and press OK.
  3. The Experts tab shows where both files were saved and how many rows each has. To find them, use File > Open Data Folder > MQL5\Files.

Notes

  • A trade closed in parts is one row. Its exit price is the average of the exits, weighted by volume.
  • Open positions are not exported.
  • Files are UTF-8 with a BOM. Prices and money use a decimal point.
  • The script only reads the account history. It doesn't place, change or close orders.
  • If the terminal isn't connected, the journal says so, because the history may be incomplete.
  • If a file is open in another program, the script can't overwrite it and writes the reason to the journal.
Account Recorder - balance, equity and day drawdown to CSV every minute (service) Account Recorder - balance, equity and day drawdown to CSV every minute (service)

A service that writes your balance, equity, floating result, margin and the drawdown from today's highest recorded equity to a CSV file every minute. Runs without a chart and never trades.

GotobiDays - include file to find Gotobi days (Japanese payment dates) GotobiDays - include file to find Gotobi days (Japanese payment dates)

Include file with small functions to find the Gotobi days: the 5th, 10th, 15th, 20th, 25th and the last day of each month, moved back to the previous business day when they fall on a weekend or a holiday you list. Information only, no trading functions.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.