Modal Confirmation Dialog
MQL4's OnChartEvent is single-threaded and returns immediately - nothing in it can pause and wait for a user's answer the way a desktop UI's modal dialog does. "Blocking-style" here means the library owns the dialog's open/ closed state and the user's answer; the host program's dangerous action waits for a later PollResult() == MCD_RESULT_CONFIRMED instead of assuming it is safe to act the instant Show() returns. Show() only opens the dialog, it never waits. The dimmed backdrop is a real, full-chart OBJ_RECTANGLE_LABEL, not just a cosmetic tint - it is clickable, and HandleClick() treats a click that lands on it the same as Cancel, the convention most modal dialogs use for "clicked outside the dialog". This means a stray click anywhere on the chart while the dialog is open is consumed by the backdrop rather than reaching whatever the panel normally has underneath, so the dangerous action cannot be accidentally triggered by something behind the dialog while it is showing. PollResult() does not reset itself - a caller must call ClearResult() explicitly once it has acted on the answer. This is deliberate: a panel that polls from both OnChartEvent and a periodic OnTick check cannot then miss a result that landed between the two, since the result value simply sits there until the caller says it has been consumed. Notes and limitations - This is not a true blocking dialog - nothing in MQL4 can be. The dangerous action must be written to wait for PollResult(), not to run immediately after Show() the way a genuinely blocking modal call would allow. - The backdrop is sized to a fixed 4000x3000 pixels deliberately larger than any realistic chart window, so it always fully covers the chart without needing to read CHART_WIDTH_IN_PIXELS/CHART_HEIGHT_IN_PIXELS on every resize - it is simply oversized and clipped by the chart's own edges. - Only one dialog can usefully be open at a time per instance; a second Show() on an already-open instance just replaces the message and keeps it open, it does not stack a second dialog. - No trading and no money at risk - the demo never performs the action a real "Close All" confirmation would gate, it only exercises the dialog.
Script · MT4 · v1.0 · Free
About Modal Confirmation Dialog
Modal Confirmation Dialog is a script for MetaTrader 4. It has 1 setting, such as Prefix. MQL source code included.
Files in the download: ModalConfirmationDialog.mqh, ModalConfirmationDialog.txt, ModalConfirmationDialogDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Prefix | MCDDemo_ | Object-name prefix for this demo's objects |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code