Loading…

Annotation Layer Manager

MQL4 has no concept of a layer. Every ObjectCreate call produces one independent, unrelated name, so an indicator that draws a "zones" overlay and a separate "labels" overlay - and wants to hide either one from a single input, or guarantee zones always sit visually behind labels regardless of the order they were created in - ends up re-inventing the same tracking arrays and toggle logic project after project. This header centralises that bookkeeping. Create a named layer, track an already-drawn object under it, and from then on the whole layer moves together: AlmSetLayerVisible() shows or hides every member object in one call using OBJPROP_TIMEFRAMES (OBJ_ALL_PERIODS / OBJ_NO_PERIODS) rather than deleting and recreating anything, so toggling is cheap and never disturbs an object's position, colour or text. AlmSetLayerZOrder() restacks every member object to a new OBJPROP_ZORDER in one call, so relative stacking within a layer never needs recomputing by hand. AlmDeleteLayer() removes every object the layer owns and forgets the layer itself, and AlmDeinitAll() is the one call an OnDeinit needs to guarantee no orphaned drawing survives a reload. The layer registry is a plain array of structs, each holding a fixed-growth dynamic array of tracked object names - safe here because layers are only ever grown or modified in place, never assigned whole (struct assignment with a dynamic array member is the unsafe pattern to avoid in MQL4, not array growth itself). Notes and limitations - This library only manages objects the caller has already created and explicitly tracked with AlmTrackObject - it does not scan the chart for pre-existing objects to adopt into a layer automatically. - Visibility is implemented via OBJPROP_TIMEFRAMES, which hides an object from the CURRENT chart's period the same way as every other period when set to OBJ_NO_PERIODS - a hidden layer is hidden on every timeframe the chart is switched to, not just the one it was hidden on. - Z-order is a per-object chart property; two layers with the same z-order interleave in whatever order MetaTrader itself resolves ties, which this library does not attempt to control further. - Deleting a layer deletes its member objects from the chart permanently - there is no undo.

Script · MT4 · v1.0 · Free

About Annotation Layer Manager

Annotation Layer Manager is a script for MetaTrader 4. MQL source code included.

Files in the download: AnnotationLayerManager.mqh, AnnotationLayerManager.txt, AnnotationLayerManagerDemo.mq4.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria