Guarda come scaricare robot di trading gratuitamente
Ci trovi su Twitter!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Script

Trade List Report — a colorful PDF of your trades, written in pure MQL5 - script per MetaTrader 5

Sandro Begashvili
Sandro Begashvili
Sandro Begashvili - sviluppatore MQL5, MQL4, Python e Pine Script
Sviluppo programmi di trading per MetaTrader 4 e MetaTrader 5: expert advisor, indicatori personalizzati e pannelli grafici di trading. Descrivetemi la vostra idea e la trasformo in codice funzionante e documentato.
Visualizzazioni:
11
Pubblicato:
Freelance MQL5 Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

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.

What the page looks like

  • A header band in your brand color, with a candle logo mark, the account name, login, broker, and the time the file was made.
  • A row of KPI cards — trades listed, net result, gross profit, gross loss — each with a colored edge down its left side.
  • A win-rate donut gauge, drawn as a real vector wedge rather than an image.
  • The trade table: a numbered badge per row, the symbol, a rounded BUY or SELL pill, volume, open and close prices aligned on their decimal points, the time, and the result in the color of its sign.
  • A diverging profit bar on every row, with a small ruler above the column, so the bars can be read as a chart instead of decoration.
  • A totals strip, and a footer with a dashed rule and the page number in a pill.
  • Automatic pagination. The column captions repeat on every page.

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.

Where the trades come from


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.

Inputs

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.

How to use

  1. Copy the MQLPDF folder into MQL5\Include, so that the headers sit at MQL5\Include\MQLPDF\PdfWriter.mqh and so on.
  2. Copy TradeListReport.mq5 into MQL5\Scripts and compile it in MetaEditor.
  3. Drop the script on any chart, set the number of trades, and click OK.
  4. Open the file from MQL5\Files. The script prints its full path to the Experts log.

How it works

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.

What comes next

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:

  • Text and fonts. A font resource managed by the document, string escaping that handles characters above code 127, and a text call on the surface itself. The font plumbing in this script disappears.
  • Metrics and layout. The width table moves into the library, the surface learns to measure a string, and text gains word wrapping, alignment and clipping boxes.
  • Later parts. A real table component with repeating headers and column styles, so a report like this one becomes a few dozen lines; charts drawn on the same surface interface; images; stream compression; and metadata.

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.

The article series

Building a PDF Creation Library in MQL5

All parts are listed on my profile: https://www.mql5.com/en/users/sandrobegashvil

Notes

  • The report lists what the account can show. A history source only sees what the terminal has actually downloaded, so a long look-back may need the history period widened in the terminal first.
  • Results are net: profit plus swap, and for closed trades plus commission.
  • A closed trade is credited to the moment it closed, which is when its result became real.
  • The script writes a file and nothing else. It never opens, changes or closes a trade.
Psychological Level Reaction Tracker 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 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.

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.