How do I enter the MetaEditor? What are its parts and what can they do? Can I customize the different panels and toolbars? Can I close some of the windows completely?<\/strong><\/p>\n As mentioned in the first part, the MetaEditor can be accessed either using the menu Tools \u2013 MetaQuotes Language Editor, or the appropriate icon in the top toolbar of the Terminal.<\/p>\n We have also mentioned that what you see then, is all the same, whether MetaEditor is opened in MetaTrader version 4 or 5.<\/p>\n MetaEditor is very simple, practical and effective. It does not contain any extra functionality. The MetaEditor work environment can be divided into five parts.<\/p>\n These toolbars contain the traditional program menu and menu related to the active program (active in the main editor).<\/p>\n The full menu is hidden in the drop-down menus File, Edit, etc., while the most used tools are \u201csurfaced\u201d in the form of icons.<\/p>\n On the left side, there are by default a block of tools for working with files, two icons to switch on\/off the Navigator module and the Toolbox, while other icons apply to the active program you are working with.<\/p>\n The icon layout can be customized according to your preferences after right-clicking one of the icons and choosing Customize.<\/p>\n What a particular icon does will appear in a tool-tip upon hovering over it or at the same time in the status bar at the bottom of MetaEditor.<\/p>\n On the far right, then, there is a very important tool \u2014 the lookup field.<\/p>\n Under the geared wheel icon, you can choose whether you want the specified expression to be searched only in the current document and\/or all files and\/or the entire MQL community.<\/p>\n If you have checked the option to search in the MQL community, the appropriate web page will open after the search.<\/p>\n The rest of the search results can be found in the Toolbox on the Search tab.<\/p>\n You will undoubtedly find search useful in solving various programming tasks, especially at the onset.<\/p>\n The MQL community operates in English and Russian.<\/p>\n The Navigator is used for navigating through the file structure, which after the \u201cgrand unification\u201d of MQL versions moved to a slightly more complex destination.<\/p>\n Generally for Windows, it is C:\\Users\\ \u201cuser\u201d \\AppData\\Roaming\\ MetaQuotes\\Terminal\\ \u201cinstance_code\u201d \\MQL4\\.<\/p>\n Here you should be able to find all the source files of programs in MQL for the particular MetaTrader instance.<\/p>\n These can then be viewed and edited directly in the editor. The module can be turned off and on using the relevant icon or menu on the main toolbar.<\/p>\n This is, of course, the largest window.<\/p>\n The Editor itself does not offer too much.<\/p>\n It is, de facto, just a text editor in which you write and edit the active program.<\/p>\n To the left, there is a useful lines counter.<\/p>\n By clicking a particular line number, you can mark it to be easily located at a later time.<\/p>\n If you have multiple open programs, then you can switch between them using the tabs at the top part of the editor.<\/p>\n The\u00a0Toolbox<\/strong>\u00a0offers several useful tools, among which you can switch in the lower part.<\/p>\n The tab\u00a0Errors<\/strong>\u00a0is used for the overview and description of the errors in the program during its compilation.<\/p>\n Bug reports will be dealt with in one of the later parts of the series.<\/p>\n Search<\/strong>\u00a0displays the results of the search in the document or in files.<\/p>\n Articles<\/strong>\u00a0display the latest articles on the website of MQL community.<\/p>\n Upon double click, the relevant article will open on the site mql5.com<\/p>\n In the\u00a0Code Base<\/strong>\u00a0tab, there is a list of new programs available from members of the MQL community have shared to their pages.<\/p>\n Once again, by clicking any of the items, the browser with the appropriate page will open.<\/p>\n The\u00a0Journal<\/strong>\u00a0section is used as the program log.<\/p>\n The status bar only occupies a single line at the very bottom of the MetaEditoru, but it provides very valuable information.<\/p>\n In its left part, it displays what an icon or menu item does upon hover over the icon or menu item.<\/p>\n In its right part, then, you can see what parts of the program your cursor is currently located in, i.e. in which row and column.<\/p>\n Still, the far right also shows the abbreviation of the type of writing. INS for classic paste, OVR for overwriting.<\/p>\n You can switch between these modes use the Insert key like in common text editors.<\/p>\n Since we already know everything about the MetaEditor, we can start creating our first program.<\/p>\n We will describe the program file wizard and the basic types of programs.<\/p>\n How do I start creating my program in the MetaEditor? What are the types of programs and their specific features? Which program should I choose?<\/p>\n In the last part, we described the individual elements of the MetaEditor, which is why we are ready to embark on the creation of the first program. We begin the creation of a new program by clicking on the icon to First, we have to select the type of program that we want to create.<\/p>\n The default pre-chosen option is Expert Advisor, other options include Custom Indicator or Script.<\/p>\n According to the selected type, MetaEditor prepares for us the code of the program, but this is not a non-reversible choice, we can then change the code as we like, even with the program type.<\/p>\n We can leave the last three types out as we will not need them in this series.<\/p>\n These are additional codes for more complex programs.<\/p>\n Now, when we are to choose the type of program, it is time to explain basic differences between strategy, indicator, and script.<\/p>\n After that, we will finish the creation of the program.<\/p>\n The script is the simplest type of program that is used for one-time execution of a task.<\/p>\n When initiated, it only executes once and turns off.<\/p>\n The entire code to be executed as part of the special function OnStart(), other functions have no purpose in the script.<\/p>\n Do not panic, we will talk about special functions in other episodes.<\/p>\n Examples of the script may be programs that perform a one-time rendition of a graphical element into a chart, programs that open or closed positions with specific characteristics, and so on.<\/p>\n Therefore, the script itself cannot contain trading functions that can open or close or modify positions.<\/p>\n Most importantly, however, the entire code is only executed once.<\/p>\n As soon as the code is executed to the end, the program ends.<\/p>\n A program of this type is primarily used for creating automated trading systems, but it can also be used to create other supporting programs that are executed repeatedly, for example, information ones.<\/p>\n Unlike in the case of a script, the code is executed on a regular basis, usually upon every incoming tick, i.e. upon each new incoming price (with the only exception of ticks which came at a time when the previous execution of the program had not finished).<\/p>\n The main part of the program is usually a part of the special function OnTick(), and there are usually also the functions OnInit() and OnDeinit() which contain the piece of code that is executed when starting or switch-off a strategy.<\/p>\n It is possible to add even more special functions to the program which we will be talking about in further installments.<\/p>\n However, you might not need these, especially if you are only just starting with MQL.<\/p>\n A strategy may of course also include trading functions.<\/p>\n When switched on, the strategy runs until it is turned off.<\/p>\n A program of the indicator type is used for creating custom graphical indicators.<\/p>\n The main special function of this type is the function OnCalculate() which is also executed upon each incoming price.<\/p>\n Here, too, the functions OnInit() and OnDeinit() are commonly used, along with some of the other special functions. Unlike the strategy, this type cannot contain trading functions.<\/p>\n Although they may be there, they will be ignored.<\/p>\n Once we know which type of program we want to create, we can move to the next options.<\/p>\n In the next window, we will need to name the program.<\/p>\n This is the only mandatory field.<\/p>\n We can also add authorship and link to a web page.<\/p>\n The already known parameters (variables) that will be active in the program can be added to the largest field.<\/p>\n Even here, it holds true that all (non-)specified values apart from the name can then be edited, deleted or added in the code without any problem.<\/p>\n If we chose the script at the beginning, the wizard to a new program will be finished at this stage.<\/p>\n If our plan is to create another program, the wizard will require us to give more information about the special functions.<\/p>\n If you are only starting with MQL, these offers do not need to distract you and you can click through them as they are with peace of mind.<\/p>\n They will first come in handy for the more complex programs.<\/p>\n If you are creating an indicator, at the end of the wizard, you can specify the planned lines of the indicator with their style, color and name.<\/p>\n You can also define whether they will be in a separate window or directly in the chart, and, where appropriate, if they will have a minimum and a maximum.<\/p>\n Once again, this is not anything that could not be changed directly in the code.<\/p>\n After you complete the wizard, the pre-designed code pops up in the code editor.<\/p>\n Its syntax is based on what you entered in the wizard.<\/p>\n In order for you to start getting to know certain parts of the code which are identical to all programs and start organizing your program code, we are going to focus on program structure in the fourth episode.<\/p>\n What are the parts of the program? Do these parts vary according to program type? Why is it important to divide codes into logical parts? How does the program control move among program parts?<\/p>\n Each program can be divided into several logical parts.<\/p>\n Their number and use depend on the type and purpose of the program.<\/p>\n The following diagram offers a basic schematic of the parts contained in most programs.<\/p>\n Below the diagram, there is an explanation of the progress of program execution as performed by the computer.<\/p>\n Then, individual main parts of the program are discussed.<\/p>\n It may seem to be an excessive theory but you will learn for yourself that the knowledge of what is being executed is very important.<\/p>\n Structure of the program. Source: https:\/\/book.mql4.com\/programm\/structure<\/p>\n<\/div>\n The usual progress of program execution among individual parts is marked in the diagram by a yellow line.<\/p>\n As evident from the last episode already, the program first reads the header and then executes the function OnInit() if it is present.<\/p>\n Then, it moves to the main special function which differs according to the type of program, as we have seen in the last episode.<\/p>\n <\/p>\n If the program is a script, the special function OnStart() is executed only once.<\/p>\n In other cases, the main special function is executed over and over again until an instruction is given to exit the program.<\/p>\n This may come either from any part of the code or from the program user.<\/p>\n Once that happens, the function OnDeinit() is in turn for the execution, if present, and then the program ends.<\/p>\n Smaller yellow lines indicate the possibility to summon the execution of custom functions from the main functions.<\/p>\n We will deal with user functions closer at a later time.<\/p>\n They are parts of the code which are to execute a specific task.<\/p>\n In the code, they are located outside of the other functions, usually below the whole code.<\/p>\n As seen here, these functions can be initiated to execution from all of the special functions, not only from the main function but also from other custom functions as well.<\/p>\n The number of custom functions in the program is not restricted.<\/p>\n Blue arrows indicate the communications of individual functions with the terminal.<\/p>\n This can be done for instance to get the current instrument price, volumes and other information.<\/p>\n In some cases, the program may even ensure communication outside the terminal, indicated by black arrows.<\/p>\n This involves, for example, the execution of orders where the program communicates with the broker\u2019s server or the work with files where information is exchanged directly with the operating system.<\/p>\n The header usually provides basic information about the program first, such as the version, authorship, description, etc.<\/p>\n This is the information displayed upon program startup in Metatrader.<\/p>\n In order for them to be displayed to the user, the code has to always start with the modifier #property and the name of the specific information type (e.g. copyright, description, version, etc.).<\/p>\n Furthermore, we define the global variables in the header.<\/p>\n These variables will be available to all functions in the program.<\/p>\n Of course, we will talk about variables closer in further episodes of this series.<\/p>\n If the name of the variable is preceded by the modifier \u201cinput\u201d, we define a variable whose value can be entered by the program user him or herself (in the case of a script, it is necessary to enter the modifier #property show_inputs to display the window with parameters).<\/p>\n In the header, it is also, for instance, possible to import functions from other file libraries and other activities.\u00a0 <\/p>\n<\/div>\n This function contains the code to be executed as first. It is, therefore, a sum of actions to be performed before starting the main part of the program.<\/p>\n It may involve the preparation of graphics, the definition of indicator lines, preparation of calculations etc. With an indicator the function is almost always present, otherwise, it is not necessarily needed and we can leave it blank or delete it completely. In that case, the control switches from the header straight to the main special function.<\/p>\n Although MetaEditor always generates it in the first place, it is in practice completely arbitrary wherein the program it is located.<\/p>\n The control always heads to it first, if it is present in the code.<\/p>\n Each program must include a special function that will contain the main part of the program for execution.<\/p>\n That is the part that defines the main mission of our program.<\/p>\n Specific main special functions vary according to the program type.<\/p>\n In the case of a script, it has the name OnStart(), in case of a strategy it is OnTick(), and finally, in case of an indicator, it is OnCalculate().<\/p>\n Several further special functions can be added to the programs.<\/p>\n There will be a special article dealing with them after the completion of the basics series as they will not be needed for the basics.<\/p>\n The name of the special function suggests what kind of events it will be performed.<\/p>\n The OnInit() is executed upon initialization, OnTick() upon receiving a new incoming tick, etc.<\/p>\n This part of the program usually contains the largest part of the code and the execution of this part also employs the control the longest.<\/p>\n In the case of a strategy or an indicator, this section repeats over and over again, until the program is ended.<\/p>\n Most of the more complex codes will contain user-defined functions for the sake of clear arrangement.<\/p>\n These are all the non-predefined functions which the programmer defines him or herself in the code.<\/p>\n They will be dealt with in detail later. Also, it does not matter where in the code they will be placed.<\/p>\n Normally, they are placed at the very end for the sake of clarity.<\/p>\n They are executed at the moment when they are initiated from other parts of the code that is currently being executed.<\/p>\n The principle of initiation and construction of custom functions will be shown in further episodes, however, it certainly will do no harm to have a look at what they can look like now.<\/p>\n As the name of this special function suggests, it is responsible for the execution of the code upon deinitialization, i.e. end of the program.<\/p>\n Thus, it is a set of actions that are performed once the user or the terminal give the command to end the program. It may involve for example deleting graphics features of the program, parting with the user, etc.<\/p>\n Once again, the position in the code does not matter.<\/p>\n Once the execution of the function is finished, the program ends. If the function is missing, the program will end directly upon the signal to exit, like in the case of OnInit().<\/p>\nTop Toolbar<\/h3>\n
<\/a><\/p>\n
Navigator<\/h3>\n
<\/a><\/p>\n
Program-Writing Editor<\/h3>\n
<\/a><\/p>\n
Toolbox<\/h3>\n
<\/a><\/p>\n
Status Bar<\/h3>\n
New MQL Program and Types of Programs in MQL4<\/h2>\n<\/header>\n
the left in the toolbar, or clicking the same button in the File drop-down menu.<\/p>\n
<\/p>\n
Script<\/h3>\n
Automated Trading System (Expert Advisor)<\/h3>\n
Custom Indicator<\/h3>\n
MQL4 Structure of the Programme<\/h2>\n<\/header>\n
<\/a><\/p>\n
The progress of program execution<\/h3>\n
Header<\/h3>\n
<\/a><\/p>\n
Special function OnInit()<\/h3>\n
<\/a><\/h3>\n
Main special function<\/h3>\n
User-defined functions<\/h3>\n
<\/a><\/h3>\n
Special functions OnDeinit()<\/h3>\n