Objects To MQL4 Code Generator
Drawing a level or a set of annotations by hand on a chart and then wanting that exact layout inside an EA or indicator normally means retyping every coordinate off the screen. This script reads the coordinates back instead: it walks every object on the chart and emits the actual ObjectCreate and ObjectSet calls that would recreate it, as one pasteable MQL4 function written to a text file. It covers the objects that reduce cleanly to the properties this API exposes: horizontal and vertical lines, trend lines (including by-angle), rectangles, text, arrows, labels, rectangle-label panel backgrounds, and a Fibonacci retracement's two anchor points. Multi-anchor tools - equidistant channels, triangles, Gann and Andrews Pitchfork tools, Fibonacci fan/arc/expansion - need more anchor points than OBJPROP_PRICE1/2 exposes and are deliberately left out rather than emitted half-right. Every object the generator cannot handle is named and counted in the Experts log rather than silently dropped, the same policy the companion "Export Chart Objects" script uses for CSV export. Colours are written as the raw packed integer ObjectGetInteger itself returns for OBJPROP_COLOR, so the generated line compiles and reproduces the exact colour without needing a name lookup table. Notes and limitations A Fibonacci retracement is recreated at its two anchor points with default level ratios and colours - custom level edits are not read back, since that needs per-level properties this generator does not walk. This is noted inline in the generated code as well as here. Bitmap and bitmap-label objects are skipped entirely: the object stores no reference back to the original image file path, so there is nothing to emit. Object names containing a double quote or backslash are escaped so the generated string literal still compiles; names are otherwise used exactly as drawn.
Script · MT4 · v1.0 · Free
About Objects To MQL4 Code Generator
Objects To MQL4 Code Generator is a script for MetaTrader 4. It draws buy and sell arrows on the chart and can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Output file and Function name. MQL source code included.
Files in the download: ObjectsToCodeGenerator.mq4, ObjectsToCodeGenerator.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Output file | GeneratedObjects.mq4 | Output file, written under MQL4\Files |
| Function name | RecreateChartObjects | Name of the generated function |
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 · Alerts · MT4 Script · MQL4 Source Code