Loading…

Import CSV As Chart Objects

Hand-drawing the same set of levels on several charts, or restoring them after a template got overwritten, is slow and invites a mis-click. This script reads them from a CSV instead: one row per object, seven fixed columns, a plain text file a trader can write in a spreadsheet or a script can generate. The trap in the naive version of an importer like this is what one bad row does to the other three hundred. A script that calls StrToTime or StringToDouble on every field and trusts the result blindly will either place an object at time zero and price zero when a field is blank, or throw away the whole file the moment one line does not parse. This script validates every field the row's type actually needs before creating anything, and a row that fails validation - wrong column count, a type it does not recognise, a price or time or colour that will not parse - is skipped and reported with its 1-based line number in the Experts log. The run continues. A typo on line 47 costs one object, not the import. The second decision worth naming is what happens when the object already exists. Every object this script creates is named InpPrefix plus the CSV name, never the bare name, specifically so a second run of the same file does not collide with anyone else's drawings. But a second run of an updated file - the same objects, moved prices - still needs somewhere to put the new geometry, and MetaTrader has no "move this object" call that also changes its type. So an existing object under the generated name is deleted and recreated from the row's current values before the new one is drawn. Skipping it would leave stale lines on the chart forever; letting it pile up would leave duplicates. Delete-then-recreate is the only option that makes a re-run an update instead of either of those. This script is the read half of a pair. Export Chart Objects To File (S070) writes chart objects out in exactly this seven-column schema, so a set of levels drawn once, exported, and imported here round-trips without any reformatting in between. The two scripts were built to the same column layout on purpose. Notes and limitations - Only five object types are supported: HLINE, VLINE, TREND, RECT and TEXT. Anything else in the type column - Fibonacci tools, arrows, channels - is reported as an unknown type and skipped. This is a deliberate limit, not an oversight: the schema only carries the coordinates these five types need, and stretching it to cover tools with different parameter shapes would break the fixed seven-column contract the whole format depends on. - Cosmetic properties outside the schema - line style, width, font, the "back" flag - are not set. Every imported object comes back solid, in the colour the file specifies, at the platform's default width and font. - Overwriting an existing object (same prefix plus name) deletes and recreates it, which puts it at the back of the object z-order relative to objects that were not touched this run. There is no MetaTrader call that updates an object's geometry in place while preserving stacking order. - A malformed line - wrong column count, unrecognised type, a price, time or colour that will not parse - is skipped and logged with its line number. It does not stop the rest of the file importing. - This script only draws what the file describes. It cannot recover cosmetic detail the file never captured in the first place.

Script · MT5 · v1.0 · Free

About Import CSV As Chart Objects

Import CSV As Chart Objects is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as File name and Prefix. MQL source code included.

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

Settings

SettingDefaultWhat it does
File namechart_objects.csvFile to read, from MQL5\Files
Prefiximp_Prefix applied to every object 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: Trend · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria