Panel Drag Manager
A dashboard panel nailed to one corner works until the user wants it somewhere else on the chart, and MQL4 has no drag-start/drag-end event to build that on - only object clicks (which carry no pixel coordinate) and raw mouse-move samples once CHART_EVENT_MOUSE_MOVE is switched on. This library reconstructs a drag entirely from mouse-move samples: a move sample with the left button held whose pixel position lands inside the title bar's current rectangle opens a drag; every subsequent held-button sample repositions the panel by the fixed offset recorded at grab time; the first sample with the button no longer held ends the drag, snaps the result to a pixel grid, clamps it to stay fully on-chart, and writes it to a GlobalVariable. Mouse-move coordinates from the platform are always reported in top-left-origin pixels regardless of which corner the panel's own objects are anchored to (CORNER_RIGHT_UPPER, etc.), so every hit-test and every reposition first converts the panel's corner-relative offset into that same top-left frame before comparing it against the mouse position - skipping that conversion is the naive mistake that makes a panel anchored to a non-default corner drag in the wrong direction or stop responding to clicks near its true screen position. Notes and limitations - This library manages only the title-bar drag handle itself. A caller with additional panel objects (body, buttons, labels) must reposition them from GetX()/GetY() inside its own OnChartEvent, typically once per drag-move call. - ChartSetInteger(CHART_EVENT_MOUSE_MOVE, true) is enabled automatically by Create() - be aware this increases the volume of OnChartEvent calls the host program receives while the mouse moves over the chart at all, not only while dragging this panel. - Persistence uses two plain GlobalVariables per persistKey (suffixed _x/_y), which are shared terminal-wide - use a unique persistKey per panel to avoid collisions with other programs. - No money is at risk in the demo. It only manipulates chart objects and GlobalVariables and never sends an order.
Script · MT4 · v1.0 · Free
About Panel Drag Manager
Panel Drag Manager is a script for MetaTrader 4. MQL source code included.
Files in the download: PanelDragManager.mqh, PanelDragManager.txt, PanelDragManagerDemo.mq4.
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: Grid · Dashboards & Scanners · MT4 Script · MQL4 Source Code