Discussing the article: "MQL5 Trading Tools (Part 34): Replacing Native Chart Objects with an Interactive Canvas Drawing Layer"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: MQL5 Trading Tools (Part 34): Replacing Native Chart Objects with an Interactive Canvas Drawing Layer.
We replace native MetaTrader chart objects with a canvas-based drawing engine that renders tools pixel-by-pixel on a full-chart bitmap layer. The article implements persistent object storage with per-tool style memory, precise hit testing, selection, whole-object dragging, and handle manipulation. It also adds new line tools, a reorganized category system with a one-click delete action, and a rubber-band preview for multi-click placement.
In Part 32, every drawing tool created a native MetaTrader chart object the moment the user clicked the chart. A trend line became an OBJ_TREND, a horizontal line became an OBJ_HLINE, and a rectangle became an OBJ_RECTANGLE. MetaTrader managed their lifetime, their rendering, and their position entirely. That approach works for basic placement, but it hands control to the terminal — and the terminal gives very little back. You cannot query which object the mouse is over with pixel precision, you cannot intercept a drag on a specific handle, and you cannot render custom handle circles, dashed rubber-band previews, or floating info panels the way a professional drawing tool would.
In Part 34, we replace native objects with a full-chart bitmap canvas. It sits above the chart content and below the sidebar and flyout panels. Every line, rectangle, and annotation is stored in our own object structure array. When the chart redraws, we iterate over that array and paint each object pixel-by-pixel onto the canvas using our own rendering routines. Because we control rendering, we can perform pixel-precise hit-testing. That control enables interaction states such as selection, dragging, handle manipulation, rubber-band preview, and deletion.
The implementation follows three layers that build on each other. First, the rendering foundation — the primitive drawing functions and the per-tool line rendering library. Second, the object management layer — the struct that stores each drawing, the canvas lifecycle, and the redraw engine. Third, the interaction layer — the hit testing system and the pointer tool that turns a hit into a selection, a drag, or a deletion. Each layer depends on the one before it, and together they replace everything that native chart objects used to provide. In a nutshell, here is a visualization of our objective.
Author: Allan Munene Mutiiria