Part 1 of 7

Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 1): Why the terminal needs its own 2D-renderer

Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 1): Why the terminal needs its own 2D-renderer

Why this article was written

MQL5 gives you chart objects and CCanvas, and both were designed for straight lines and filled rectangles. The moment a panel needs a rounded card, a ring, a translucent overlay or a gradient, you run into hard limits: square corners, jagged edges, no true alpha in object background colors, integer-only geometry, and a redraw that slows down as the object count grows.

You can reach for a DLL, but then the product will not pass Market validation and many traders will refuse to install it. Part 1 starts the other way round: stay completely inside the terminal, and build the missing renderer in MQL5 itself.

What is inside

The case for a new renderer. A concrete look at what CCanvas and chart objects cannot do, and why each limitation matters for real interfaces.

Cairo's model, briefly. Geometry (paths) is kept separate from paint (sources), and a per-pixel coverage mask resolves the two before compositing. That separation is what lets one routine draw every shape — and it is what the rest of the series builds on.

Color.mqh — the color type. A single ARGB value packed into a uint as 0xAARRGGBB, with the conversion and blending helpers every later part needs. Real transparency starts here.

Surface.mqh — the drawing target. A pixel buffer bound to one OBJ_BITMAP_LABEL. Every shape in the series is written into this buffer and delivered to the chart as a single object, so complexity costs you nothing in chart performance.

A first drawing. A triangle and a circle, painted pixel by pixel in nested loops. It works — and it deliberately shows the two problems that drive Parts 2 and 3: the edges are staircased, and every new shape needs its own function.

What you can do after reading it

Create a surface, put pixels on the chart with real alpha, and understand why the library is split the way it is.

More in this series

Building a real 2D renderer for MetaTrader 5 in pure MQL5 — anti-aliased shapes, transparency and gradients, with no DLLs and no external tools. About this series

  1. Part 1Why the terminal needs its own 2D-renderer — you are hereSeptember 3, 2026
  2. Part 2Points, Contours and the PathSeptember 10, 2026
  3. Part 3Edges and the First Filled ShapeSeptember 28, 2026
  4. Part 4Anti-Aliasing, Coverage and CompositingSeptember 28, 2026
  5. Part 5Fill Rules, Holes and BordersOctober 1, 2026
  6. Part 6Curves and Adaptive FlatteningOctober 23, 2026
  7. Part 7Arcs, Circles and Rounded RectanglesOctober 27, 2026

Continue reading on MQL5.com

The full article with complete source code is published on MQL5.com.

Read the full article