Run this script, choose how many trades you want listed, and it writes a real PDF file into your MQL5\Files folder. Not an HTML page, not a CSV you open in something else, and not a screenshot — a PDF, built byte by byte in MQL5, that opens in any viewer and prints at exactly the size it says.
Figure 1. Output PDF file of script
There is no DLL, no external converter and no internet connection involved. Every rectangle, every rounded pill, every curve of the win-rate donut is a native PDF drawing operator written by MQL5 code.
Everything on the page is vector. Zoom to 1600% and the pills, the donut and the candles stay crisp, and the whole file is a few tens of kilobytes.
| Trade source | What gets listed |
|---|---|
| Auto | Open positions; if there are none, closed history; if that is empty too, sample data |
| Open positions only | The positions currently open, newest first |
| Closed deals from history (default) | Closed trades from the last N days, newest first, with the opening price looked up from the entry deal |
| Sample data | A plausible list built from your Market Watch prices |
The fallback chain and the sample source are there on purpose. A brand-new demo account has no positions and no history, and an empty report teaches nobody anything — so the script still produces a full, finished page you can look at on the first run.
| Input | Meaning |
|---|---|
| Number of trades to list | How many rows the report contains. More rows simply add pages. |
| Trade source | See the table above. |
| Output file in MQL5\Files | The file name. .pdf is appended if you leave it off. |
| Report title | Printed in the band, and set as the PDF document title the viewer shows in its window. |
| Paper size | A3, A4, A5, Letter or Legal. The table re-proportions itself to the width. |
| Brand color | The header band, the headings and the page-number pill. |
| Accent color | The rule under the band, the zero tick of the ruler, and the open-trade marker. |
| Shade alternate rows | Zebra striping on or off. |
| History look-back, days | How far back the history source reaches. |
This script is a companion to my article series Building a PDF Creation Library in MQL5, and it uses the library exactly as it stands after Part 4: Lines, Boxes, and Color. It adds nothing to the library. Every component you see on the page is composed inside this one script out of the primitives Part 4 made available: rectangles, rounded rectangles, circles, ellipses, Bézier curves, line widths, caps and joins, dash patterns, clipping paths, and color with its luma helpers.
Two details are worth a look if you are reading the source.
The coordinate flip. CPdfPage turns the page upside down once, so that the origin is at the top-left and y grows downward, like almost every other coordinate system a programmer meets. The cost of that lands on text, which would come out mirrored. The script pays it back with a second flip in the text matrix:
BT /F1 8 Tf 1 0 0 -1 120 240 Tm (EURUSD) Tj ET
The two mirrors cancel, the glyphs stand upright, and text ends up using the same coordinates as every rectangle on the page.
Measuring text. To center a caption or right-align a price you have to know how wide a string will be. Helvetica is proportional, so the script carries the font's own advance-width table and sums it. That is also why the numbers in the price columns line up on their decimal points instead of drifting.
One more thing the source explains in a comment: the script drives CPdfWriter directly instead of using CPdfDocument. Part 4's document writes a single resource, /ProcSet, because shapes need no others — text needs a font resource, and fonts are Part 5. Rather than add one to the library ahead of its article, the script declares /F1 and /F2 in its own page tree. Everything that draws still goes through CPdfPage, untouched.
The library is a series, and it is still growing. The parts after this one replace the scaffolding you can see in this script with real library features:
Because every drawing call in the library is written against the abstract CPdfSurface rather than against CPdfPage, those additions also arrive on any future backend — a raster canvas, for instance — without a single existing component being rewritten.
I will post an updated, much shorter version of this report as the library gains those capabilities. If there is a component you would like to see in it, say so in the comments.
Building a PDF Creation Library in MQL5
All parts are listed on my profile: https://www.mql5.com/en/users/sandrobegashvil
Psychological Level Reaction Tracker
Free MQL5 indicator that plots 00, 25, 50 and 75 psychological price levels and tracks historical touches, rejections, breakouts and sweeps with dashboard statistics and alerts.
Round Number Levels
Auto-scaled round-number (psychological) levels with major, half and quarter lines, plus a panel showing the nearest levels and their distance in price, points and % of daily ATR.
Economic News Window Flag for Pausing Expert Advisors
Utility Expert Advisor that reads the built-in economic calendar and sets a terminal global variable to 1 around important events, so other Expert Advisors can skip new entries during the news.
Spread Spike Histogram with Moving Average
Separate window indicator that draws the spread of every bar as a histogram with its moving average and colors the bars where the spread is far above normal or above a fixed ceiling.