MetaEditor Help

Intellectual Control

Different tools, from the auto substitution of names and tips of functions to bookmarks and hotkeys, are implemented in MetaEditor for the convenient development of programs. These means allow to quicken up the process of the source code writing, conveniently navigate through it and avoid mistakes.

The following functions are described in this section:

Any changes made to the source code can be rolled back using the "Undo Undo" command in the "Edit" menu, in the "Standard" toolbar or using the "Ctrl+Z" key combination.

Auto Substitution of Function Names

It is the possibility of viewing the list of variants of names of built in and user functions, constants, variables, members of classes, keywords, etc. The variants of substitution are determined by the first typed symbols. Opening of this list is performed automatically when writing the source code. In order to manually open this list one should use the "List Names List Names" command in the "Edit" menu, in the "Standard" toolbar or use the "Ctrl+Space" key combination after the first symbols of the name are typed:

List of Names

Further it is only left to choose the necessary variant using the "Arrow Up" and "Arrow Down" keys and then press the "Enter" key. The choice can be made using the mouse as well. If one continues to type the letters of the function name, the list of possible variants of substitution will get shorter.

Information about Parameters

This feature allows viewing parameters of a chosen function and their types. In order to open this information one should execute the "Parameter Info Parameter Info" command in the "Edit" menu, in the "Standard" toolbar or use the "Ctrl+Shift+Space" key combination. The commands must be executed when the mouse cursor is within the brackets where the parameters are specified. The pop-up help line containing the parameters will appear below the function as soon as you do it:

Information about Parameters

Let's consider the displayed information in the example shown in the screenshot above:

  • [1 of 2] — it means that there are two variants of parameters specification for the function. In order to switch between them one should use the "Arrow Up" and "Arrow Down" keys or click with the left mouse button on the tip line;
  • bool — it indicates the type of the values returned by the function;
  • ObjectSetInteger — the name of the function;
  • (long chart_id, ... ) — the enumeration of possible parameters of the function, the type of the parameter is specified before each of them ("long" in this case). The parameter where the mouse cursor currently is displayed bold.

Go To Definition

This function allows to automatically move to the declaration or definition of the selected function or variable. If the definition or declaration is in another file, then this file will be opened and the mouse cursor will be moved to the corresponding position. This function also allows to move to the include files (#include).

In order to go to definition one should place the cursor at a parameter and execute the "Go To Definition Go To Definition" command in the "Edit" menu, in the "Standard" toolbar or use the"Alt+G" key combination. In order to go to an include file one should place the cursor at the line where it is declared and execute one of the commands mentioned above.

List of Functions

This feature allows to open the list of all declared functions in the current file. In order to open the list one should execute the "List Functions List Functions" command in the "Edit" menu, in the "Standard" toolbar or use the "Alt+M" key combination.

List of Functions

The parameters that were specified for the functions are shown in brackets. By clicking with the left mouse button or using the "Enter" key one can go to the definition of the selected function in the file. Each type of the function has its own icon in the list:

  • Function — function;
  • Fucntion of Events Handling — function of events handling (On*);
  • Public Method of Class — public method of a class;
  • Protected Method of Class — protected method of a class;
  • Private Method of Class — private method of a class;

Comments Inserting

Different commands for working with comments in the source code are implemented in the "Edit" menu and in the "Standard" toolbar:

  • Function Header Function Header — insert a ready field for a comment to a function;
  • Block Comment Block Header — insert symbols of a single-line comment;
  • Comment Lines Comment Lines — insert the "//" comments in the beginning of each selected line;
  • Uncomment Lines Uncomment Lines — remove the "//" comments from the beginning of each selected line.

The execution of the "Block Comment Block Comment" or the usage of the "Ctrl+/" key combination inserts the symbols of a single-line comment at the indicated position:

//---

If the "Function Header Function Header" or the "Ctrl+." key combination is used then the workpiece for a comment to the function will be inserted at the indicated position:

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

Additional Functions for Code Editing

The "Additional" submenu of the "Edit" menu contains several commands for easier editing a source code:

  • Increase Line Indent Increase Line Indent — this command allows inserting three spaces (or a tab character) at the beginning of selected lines. To insert spaces in a single line, put the mouse cursor at the beginning of the line and execute this command (or press the "Tab" hotkey). To insert spaces in several lines, select the whole lines.
  • Decrease Line Indent Decrease Line Indent — this command allows removing three spaces (or a tab character) from the beginning of selected lines. The same action can be performed using the Tab+Shift key combination.
  • Make Uppercase Make Uppercase — this command makes all the letters of a selected phrase uppercase. The same action can be performed using the Ctrl+Shift+U key combination.
  • Make Lowercase Make Lowercase — this command makes all the letters of a selected phrase lowercase. The same action can be performed using the Ctrl+U key

Working with Bookmarks

Bookmarks are intended for denoting necessary lines in the source code for further convenient navigation through them. The commands for working with bookmarks are located in the "Bookmarks" submenu of the "Edit" menu, in the "Standard" toolbar and in the context menu of the text. There are the following commands for working with them in MetaEditor:

  • Toggle Bookmark Toggle Bookmark — toggle or untoggle a bookmark on the current line of the edited file depending on its current state. The same action can be performed using the "Ctrl+F2" key combination;
  • Next Bookmark Next Bookmark — move to the next bookmark in the current source code. The same action can be performed using the "F2" key;
  • Previous Bookmark Previous Bookmark — move to the previous bookmark in the source code. The same action can be performed using the "Shift+F2" key combination;
  • Clear All Bookmarks Clear All Bookmarks — clear all bookmarks from the current file. The same action can be performed using the "Ctrl+Shift+F2" key combination.

MetaEditor includes the feature of working with named bookmarks - bookmarks that have a one-digit identifier assigned. To set such a bookmark press a 0-9 digit key holding the "Ctrl" key. To go to a previously set key, press the corresponding digit key while holding the "Alt" key. Name bookmarks make the navigation through a source code much easier.

Go To Line

To quickly go to a line in the code of the current file, one can use the "Go To Line Go To Line" command of the "Edit" menu or the "Standard" toolbar. The following window is opened as soon as this button is pressed:

Go To Line

The range of lines containing code in the file is specified in the window. To go to a line, one should indicate its number and press the "OK" button.

Snippets

To make writing of a code easier, MetaEditor includes a possibility of inserting snippets — small template fragments of code that describes a structure element of the MQL4/MQL5 language. To insert a snippet you should type a special keyword. As soon as you do it, the cursor will change to A snippet can be inserted, what means that a snippet can be inserted. The next step is to press the "Tab" key.

For example, to insert a class declaration, type the keyword "class" and press the "Tab" key:

Example of snippet

As soon as you do it, the keyword will be replaced with a class declaration. To switch between the active fields of a snippet (in this case? they are the name, constructor and destructor of a class), use the "Tab" and "Shift+Tab" keys.

If you change an active field, the other fields of the snippet will be changed automatically. For example, if you change the class name, the names of the constructor and destructor will be changed automatically; if you change a variable name in one of the expressions of a "for" operator, the names of variables in its other expressions will also be changed.

The system of working with snippets recognizes structures, classes, enumerations, methods and functions if your press the "Ctrl+Enter" key combination. At that the cursor must be within description of the corresponding structural element. As soon as that combination is pressed, the user will be able to move between members (for classes, structures and enumerations) and arguments (for methods and functions) using the "Tab" and "Shift+Tab" keys as well as to edit them together as described above.

At this moment, the following snippets are supported:

Keyword

Value

#import

Declaration of an import.

OnBookEvent

Event handler OnBookEvent.

OnCalculate

Event handler OnCalculate.

case

The "case" selector.

OnChartEvent

Event handler OnChartEvent.

class

Declaration of a class.

OnDeinit

Event handler OnDeinit.

do

Declaration of the "do while" loop.

enum

Declaration of an enumeration.

for

Declaration of the "for" loop.

if

Declaration of the "if" condition.

else

Declaration of the "else" condition.

OnInit

Event handler OnInit.

OnStart

Event handler OnStart.

struct

Declaration of a structure.

switch

The "switch" selector.

OnTester

Event handler OnTester.

OnTesterInit

Event handler OnTesterInit.

OnTesterPass

Event handler OnTesterPass.

OnTesterDeinit

Event handler OnTesterDeinit.

OnTick

Event handler OnTick.

OnTimer

Event handler OnTimer.

OnTrade

Event handler OnTrade.

OnTradeTransation

Event handler OnTradeTransation.

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>

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