Friday, March 20, 2009

Programming language MQL 4: Interaction with the environment

In the previous article devoted to the study of MQL4 (Forex Magazine ? 48), we examined the environment of programs written in MQL4. In this article, try to understand the intricacies of communication between the MQL-media program and the client terminal, performing the program, but for one explain step by step, one of three possible types of user programs - Indicators.

But first a slight digression, which we hope will greatly facilitate the passage of one of the stages of MQL-creation program to combine creation wizard advisers:
Each time, beginning to write MQL-program with wizard creation advisors, we get the skeleton of the program with information about the developer, stating that the copyright belongs MetaQuotes Software. With that you can live on stage, but when you begin to write independently, and may distribute their own programs, naturally want to "cap" of the program contain your personal information. You can manually correct each time this version of the "cap" on its own or do it in one of the steps the wizard correcting field "Author" and "Link", but easier once done so, as suggested below.
Attention, described further method involves the precise understanding and consistent implementation of all these actions. If you are not confident that the deal with a task, it is better not berites for it at all!
Irregular steps with the register could lead to full or partial inoperable vehicles. Neither the author nor the Journal assumes no responsibility for the consequences of the process or other breaches of your system.

1. Run RegEdit

2. Select a tree in the left pane of the branch HKEY_CURRENT_USERSoftwareMetaQuotesSoftwareMetaEditor 4Experts

3. In the "File" menu, select "Export" and save in the selected line information. Reg file. Next to the certainty we assume that the selected registry branch was saved in the file "ME_ProgramHeader.reg"

4. Close the program RegEdit.

5. ME_ProgramHeader.reg open the file for editing. To do this in Windows Explorer, clicking on the file name, right-click from the context menu choose "Edit".

6. Change the field "Address" and "Author" to those that you want to see in the future in the "cap" program. Do not forget to double quotes, as in the names of the parameters and their values, as was the uncorrected file.

7. Now save the file under a different name, for example, "My_ProgramHeader_.reg" and close it.

8. Now you have two files: one - with the original data, which can at any time to restore the other - with your data that we have now added to the registry.

9. In Windows Explorer, double-click on the file name My_ProgramHeader_.reg, agree with the proposal to make the data file to the registry click "Yes" and then accepted congratulations on the successful introduction of data in the registry, again pressing "OK".

10. Established in MetaEditor'e with the wizard and a new program in the second stage, when prompted to enter the name of the program, we see that the "author" and "Reference" contains the necessary lines to us.

Now, each time the wizard will offer to create a MQL-program with the "correct" fields "Author" and "Reference". But if suddenly you want to return the value of the registry to its original state, it will be done very easily, you will need to restore the values from a file created on the 3 rd stage.

For this material will need to create a skeleton of an indicator. Causing the creation wizard advisers indicate that we want to create a custom indicator and proceed to the next screen, click "Next." The next stage is to determine, let's call our indicator Indicator1 and then click "Next." Adding an index and complete the wizard.

Our code, which has so far not doing anything useful, but it already contains all the formalities required in order to begin filling its functionality. Nachnem line parsing skeleton future indicator. Preview of five lines - this comment, which contains the name of the file pravaobladatel source code and a link on how to contact the author of the code. Comments from the viewpoint of MQL-program, there is something, which at the time of compiling the program does not need to pay attention, that is, they will never become the compiler of any executable command. Comments are written mainly for the fact that either do not forget the very many years, or that others read the source code to understand what it is.

The next section, which describes the properties (properties) buduyuschey program. Properties may include the following fields:

general information about the program:
copyright
link
Type of compiled module:
library
indicator_chart_window
indicator_separate_window
maximum and minimum indicator:
indicator_maximum
indicator_minimum
number of charts and color:
indicator_buffers
indicator_color1. indicator_color8

From general information about the program, we can specify two parameters. The effect of these parameters will be visible when we add an indicator on the graph. On the options panel display appears with the text, which we indicated in the "copyright". Clicking this inscription runs described in "link" refers to a web resource.

Then you can select the type of compiled module

If we write a program advisor, then none of these properties are not required. If we write the indicator, you can choose an indicator risuemy in the window with the price schedule, (chart window indicator) or indicator risuemy in a separate window (separate window indicator). The property of "library" refers to the fact that we do not want to write a program advisor or the type of indicator, and library functions. When we say that there are three types of programs, we purposely did not mention the library of functions - firstly, it is not a program, as well as can not be met, and secondly, until they turn comes when we are fully ovladeem skills MQL-creation programs.

The following properties of the program are responsible for the maximum (indicator maximum) and minimum (indicator minimum) value of the indicator. They are useful in the case when we write the indicator displayed in a separate window.

Let's look a little more detail the properties, indicating the number of schedules displayed indicator, and color. In previous versions of MetaTrader 3.x users from MQL-programs could draw only two curves. Often this is not enough, and had to resort to various tricks. It was common to use several programs for MQL-drawing of one indicator. This method does not satisfy many of the fact that he was not so time consuming, but not obvious and inconvenient. MetaQuotes Software Developers MetaTrader4 have taken into account when writing this weakness and the possibility of adding custom indicators to draw up to eight graphs. Now, in order to use a few graphs will need to specify the number of property
indicator "indicator_buffers". Well, to each of the scheduling indicator is displayed on the screen the desired color, you need to specify them in saoystvah indicator_color1, indicator_color2, indicator_color3 and so on until indicator_color8.

It is important to understand that it is not a direct indicator draws on the screen MetaTrader'a all that want, but merely asked to comply with this or that drawing, as already MetaTrader is free to decide how and what to do. Properties of the program during its run MetaTrader'om and deducted on the basis of their values MetaTrader Indicator draw on the screen, but these properties can be further modified from the terminal using the panel properties of the program.

Explain what properties can be used in MQL-programs, and how they operate in interaction with the indicator MetaTrder'om, you can go back for further review postrokovomu skeleton buduyuschey program.

For the section describing the properties, there is a section on global variables, recall that the "global", they are called from the fact that the area of visibility extends to all the features included in this file.
There is no global (we'll call them "local") who are declared within a function is not available for other functions.

The first and so far the only variable - it ExtMapBuffer1. This array, which must be filled with the values of our indicator. This is another fine place to back-terminal program, which is important to clearly represent yourself. ExtMapBuffer1 - this is the only one (in the case of a schedule) the opportunity to influence the way of rendering graphics. Then we will see how this variable relates to the schedule.

Look at the function init (). There are two callback functions of the software interface MetaTrader'a:
SetIndexStyle (0, DRAW_LINE);
SetIndexBuffer (0, ExtMapBuffer1);

One of them said that the schedule should be otrisovan as the solid line and the second connects the variable array ExtMapBuffer1 in our program with an array, which will be deducted MetaTrader data
otrisovyvaya schedule.

If you want to display multiple graphs on a screen, each of them will be proinitsializirovan this way. Number initsializiruemogo schedule is transmitted first parammetrom in both functions, this value is "0" as the indexing of arrays of graphs starting from scratch.
Further lines of you should already know. If not, then explaining to continue sending the reader to the previous issues of the journal Forex Magazine (? ? 20-28) and the site developers MetaTrader 4 - site of the company MetaQuotes Software



Alexander Ivanov
to Forex Magazine
fxtrade@tomsk.ru

No comments: