Today we are going to create a simple script for Metatrader 5 that will instantly delete all objects on the active chart window. If you are experimenting with graphical objects or if you are using indicators that do not redraw graphical objects automatically, the script will save your time.

First, open MetaEditor 5 and press the "New" button. The MQL5 Wizard will start up. Select "Script" and press "Next":

Delete all Objects Script for Metatrader 5

Now give a name to your script and fill your copyright information - author and website, then press "Next":

Delete all Objects Script for Metatrader 5

A window with the code for your script will appear. Our script is probably the easiest one, because it contains only one line of code. Add this line of code as shown on the picture:


ObjectsDeleteAll(0);
//---


Now press the "Compile" button and make sure that no errors appear in the debugging window below:

Delete all Objects Script for Metatrader 5

The script is saved in your Scripts folder. Now open Metatrader 5 terminal and add some graphical objects to the chart. Now open the navigator window, select your script and drag it to the chart window. All graphical objects will instantly disappear. It's much faster than doing it by hand, isn't it?

Delete all Objects Script for Metatrader 5

As you can read in the MQL5 reference guide, the ObjectsDeleteAll function removes all objects from the specified chart. You can also specify such variables as chart id, type of object that will be removed, etc. In our case "0" means the current chart. If you want to learn more about this function, search for "ObjectsDeleteAll" in the MQL5 reference guide.

0 comments

Post a Comment