- MQL5 100%
| Article-22233-Tools-Palette-Part-32-Crosshair-Magnifier.mqproj | ||
| README.md | ||
| Tools Palette Part 4.mq5 | ||
Article-22233-Tools-Palette-Part-32-Crosshair-Magnifier
This repository is an article-derived reference project based on the original MQL5 article. It does not claim to reproduce the full original source code unless files are explicitly attached.
Overview
This project references MQL5 article Part 32 of a Tools Palette series. The article extends a previously built interactive chart sidebar with a dedicated crosshair subsystem that adds:
- reticle tick-mark overlays
- full-chart vertical and horizontal crosshair lines
- dynamic price and time axis labels
- a circular magnifier lens for zoomed candle inspection
- a double-click measurement mode with anchor, diagonal line, bar count, pip distance, and raw price difference
The implementation described in the article is centered around canvas-based rendering and chart event handling.
Original Article
- Article ID: 22233
- Author: Allan Munene Mutiiria
- Publication date: 2026.05.21
- Category: MQL5 GUI / Chart objects
- URL: https://www.mql5.com/en/articles/22233
Repository Purpose
This repository should be treated as a reference/reconstruction project for the article’s described architecture and code fragments.
Its purpose is to document and preserve the article’s main implementation ideas for:
- custom chart navigation overlays in MQL5
- layered bitmap-label canvas rendering
- magnifier lens rendering on live chart data
- measurement tooling integrated into a sidebar-driven UI
- event-driven crosshair interaction and cleanup logic
Key Concepts
- Custom crosshair rendering beyond the default MetaTrader crosshair
- Reticle overlay with configurable offset, tick length, and thickness
- Magnifier lens with configurable diameter, zoom factor, and cursor offset
- Axis label rendering using chart foreground/background colors
- Canvas layer expansion from basic sidebar/flyout rendering to multiple overlay surfaces
- Bresenham line drawing for measure diagonals
- Double-click detection using microsecond timing
- Conversion between chart coordinates and screen coordinates
- Theme-aware redraw behavior
- Automatic hiding of crosshair elements over sidebar and flyout regions
Algorithm / Architecture Summary
The article describes the following architecture:
- New input parameters
ReticleOffsetReticleTickLenReticleThicknessMagDiameterMagZoomMagOffsetAxisLabelFontSizeAxisLabelFont
- Primitive extension
CCanvasPrimitivesis extended withDrawBresenhamLine(...)for pixel-level diagonal rendering with alpha blending.
- Canvas layer expansion
CCanvasLayergrows from four canvases to fifteen total surfaces.- Added canvases include reticle, magnifier, crosshair lines, crosshair labels, measure anchor lines, measure labels, and a full-screen diagonal line canvas.
- Helper methods prefill 1-pixel-wide or 1-pixel-tall line canvases using chart foreground colors.
- Dedicated manager class
- A new
CCrosshairManagerclass is introduced between sidebar rendering and chart event handling. - It tracks visibility flags, measurement state, anchor coordinates, double-click timing, and cached magnifier cursor position.
- Rendering responsibilities
- Draw reticle tick marks on a transparent square canvas.
- Show/hide and reposition vertical/horizontal crosshair lines.
- Render and place price/time axis labels.
- Render a circular magnifier lens with:
- candle bodies and wicks
- bid/ask lines
- circular clipping
- anti-aliased lens border
- center guide marks
- current price label
- Measurement mode
- Double-click toggles measurement anchor mode.
- Anchor time/price and pixel coordinates are stored.
- Vertical/horizontal anchor lines and axis labels are shown.
- A diagonal line is drawn from anchor to current cursor.
- A floating chart label shows bars, pips, and absolute price difference.
- Top-level integration
- Cleanup method removes crosshair and measurement state on tool switch.
- Mouse-move handler coordinates all real-time updates when the crosshair tool is active.
Mentioned or Attached Files
Explicitly attached files
No attached source files were available in the processed input.
Files mentioned in the article text
Tools Palette Part 4.mq5
Classes mentioned in the article
CCanvasPrimitivesCCanvasLayerCCrosshairManagerCToolsSidebar
Methods specifically shown or discussed
DrawBresenhamLineCreateAllCanvasesDestroyAllCanvasesDrawCrossVerticalLinePixelsDrawCrossHorizontalLinePixelsDrawMeasureVerticalLinePixelsDrawMeasureHorizontalLinePixelsDrawReticleTickMarksShowReticleHideReticleUpdateReticlePositionShowCrossVerticalHideCrossVerticalUpdateCrossVerticalPositionShowCrossHorizontalHideCrossHorizontalUpdateCrossHorizontalPositionShowCrossPriceLabelHideCrossPriceLabelShowCrossTimeLabelHideCrossTimeLabelDrawAndPositionAxisLabelUpdateCrosshairAxisLabelsShowMeasureLinesHideMeasureLinesUpdateMeasureVerticalPositionUpdateMeasureHorizontalPositionUpdateMeasureAnchorLabelsShowMagnifierHideMagnifierUpdateMagnifierPositionDrawMagnifierLensContentUpdateMeasureDiagonalLineUpdateMeasurementInfoLabelHideAllCrosshairElementsShowAllCrosshairElementsHandleCrosshairDoubleClickDeleteAllMeasureObjectsCleanupCrosshairOnToolSwitchHandleCrosshairMouseMove
Statistics
- Inputs added: 8
- New canvas layers added: 11
- Total canvases after expansion: 15
- New manager class introduced: 1
- Protected member variables in
CCrosshairManagerdescribed by the article: 20 - Protected methods in
CCrosshairManagerdeclared in the article: 30
Tags
mql5 metatrader-5 canvas crosshair magnifier chart-ui sidebar measurement-tool bresenham-line interactive-tools
Difficulty
Intermediate to Advanced
Limitations
- The full original project source code is not available in the provided input.
- Only article text and embedded code excerpts were provided, so this repository should not be presented as a complete drop-in reproduction.
- The article depends on earlier parts of the Tools Palette series, especially prior sidebar, renderer, event-routing, and tool-registry infrastructure.
- Some referenced base classes and existing methods are not fully included in the provided material.
- Backtesting visuals are described, but no packaged test assets or complete runnable project structure were attached in the processed input.
Reference
Original article: Tools Palette Part 32 by Allan Munene Mutiiria.