Creating a Cairo-Inspired Graphics Library for MetaTrader 5
Building a real 2D renderer for MetaTrader 5 in pure MQL5 — anti-aliased shapes, transparency and gradients, with no DLLs and no external tools.

The problem this series solves
Every serious MetaTrader panel eventually hits the same wall. MQL5's chart
objects and the standard CCanvas were built for lines and rectangles, so as
soon as you want a rounded card, a donut chart, a semi-transparent overlay or a
smooth gradient, you are stuck: corners are square, edges are jagged, background
colors have no real alpha channel, geometry is whole-number only, and a panel
made of hundreds of objects starts to feel slow.
The usual escape route is a DLL. That costs you portability, it will not pass Market validation, and many traders will not run it.
The approach
Rather than invent an architecture, this series ports the design of Cairo — the 2D graphics library behind GTK, Firefox and many other programs — into pure MQL5.
Cairo's central idea is a clean separation:
- Paths describe what to draw — the geometry, in floating-point coordinates
- Sources describe what to paint with — a solid color, a gradient, a pattern
- A per-pixel coverage mask resolves the two and composites the result
Because those three stages are independent, one fill routine can render any
shape, and anti-aliasing falls out of the coverage mask instead of being a
special case per shape. Everything lands on a single OBJ_BITMAP_LABEL, so the
chart stays fast no matter how complex the drawing is.
How the series is built
Each part is a small, verifiable step, and every part ends with code you can compile and run. Nothing is hand-waved and nothing depends on a later part to make sense.
The source code lives on MQL5 Algo Forge, so you can read the library as it grows rather than copying snippets out of the text.
Who it is for
MQL5 developers who build panels, dashboards or indicators with a visual interface, and anyone curious how a real graphics library works underneath. You should be comfortable with MQL5 classes and arrays. No graphics background is assumed — the maths is introduced where it is needed.
All parts
Each part builds on the one before it. Start at Part 1.
- Part 1Why the terminal needs its own 2D-rendererSeptember 3, 2026
- Part 2Points, Contours and the PathSeptember 10, 2026
Read the full articles on MQL5.com
Every part is published in full, with complete source code, on MQL5.com.

