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:
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:
If an option list is too large, type a few more letters of the function name. To call the list manually, click List Names in the Edit menu or Ctrl+Space after entering the first characters of the name.
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 in the Edit menu or Ctrl+Shift+Space. Info on parameters and type of a function return value is displayed in tooltips:
The following info is displayed for the function in the image above:
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" 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.
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.
This tool allows you to see a list of all declared functions in the current file. To open the list, click List Functions in the Edit menu or Alt+M.
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:
To simplify working with comments in the program code, use a number of functions in the Edit menu and Standard toolbar:
The Block Comment command (Ctrl+/) inserts single-line comment characters in the current position:
//--- |
The Function Header (Ctrl+.) inserts a comment blank for a function in the current cursor position:
//+------------------------------------------------------------------+
|
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:
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:
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.
To quickly jump to any line of code in the current file, click Go to Line in the Search menu or press Ctrl+G. The following window is opened:
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 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 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.
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. |
Commands from the Edit – Insert menu allow to quickly insert resource files and thus can facilitate application development.
Inserts in the current position the #property directive and immediately opens the list of all program properties available in the language.
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" |
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"
|
Add a description of the imported functions between the directives.
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> |
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" |
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.
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.
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.
//+------------------------------------------------------------------+
|
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]=
|
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:
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.
You can enable/disable tracking by using the corresponding toolbar command or via editor settings.