Skip to content
All library documents

Optimizing Market Profile Rendering with Canvas Objects

Article MQL5 articles

Summary

This article explains how to reduce the chart objects required to display a Market Profile indicator. Instead of drawing each histogram segment as a separate rectangle, it uses the CCanvas class to render the profile for each day on a bitmap object. A CMarketProfile class stores daily price bounds and intraday bars, tracks session counts, sizes its canvas, and draws the Asian, European, and American session histograms.

The article reports that a three-day M30 example falls from 4,697 rectangle objects to three bitmap objects, one per day. This demonstrates a large reduction in object count, while preserving the indicator’s underlying profile calculations. The rendered version still shows flickering and image movement during redraws, so the resource improvement does not eliminate visual artifacts. The author points to an unimplemented chart-scale-change check as a possible way to avoid unnecessary redraws and notes that further optimization remains possible.

Key ideas

  • Canvas rendering can replace thousands of profile rectangles with one bitmap object per displayed day.
  • The CMarketProfile class manages daily data, canvas dimensions, session arrays, and drawing.
  • Three session histograms can be drawn in separate colors on each daily canvas.
  • The example reduces object count from 4,697 to three for three displayed days.
  • Redrawing can still cause flicker, and the scale-change method is not implemented.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.