Loading…

Declarative Panel Layout Engine

Every hand-built chart panel repeats the same block of ObjectCreate / ObjectSetInteger calls per control, and the panel's actual layout - which buttons, in what order, on which row - ends up buried inside that imperative code rather than being something you can read at a glance or change without touching program logic. This header separates the two: a small text grammar describes the panel, and Build() turns that text into real chart objects in one call. The grammar is intentionally small (documented in full in the header comment) - one "row:" line per row, widgets on a row placed left to right in the order written, each widget written as type(prop=value,...). Three widget types are supported (button, label, edit) with a handful of properties (id, text, width, height, numeric, toggle). This is a new format, not a standard one, so the design choices are worth stating: a property value cannot contain a comma, parenthesis or equals sign, which keeps the parser a single linear scan with no escaping rules to document or get wrong, at the cost of not supporting punctuation inside button labels. Malformed tokens - an unknown widget type, a widget missing its required id - are skipped individually with a recorded warning rather than failing the whole panel, so one typo in a twelve-control layout does not cost the other eleven. Once built, every widget is addressed by the id from the layout text, not by the generated object name - GetText/SetText/HandleClick/HandleEndEdit all take that id, so the host program's event-handling code never compares chart-object name strings directly. Notes and limitations - No nested containers or columns within a row beyond left-to-right placement - a "row" is the only grouping concept this grammar has. - Property values cannot contain a comma, parenthesis or equals sign - a documented parser trade-off, not a bug (see the full description). - Duplicate ids are not rejected - both widgets are created, but id-based lookups (GetText, HandleClick, etc.) always resolve to whichever one was registered first. Give every widget a unique id. - This header duplicates the small set of ObjectCreate calls it needs rather than including WidgetButton.mqh / WidgetLabel.mqh / WidgetEdit.mqh / PanelFramework.mqh from elsewhere in this catalogue, per the self-containment rule every submission here follows - each download must compile standing entirely on its own. - No money is at risk in the demo. It builds on-chart controls only and never sends an order.

Script · MT5 · v1.0 · Free

About Declarative Panel Layout Engine

Declarative Panel Layout Engine is a script for MetaTrader 5. MQL source code included.

Files in the download: DeclarativePanelLayout.mq5.mqh, DeclarativePanelLayout.txt, DeclarativePanelLayoutDemo.ex5, DeclarativePanelLayoutDemo.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: MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria