tradehistoryexporttocsv
Download scriptThis script is a specialized utility designed for MetaTrader users who want to export their historical trading data into a structured CSV (Comma Separated Values) file. Instead of manually scrolling through trade history, this tool automates the collection of specific metrics and saves them into a file that can be opened in programs like Microsoft Excel or Google Sheets.
Core Functionality
The logic follows a straightforward path: the user defines which types of trades to include, sets a specific date range, and clicks a button on the chart to generate the report.
1. User Configuration and Filters The script allows you to customize exactly what data is gathered through several toggleable options:
- Trade Types: You can choose to include specific types of orders in your report, such as standard Buy and Sell trades, or more specific ones like Buy/Sell Limits and Buy/Sell Stops.
- Timeframe Filtering: You can set a specific "Start Date" and "End Date." The script will ignore any trades that occurred outside of this window.
- Profit Logic: There is an intelligent filtering system for profits. Depending on your settings, the script can be instructed to only export winning trades, only losing trades, or all trades regardless of the outcome.
2. The Export Process Once you are ready to generate the file, the script performs the following actions:
- File Creation: It looks for a specific folder (defaulting to a folder named "Data") and creates a CSV file with a unique title based on the currency pair (e.g., EURUSD) and the date range selected.
- Header Generation: It automatically writes a header row so your spreadsheet is organized into columns: Type, Size (Lots), Commission, Swap, and Profit.
- Data Calculation: The script scans through your entire account history. For every trade that matches your chosen criteria (correct type, correct date, and profit status), it calculates the totals for volume, fees, and net profit.
- Writing to File: It compiles these figures into a clean text format and writes them line-by-line into the CSV file.
User Experience
From a user's perspective, the script adds a dedicated button directly onto your trading chart. When clicked, it handles the heavy lifting of scanning thousands of historical records and organizing them into a professional data sheet in seconds. It also provides feedback in the "Experts" journal to confirm if the file was successfully created or if there were any issues accessing the folder path.
ÿþ/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
/ / | t r a d e h i s t o r y e x p o r t t o c s v . m q 4 |
/ / | C o p y r i g h t 2 0 1 5 , M e t a Q u o t e s S o f t w a r e C o r p . |
/ / | h t t p s : / / w w w . m q l 5 . c o m |
/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
# p r o p e r t y c o p y r i g h t "