Trade List Report: A Pure MQL5 PDF Generator

Trade List Report: A Pure MQL5 PDF Generator
Download ALL MT5 scripts (462)
YouTube Video Thumbnail



Similar MetaTrader Tools

Trade List Report: A Pure MQL5 PDF Generator

Info

The Trade List Report: A Pure MQL5 PDF Generator is a Script for MetaTrader 5 that this script generates a professional pdf report of your trading activity directly in mql5. Choose the number of trades to include, and the script will create a PDF file in your MQL5\Files folder.

Usage

This tool is typically used for enhancing chart analysis and decision making.

Platform

This Script works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Scripts folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use Trade List Report: A Pure MQL5 PDF Generator

1. Installation: Move your script file into the MQL/Scripts directory and restart the platform.

2. Execution: Drag the script onto a chart; it will perform a one-time action, such as closing all open orders or clearing chart objects.

3. Editing: Use MetaEditor (F4) to modify code, click "Compile," and verify no errors appear in the terminal before running.

4. Removing: Scripts stop automatically, but you can remove them manually by right-clicking the chart and choosing "Remove Script."

Frequently Asked Questions

Q: How are scripts different from EAs? A: Scripts execute a single action and then stop; EAs monitor the market and trade continuously.

Q: Can I assign a hotkey to a script? A: Yes, right-click the script in the Navigator, select "Set Hotkey," and define your preferred keyboard shortcut.

Q: Why did my script stop? A: Scripts are designed to stop immediately after finishing their programmed command; this is normal behavior.

What this tool does

This script generates a professional PDF report of your trading activity directly in MQL5.

Typical Use Case

This Script excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Script works on MetaTrader 5. Place the file in the MQL5/Scripts folder and restart the terminal.

Description & Settings

Related: Trade Cost Analysis: Commission, Swap, and Fees by Symbol - another powerful script for MetaTrader 5 traders.

This script generates a professional PDF report of your trading activity directly in MQL5. Choose the number of trades to include, and the script will create a PDF file in your MQL5\Files folder. This is a native PDF, not an HTML or CSV file, ensuring compatibility with any PDF viewer and accurate printing.

Also recommended: Risk Lot Calculator: Accurate Trade Sizing - similar script with strong performance on MetaTrader 5.


The report is generated without external DLLs, converters, or internet connections. All graphical elements, such as rectangles, rounded shapes, and the win-rate donut, are created using MQL5's native PDF drawing operators.



Report Structure



Header: Features your brand color, a candle logo, account name, login, broker, and the report generation time.

KPI Cards: Displays key performance indicators like total trades, net result, gross profit, and gross loss, each with a colored indicator.

Win-Rate Donut Gauge: A vector graphic representation of your win rate.

Trade Table: Lists each trade with a number, symbol, trade type (BUY/SELL pill), volume, prices aligned to the decimal, open/close times, and the trade result displayed in color.

Diverging Profit Bar: A visual representation of profit for each trade, with an optional ruler above the column for better readability.

Totals Strip and Footer: Includes summary totals and page numbering.



Features



Automatic Pagination: Columns repeat on each page for clarity.

Vector Graphics: All elements are vector-based, ensuring crispness at any zoom level. File size is minimal (tens of kilobytes).



Trade Source Options



Auto: Prioritizes open positions, then closed history, and finally sample data if others are unavailable.

Open Positions Only: Lists currently open positions, newest first.

Closed Deals from History (Default): Lists closed trades from a specified number of recent days, looking up opening prices from the entry deal.

Sample Data: Generates a sample trade list using Market Watch prices for initial viewing.



Script Inputs



Number of trades to list: Determines the number of rows in the report. More rows will extend the report across multiple pages.

Trade source: Selects the data source for the report (see options above).

Output file in MQL5\Files: Specifies the name for the generated PDF file. The .pdf extension is added automatically if omitted.

Report title: Sets the title displayed in the report header and as the PDF document title.

Paper size: Options include A3, A4, A5, Letter, or Legal. The table layout adjusts to the selected paper width.

Brand color: Sets the color for the header band, column headings, and page number indicator.

Accent color: Used for the rule under the header, the zero line on the ruler, and the open trade marker.

Shade alternate rows: Enables or disables zebra striping for the trade table rows.

History look-back, days: Defines the number of past days to consider when using the history data source.



How to Use



1. Include Files: Copy the MQLPDF folder into your MQL5\Include directory.
2. Copy Script: Place the TradeListReport.mq5 file into your MQL5\Scripts directory.
3. Compile: Compile the script in MetaEditor.
4. Run: Drag the script onto any chart, set the desired number of trades, and click OK.
5. Access Report: Locate the generated PDF file in your MQL5\Files folder. The script will log the full file path to the Experts log.



Technical Details



This script is based on the MQL5 PDF Creation Library series, specifically utilizing primitives from Part 4: Lines, Boxes, and Color. It constructs the PDF page using rectangles, rounded rectangles, circles, ellipses, Bézier curves, line styles, and color manipulations directly within MQL5.

Coordinate System: The script manages a coordinate flip to align the PDF's top-left origin with typical programming conventions, ensuring text is rendered correctly.

Text Measurement: Proportional font metrics are used to accurately measure string widths, enabling precise text alignment (centering, right-alignment) and ensuring decimal points in price columns align perfectly.

Direct PDF Writer Usage: The script interacts directly with CPdfWriter, declaring necessary font resources like /F1 and /F2 within its own page tree, rather than relying on a higher-level document object for simplified drawing operations.



Future Enhancements



The PDF creation library is continuously evolving. Future updates will introduce:

Text and Fonts: Integrated font resource management, advanced string escaping, and on-surface text rendering.

Metrics and Layout: Enhanced text measurement capabilities, including word wrapping, alignment, and clipping.

Advanced Features: A dedicated table component with repeating headers and styles, chart rendering on the PDF surface, image embedding, stream compression, and metadata support.

These advancements will be integrated seamlessly due to the abstract CPdfSurface interface, ensuring compatibility with future rendering backends.



Article Series Reference



Building a PDF Creation Library in MQL5

Part 1 — Writing a PDF by Hand

Part 2 — Why PDFs Break

Part 3 — The Byte-Exact Writer

Part 4 — Lines Boxes and Color (used in this script)



Notes



The report reflects the data available in your trading terminal. For extensive history periods, ensure your terminal's history settings are appropriately configured.

Results are calculated net, including swaps, commissions, and profit/loss for closed trades.

A closed trade's result is attributed to its closing time, marking when the profit or loss became realized.

This script solely generates a report file and does not interact with, modify, or close any trades.

You may also like: Trade History in R: Comprehensive Analysis - excellent alternative for script users on MetaTrader 5.

Source Code

#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version     "1.00"
#property script_show_inputs
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#include <MQLPDF/PdfWriter.mqh>
#include <MQLPDF/PdfPage.mqh>
enum ENUM_TRADE_SOURCE
  {
   SOURCE_AUTO,

.......

Leave your opinion, ask a question, share some knowledge

⚠ Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.