Discussing the article: "MQL5 Trading Tools (Part 32): Crosshair, Magnifier, and Measure Mode"

 

Check out the new article: MQL5 Trading Tools (Part 32): Crosshair, Magnifier, and Measure Mode.

In this article, we extend the Tools Palette with a precision crosshair for MQL5 charts: reticle tick marks, full-width and full-height lines with axis labels, and a circular magnifier that renders zoomed candles. A double-click measure mode adds anchor markers, a diagonal connector, and a floating label with bars, pips, and price difference. Implementation details include a crosshair manager, eleven canvas layers, Bresenham line drawing, and theme-aware behavior that hides near the sidebar and fly out.

The previous parts gave the sidebar the ability to select and place drawing tools, but once you move the cursor onto the chart, there is no visual feedback about where you are pointing. The default MetaTrader 5 crosshair exists, but it cannot be customized and does not offer magnification. We fill that gap here.

The crosshair system we added consists of several layered elements that work together. A reticle overlay draws tick-mark crosses offset from the cursor center, giving a precise aiming reference without cluttering the exact point you are targeting. Full-width horizontal and full-height vertical lines extend across the entire chart from the cursor position, and price and time axis labels snap to the right and bottom edges, showing the exact value under the cursor.

A circular magnifier lens follows the cursor and renders a zoomed view of the surrounding candles inside a bordered bubble, complete with wicks, bodies, bid and ask lines, and a price label, so you can read congested areas without changing the chart zoom level. Double-clicking locks a measure anchor at that point, after which a diagonal line connects the anchor to the moving cursor, while a floating label displays the bar count, pip distance, and raw price difference in real time.

On the chart, this means you can hover any area and immediately see the exact price and time, inspect tight candle clusters through the magnifier without losing your chart context, and double-click two points to get an instant distance measurement. When you hover over the sidebar or flyout, all crosshair elements hide automatically so they do not interfere with tool selection, and toggling the theme redraws every crosshair canvas in the new foreground color.

We will achieve this in four steps. First, we add eight input parameters for reticle, magnifier, and axis label customization. Second, we add a Bresenham line drawing method for the measure diagonal. Third, we add eleven new canvas layers managed by a dedicated crosshair manager class inserted between the sidebar renderer and the chart event handler. Finally, we update the event handler and top-level shell for crosshair mouse tracking, double-click detection, and theme-aware canvas refresh. Here is a visualization of what we will be achieving.

CROSSHAIR RETICLE AND MAGNIFIER LENS

Author: Allan Munene Mutiiria