MetaEditor HelpDeveloping programsIntelligent management

Intelligent management

For ease of programming, MetaEditor provides various tools from auto substitutions of names and tips to functions up to bookmarks and hot keys. These tools allow you to speed up the process of code writing, make navigation easier and help prevent errors.

This section describes the following functions:

Any changes can be undone by executing Undo Undo command in the Edit menu or on the Standard toolbar, or by pressing Ctrl+Z.

Auto substitution of function names #

When you write the program code, MetaEditor automatically offers possible substitution options for built-in and custom functions, constants, variables, class members, keywords, etc. This speeds up the code writing. For example, as soon as you enter the first letters of the function name, a list of functions with suitable names immediately opens. Select the appropriate option with keyboard arrows and press Enter:

Name list

If an option list is too large, type a few more letters of the function name. To call the list manually, click List Names List Names in the Edit menu or Ctrl+Space after entering the first characters of the name.

Information on parameters #

You can see the function signature right when writing the code without opening the language help. To do this, place the cursor after the opening parenthesis which starts the description of the function parameters, and then click Parameter Info Parameter Info in the Edit menu or Ctrl+Shift+Space. Info on parameters and type of a function return value is displayed in tooltips:

Information on parameters

The following info is displayed for the function in the image above:

  • [1 of 2] means that the function has call options with different parameters. To switch between them, use the arrows on the keyboard or left-click on the prompt line.
  • bool specifies the value type returned by a function.
  • ObjectSetInteger – function name.
  • (long chart_id, ... ) – enumeration of possible function parameters, a type is specified before each parameters (here it is “long”). The parameter the cursor is currently located on is displayed in bold.

Jump to definition #

This tool enables a quick navigation to the definition (implementation) of the selected class type or element. Place the cursor over its name and select Go to Definition "Go to Definition" in the context menu or press “Alt+G”. If the definition is located in another file, it will be opened and the cursor will be placed in its corresponding position.

The function also enables the navigation to include files. To do this, place the cursor anywhere on the line where the include is declared (the #include directive) and execute the above command.

Jump to declaration #

This tool enables quick navigation to a variable or class member declaration. Place the cursor over the element name and select "Go to Declaration" in the context menu. If the declaration is located in another file, it will be opened and the cursor will be placed in its corresponding position.

List of functions #

This tool allows you to see a list of all declared functions in the current file. To open the list, click List Functions List Functions in the Edit menu or Alt+M.

List of functions

The function parameters are indicated in parentheses to the right of its name. To go to the function, click on its name in the list. Each type of functions in the list is marked by its icon:

  • Function – function.
  • Event handling function – event handling function (On*).
  • Public class method – public class method (public).
  • Protected class method – protected class method (protected).
  • Private class method – private class method (private).

Inserting comments #

To simplify working with comments in the program code, use a number of functions in the Edit menu and Standard toolbar:

  • Function Header Function Header – insert a comment blank for a function;
  • Block Comment Block Comment – insert symbols of a single-line comment;
  • Comment Lines Comment Lines – insert "//" comments at the beginning of each selected line;
  • Uncomment Lines Uncomment Lines – remove "//" comments from the beginning of each selected line.

The Block Comment Block Comment command (Ctrl+/) inserts single-line comment characters in the current position:

//---

The Function Header Function Header (Ctrl+.) inserts a comment blank for a function in the current cursor position:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

Additional code editing features #

You can easily move code fragments from one part of the program to another. To do this, highlight the fragment and drag it to the necessary position (Drag'n'drop).

The Advanced sub-menu of the Edit menu features a series of commands simplifying the source code editing:

  • Increase Line Indent Increase Line Indent – insert three spaces (tab symbol) at the beginning of the selected lines. To insert spaces in a single line, position the cursor at its beginning. To insert spaces in several lines, select them in full.
  • Decrease Line Indent Decrease Line Indent – remove three spaces (tab symbol) at the beginning of the selected lines. A similar action is performed by the Tab+Shift hot key.
  • Make Uppercase Make Uppercase – change all characters of a selected phrase to uppercase. A similar action is performed by the Ctrl+Shift+U hot key.
  • Make Lowercase Make Lowercase – change all characters of a selected phrase to lowercase. A similar action is performed by the Ctrl+U hot key.

Working with bookmarks #

Bookmarks allow you to quickly jump to different parts of a code. Mark the required lines with bookmarks and navigate between them using the Edit – Bookmarks menu commands and the context menu of a source code:

  • Toggle Bookmark Toggle Bookmark – enable/disable a bookmark on the current line depending on its current status. The same can be done using the Ctrl+F2 hot key;
  • Next Bookmark Next Bookmark – move to the next bookmark in the current code. The same can be done by F2 key;
  • Previous Bookmark Previous Bookmark – move to the previous bookmark in the current code. The same action can be performed by pressing Shift+F2 hot key;
  • Clear All Bookmarks Clear All Bookmarks – remove all bookmarks from the current code. The same can be done by the Ctrl+Shift+F2 hot key.

MetaEditor also features named bookmarks – the ones having a digital ID assigned to them. To set such a bookmark, click 0-9 while holding Ctrl. To go to the previously set tab, press the corresponding number while holding Alt.

Go to Line #

To quickly jump to any line of code in the current file, click Go to Line Go to Line in the Search menu or press Ctrl+G. The following window is opened:

Go to Line

The window displays the range of lines with a code in the current file. To go to the line, enter its number and click OK.

Snippets #

Snippets are small template fragments of a source code that describe a certain MQL4/MQL5 language construction. They make it easier and faster to write a source code. For example, they allow you to quickly add a workpiece to a program code to describe a class or a loop. To do this, simply enter a key word – 'class' or 'for'. The cursor changes to Snippet can be added meaning that it is now possible to insert a snippet. Press Tab and a blank for class or 'for' loop is inserted to a program code according.

Sample snippet

In order to switch between active snippet fields (here, these are name, class constructor and destructor), use Tab and Shift+Tab.

Changing one active field automatically changes the rest. For example, when changing the class name, constructor and destructor names are changed automatically as well. When changing a variable name in one of the 'for' loop expressions, the variables in its other expressions are changed as well.

The system of working with snippets also recognizes already described structures, classes, enumerations, methods and functions. Place the cursor within the description of the corresponding structure and press Ctrl+Enter. After that, you can navigate between members (classes, structures and enumerations) and arguments (methods and functions) using Tab and Shift+Tab keys and edit them together as described above.

The following snippets are supported at the moment:

Keyword

Value

#import

Import declaration.

OnBookEvent

OnBookEvent handler.

OnCalculate

OnCalculate handler.

case

'case' selector.

OnChartEvent

OnChartEvent handler.

class

Class declarations.

OnDeinit

OnDeinit handler.

do

Declaration of the 'do while' loop.

enum

Declaration of enumeration.

for

Declaration of the 'for' loop.

if

Declaration of the 'if' condition.

else

Declaration of the 'else' condition.

OnInit

OnInit handler.

OnStart

OnStart handler.

struct

Structure declaration.

switch

'switch' selector.

OnTester

OnTester handler.

OnTesterInit

OnTesterInit handler.

OnTesterPass

OnTesterPass handler.

OnTesterDeinit

OnTesterDeinit handler.

OnTick

OnTick handler.

OnTimer

OnTimer handler.

OnTrade

OnTrade handler.

OnTradeTransation

OnTradeTransation handler.

while

Declaration of the 'while' loop.

Inserting resources #

Commands from the Edit – Insert menu allow to quickly insert resource files and thus can facilitate application development.

Options as #property

Inserts in the current position the #property directive and immediately opens the list of all program properties available in the language.

BMP/WAV as #resource

To add an image or a sound file to the program resources, run this command and select a BMP or WAV file (the appropriate file must be located in the\ MQL5 directory). The #resource directive with the proper path to the selected file will be inserted at the current position of the program.

#resource "\\Images\\image.bmp"

DLL/EX5 as #import

You can import functions from an external library or an EX5/EX4 file by executing this command and selecting the appropriate file (the file must be located in the\ MQL5 directory). A pair of #import directives with the proper path to the selected file will be inserted at the current position of the program.

#import "..\Experts\SendNotification.ex5"
 
#import

Add a description of the imported functions between the directives.

MQH as #include

To insert an include file to the program code, run this command and select an MQH file (the appropriate file must be located in the \MQL5 directory). The #include directive with the proper path to the selected file will be inserted at the current position of the program.

#include <Arrays\Array.mqh>

A set of parameters as #property

To insert to a program code a set of parameters for Expert Advisor testing, run this command and select a SET file (the appropriate file must be stored in the\ MQL5 directory). The #property directive with the proper path to the selected file will be inserted at the current position of the program.

#property tester_set "\\Profiles\\Tester\\Moving Average.set"

Data and time as YYYY.MM.DD hh:mm:ss / UNIX time

Use this command to insert the date and time in the required format, into your code. The command selection opens an interactive calendar. Select the date and time in the calendar, and it will be inserted into the current program position in the selected format.

Inserting date and time into code

 

Color as clrColor

Use this command to easily insert the color in the required format, into your code. A click on the command opens an interactive palette. Select a color from the palette, and it will be inserted into the current position in the CLRColor format used in MQL5 functions.

Inserting color into code

File as Binary Array

This command allows you to add to the program text any file in the form of a binary array. Run the command and select the desired file (the appropriate file must be located in the\ MQL5 directory). A char array will be inserted at the current position of the program.

Among others, this function allows you to transfer chart templates with Expert Advisors or indicators: insert your template in the program code as an array, and save it to disk then using the FileSave function. After that the template can be applied on the desired chart using the ChartApplyTemplate function.

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- a template file as a binary array
   unsigned char my_template[]=
     {
      0xFF,0xFE,0x3C, ... ,0x00 // the data array in this example is shortened
     };
//--- saving and applying the template
   if(FileSave(“my_template.tpl”,my_template))
     {
      Print("Custom template saved in \\MQL5\\Files");
      if(ChartApplyTemplate(0,"\\Files\\my_template.tpl"))
         Print("Custom template applied to the current chart");
      else
         Print(“Failed to apply custom template”);
     }
   else
      Print(“Failed to save custom template”);
  }

CSV as a text array

To add data from a text file to the program code, run this command and select a TXT or CSV file (the appropriate file must be located in the\ MQL5 directory). A string array of the required dimension containing data from the file will be inserted at the current program position:

string data[][3]=
  {
   {"name1","value1"},
   {"name2","value2"},
   {"name3","value3"}
  };

Text conversion #

The MetaEditor allows you to easily convert the format of source data. Open the desired file, select text in it and execute one of the commands from the Edit – Convert menu:

  • ASCII to HEX
  • ASCII to Base64
  • ASCII to Binary Array
  • HEX to ASCII
  • Base64 to ASCII

Clipboard tracking #

The clipboard tracking manager improvements the source code convenience by enabling quick access to the last used data. Press Alt+V anywhere in the source code, select any of the previously copied lines from the menu, and it will be pasted in place.

To paste lines from the clipboard history, press ALT+V or use the toolbar

You can enable/disable tracking by using the corresponding toolbar command or via editor settings.