Chart Object Wrapper
Two habits cause most chart-object bugs in home-grown indicators and panels. The first is creating an object without checking whether the name is already taken - ObjectCreate returns false on a duplicate name and the existing object is left exactly where it was, so code that assumes creation always succeeds ends up moving nothing while believing it moved something. Every create function in this header checks ObjectFind first and returns false rather than silently doing nothing useful. The second is cleanup. OnDeinit routines that loop ObjectsTotal and delete everything, or everything matching a loose substring, regularly take out objects a different indicator or the user drew by hand on the same chart. The only bulk-delete function here, ChObjDeleteByPrefix, requires an explicit prefix and only ever removes names that start with it - nothing else on the chart is at risk, which the demo proves directly by planting a foreign object outside the prefix and showing it survives the cleanup call. The header also draws a firm line between the two families of chart object. Corner-anchored objects - label, button, rectangle label, edit - are positioned in pixels from a corner and moved with ChObjMove. Price/time objects - h-line, v-line, trend line, arrow - are positioned in chart coordinates and the horizontal line has its own ChObjMovePrice, because calling the wrong mover on the wrong family is a common source of "nothing happens" reports. Visibility uses OBJPROP_TIMEFRAMES rather than delete/recreate, so toggling something like a panel's collapse state is cheap and does not lose the object's other properties. Notes and limitations - ChObjDeleteByPrefix matches on the start of the name only (StringFind result 0), so choose a prefix specific enough that it cannot collide with another program's naming scheme running on the same chart. - Corner-anchored and price/time objects are moved with different functions. Calling ChObjMove on a trend line, or ChObjMovePrice on a label, returns true (the property calls succeed) but has no visible effect, because those objects do not use that property for positioning. - ChObjSetVisible hides an object from every timeframe; it does not support showing an object on some timeframes and not others. - This header only wraps the object API - it does not track object state for you. A panel framework or widget library built on top of it is responsible for remembering what it created.
Script · MT4 · v1.0 · Free
About Chart Object Wrapper
Chart Object Wrapper is a script for MetaTrader 4. It draws buy and sell arrows on the chart. It has 1 setting, such as Prefix. MQL source code included.
Files in the download: ChartObjects.mqh, ChartObjects.txt, ChartObjectsDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Prefix | ChObjDemo_ | Prefix used for every object this script creates |
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 · MT4 Script · MQL4 Source Code