Loading…

Import Chart Objects From File

Export Chart Objects To File saves a chart's annotations to a CSV. This script is the other half - it reads that file back and puts the objects on the chart, so a set of support/resistance lines, session boxes or Fibonacci levels built once can be carried to another chart, another terminal, or restored after a template got overwritten. The file format is deliberately small: type, name, a price, and for anything that needs a second point, a time and a second price and time, then a colour written as three numbers separated by semicolons rather than a single packed integer, so the colour is readable in the file without decoding it. A horizontal line only needs a price, so its row is four columns. A trend line, a rectangle or a Fibonacci retracement needs two full points, so its row is seven. The importer reads whichever shape a line actually has rather than assuming every row is the same width, which is what makes the four-column short form possible at all. The trap in the naive version of this script is what happens to an object that is already on the chart under the name the file wants to use. Silently skipping it hides that the import did nothing there; silently overwriting it destroys work the user may not have wanted touched. This script asks: Overwrite (default) deletes the old object and recreates it from the file, reported line by line so nothing changes without a line in the log to show for it. Skip leaves the existing object exactly as it is and reports that too. Overwriting a line or a box loses its position in the z-order relative to other objects, because MetaTrader has no "replace in place, keep the stacking order" call for these object types - deleting and recreating is the only way to update one, and it is an honest trade the .txt does not hide. A line in the file that does not parse - wrong number of columns, a colour that is not three 0-255 numbers, a name left blank, a type this script does not know - is skipped and reported with its line number, and the run continues. One bad line in a 200-line export should not sink the other 199. Notes and limitations - Five object types are supported: HLINE, VLINE, TREND, RECTANGLE and FIBO. These are the shapes that need only coordinates and a colour. Anything that needs a caption - OBJ_TEXT, OBJ_LABEL, an arrow with a description - is out of scope, because the shared schema has no text field; inventing one would break the four/seven-column contract this script and its exporter both rely on. - Cosmetic properties that are not part of the schema - line style, line width, "back" flag, font - are not restored. Every imported object comes back solid, width 1, in front, in the colour the file specifies. If you need exact cosmetics preserved, keep a template as well as the CSV. - Object names are used exactly as given in the file. Whatever prefix convention the exporting script applied travels with the name column; this script neither adds one of its own nor strips one. - Restored objects are left on the chart when the script finishes - they are the output, not scratch work, so this script does not clean them up the way a script drawing temporary markers would. - A malformed line is skipped and logged with its line number; it does not stop the rest of the file from importing. - This only restores geometry and colour. It cannot restore anything the original export did not capture in the first place.

Script · MT5 · v1.0 · Free

About Import Chart Objects From File

Import Chart Objects From File is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as File name, Delimiter and On duplicate. MQL source code included.

Files in the download: ImportChartObjects.ex5, ImportChartObjects.mq5, ImportChartObjects.txt.

Settings

SettingDefaultWhat it does
File nameChartObjects.csvFile to read, from MQL5\Files
DelimiterDelimiterCommaCSV column separator (must match the export)
On duplicateOnDuplicateOverwriteExisting object with the same name

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Fibonacci · Support & Resistance · Trading Sessions · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria