Loading…

Apply Template To All Charts

Re-applying a house template across a dozen open charts after tweaking an indicator setting, or restoring a clean look before a screenshot, is normally one right-click per chart. This script does it in one pass: name the template once, run it, and every open chart gets it. Two things about ChartApplyTemplate make a naive version of this script unreliable, and both are handled deliberately here. The first is that the call is asynchronous. A true return means the request was accepted into that chart's own message queue, not that the template has actually been painted yet. The per-chart result this script reports is therefore worded as "queued", not "applied", and the real result can land a moment later - sometimes visibly after this script has already finished and the journal has stopped updating. Do not read a queued result as a confirmed one; check the charts themselves afterwards. The second, more serious trap is what applying a template does to the chart it lands on: it reloads that chart, which unloads whatever program is running there - including this very script, if it is the one being retemplated. A script that processed charts in a simple list order could retemplate its own chart partway through and never reach the charts still queued after it. This script processes every other chart first, prints the full summary, and only then applies the template to the chart it is running on, as the last thing it does. If that final call is the one that ends the script, everything before it has already been reported. Notes and limitations - A "queued" result is not proof the template was applied. It only means the chart accepted the request; the actual repaint happens on that chart's own schedule and this script cannot wait for it. - The chart running this script is always done last, even if its natural position in the chart list would put it earlier. This is deliberate, not a bug in the ordering. - If the last, self-chart call is the one that reloads the chart, that final journal line may never appear even though the template did apply successfully - check the chart, not just the log. - A template loaded on an Expert Advisor's chart can carry its own EA and input settings, which will replace what was running there. Save a backup template of the original setup first if that matters. - The chart walk is capped at 200 charts as a defensive limit.

Script · MT4 · v1.0 · Free

About Apply Template To All Charts

Apply Template To All Charts is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Template name and Confirm first. MQL source code included.

Files in the download: ApplyTemplateAll.ex4, ApplyTemplateAll.mq4, ApplyTemplateAll.txt.

Settings

SettingDefaultWhat it does
Template nameTemplate name, with or without .tpl (required)
Confirm firsttrueAsk for confirmation before applying

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: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria