Loading…

Chart Management Toolkit

MQL4 has had ChartFirst/ChartNext/ChartOpen/ChartSetInteger and the rest of the unified chart API since build 600, but nothing wraps them into one reusable set of helpers - most scripts that touch charts re-implement the same enumerate-and-configure loop from scratch. This header does that once: CMT_EnumerateCharts walks the ChartFirst/ChartNext linked list and returns every open chart id (MQL4 has no ChartsTotal() count function at all, unlike some of its other MODE_*-style counters, so walking the list is the only way to get a terminal-wide count), CMT_OpenChart/ CMT_CloseChart handle lifecycle, CMT_SetSymbolPeriod/CMT_ApplyTemplate/ CMT_ConfigureAppearance handle configuration, and CMT_BringToFront cycles which chart sits at the front of the window stack. Read this plainly before treating it as a window-arranging tool: NEITHER MQL4 NOR MQL5 can move or resize the actual OS chart window. There is no built-in function for it on either platform - MQL5's CHART_FLOAT_LEFT/TOP properties only affect a chart already undocked into its own floating window, and going further would require user32.dll/SetWindowPos, which house style forbids outright (no DLL imports, no exceptions). What this header actually provides toward "arranging" charts is CMT_SuggestGridPosition - pure arithmetic that computes a row/column slot for a chart index in an N-column grid, for the trader to apply BY HAND (Window > Tile, or manual dragging) - and CMT_BringToFront, which cycles which chart is frontmost. Advertise this toolkit as chart CONFIGURATION and front-window cycling, not as automated window tiling, because it genuinely is not that. Notes and limitations - Cannot move or resize chart windows - see the full description above. This is a hard platform limitation, not a gap in this header. - CMT_CloseChart refuses chart id 0 outright, since 0 means "the current chart" to most Chart* functions - a loop variable accidentally left at its zero default would otherwise silently close the chart the script itself is running on. - CMT_EnumerateCharts is capped at CMT_MAX_CHARTS (64) - raise it in the header if a terminal genuinely has more charts open at once. - CMT_ApplyTemplate requires the named .tpl file to already exist in the terminal's templates folder; it does not create or validate templates. - ChartOpen()'d charts are NOT automatically closed by this header if a script is interrupted (e.g. Stop button mid-run) before reaching its own CMT_CloseChart call - the demo's own charts are cleaned up in the ordinary flow, but a caller building a longer-lived tool should handle its own cleanup on early exit.

Script · MT4 · v1.0 · Free

About Chart Management Toolkit

Chart Management Toolkit is a script for MetaTrader 4. It has 1 setting, such as Grid columns. MQL source code included.

Files in the download: ChartManagementToolkit.mqh, ChartManagementToolkit.txt, ChartManagementToolkitDemo.mq4.

Settings

SettingDefaultWhat it does
Grid columns3Column count used by the CMT_SuggestGridPosition demonstration

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