Loading…

Bitmap Plot Engine

MetaTrader can draw a candlestick chart and not much else without leaving the platform. Anything that is not price against time - a rolling correlation, an equity curve against a benchmark, a histogram of trade outcomes, a scatter of predicted versus actual moves - usually ends up either exported to a spreadsheet or approximated with a stack of trend line objects that fight the chart's own scale. This header draws proper plots directly on the chart as their own bitmap object, independent of price and time axes: a line series, a scatter series and a bar series, each with its own colour, sharing one set of autoscaled or manually fixed axes, gridlines, tick labels and a legend built from the series you actually added. It is built on CCanvas from Include\Canvas\Canvas.mqh, which ships with every MQL4 and MQL5 terminal as part of the standard library. Using it here means this header never has to hand-roll raw ResourceCreate and OBJ_BITMAP_LABEL plumbing, while staying fully self-contained: nothing beyond what the terminal already ships with. The one correctness detail worth knowing before you build on top of this: pixel coordinates are ALWAYS clamped to the canvas bounds before anything is drawn. CCanvas itself does not protect against writing outside its own pixel buffer, so a fixed-range plot fed a value outside that range would otherwise compute a pixel index past the edge of the backing array. The clamp means an out-of- range value is simply drawn at the plot's edge instead of causing an error - the second demo plot shows this directly with a series that deliberately overshoots its configured range. Notes and limitations - Fixed series cap of 8 per CPlotEngine instance (PLOTENGINE_MAX_SERIES). Raise the #define in the header if you genuinely need more; it is a fixed array, not a dynamic list, to keep the internal storage simple. - AddPoint resizes the series arrays on every call, which is O(n) per point. For a series with more than a few dozen points that you already have as an array, build it once and call SetSeriesData instead. - Autoscale always includes zero in the y range so bar series never appear to float from an arbitrary baseline. Turn autoscale off and set your own range if that is not the behaviour you want for a non-bar plot. - This is a static snapshot renderer: call Render() again after changing data to redraw. There is no automatic redraw on a timer or on new ticks - wire that up yourself in an indicator or EA's OnTimer/OnTick if you need a live chart. - Chart objects created by Create() are ordinary chart objects and persist after the script that created them ends, exactly like any drawing tool. Remove them explicitly (Destroy() or right-click > Remove) when you no longer need them.

Script · MT5 · v1.0 · Free

About Bitmap Plot Engine

Bitmap Plot Engine is a script for MetaTrader 5. MQL source code included.

Files in the download: PlotEngine.mq5.mqh, PlotEngine.txt, PlotEngineDemo.ex5, PlotEngineDemo.mq5.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Trend · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria