Delete Objects By Prefix
Any indicator or EA that draws its own objects - a signal arrow, a session box, a zone rectangle - should prefix its object names so its drawings can be told apart from a trader's manual analysis. This script is the other half of that convention: give it the prefix and it clears exactly those objects and nothing else, on the current chart or across every open chart at once. The one input that matters is required for a reason. An empty prefix is not treated as "match everything", because that would make this script a second, less obvious way to trigger a full wipe - Delete All Chart Objects already exists for that, with its own confirmation wording that says so plainly. A blank InpPrefix here is refused outright and the journal points at that other script by name, rather than quietly deleting the whole chart because a field was left empty. The count shown before deleting is a real pre-count, not an estimate. The script walks the chart's object list once to find every name starting with the prefix, so the number in the confirmation prompt is exactly the number about to be removed - not the chart's total object count, which is usually a much larger and less reassuring figure to be asked to confirm. Matching is case-sensitive, because object names are case-sensitive on both platforms. "Zone_" and "zone_" are different prefixes and will not catch each other's objects. Type the prefix exactly as the objects were named. Notes and limitations - Objects only. Indicators, Expert Advisors and scripts attached to a chart are never touched, regardless of what their short name looks like. - The match is a plain "starts with" test, not a wildcard pattern. There is no way to match a suffix or a substring in the middle of a name. - The chart walk is capped at 200 charts as a defensive limit. - Deleted objects cannot be recovered by this script.
Script · MT4 · v1.0 · Free
About Delete Objects By Prefix
Delete Objects By Prefix is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Prefix, All charts and Confirm first. MQL source code included.
Files in the download: DeleteObjectsByPrefix.ex4, DeleteObjectsByPrefix.mq4, DeleteObjectsByPrefix.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Prefix | Object name prefix to delete (case-sensitive, required) | |
| All charts | false | Apply to every open chart, not just this one |
| Confirm first | true | Ask for confirmation before deleting |
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: Buy/Sell Arrows · Trading Sessions · Alerts · MT4 Script · MQL4 Source Code