Tuesday, March 3, 2009

Programming in MQL 4: Trading System


The history of trade in financial markets with the use of indicators has a lot of evidence that can be advantageous to carry out the transaction, based solely on the recommendation of technical analysis. Traders of this sort are one of the basic tenets of technical analysis, states that all the necessary information, including fundamental and important factors are already reflected in market price. The essence of their trade is reduced to the tracking signal to the transaction filed by a set of indicators.

The combination of an individual set of indicators, a clear interpretation of the rules filed by the signals and the methodology for determining involvement in the transaction of funds (the size of the position) are known as "trading system" (TS). These rules of the TC should be linked logically to one another, and their truth must be confirmed by the history of prices. The latter requirement is due to have one of the tenets of technical analysis, which is to say that history repeats itself.

Of course, in order to develop a logical trading system, traders will have to understand the principles of multiple indicators and to try some of them in practice. As almost every indicator has one or more parameters, they require the fitting of the selected features of the market. Market volatility, the time interval, cyclical behavior of prices, liquidity of traded goods, are just a few factors that can be attributed to the characteristics of the market. Fit parameters of the indicators is to understand and check the background of the work vehicle, built on the same indicators, but with modified parameters.

It is because of the need to fit the parameters of particular indicators chosen market and the consequent massive amount of work for many of the development of their vehicle can take many years to come, which will inevitably be accompanied by frustration, sometimes so strong that not everyone will remain loyal to the chosen destination. However, it is hoped that the outcome of the effort, nerves, time and money the trader will receive the exact set of rules and the experience of trading, which would make it fortunate financial speculator.

Ease and, more importantly, greatly accelerate the development of the TC will help your computer. Who does not like, he is best suited to carry out routine work on the results of the multiple re-TC with different parameters.

Many believe that the advisers could be used not only for the test vehicle, but also for automated, fully autonomous trade without the involvement of a trader. Author skeptical about this kind of statements, and therefore can not recommend to take full advantage of what he said about the advisers for the writing of a fully automated vehicle, operating without the participation of the trader.

Trade Information System MetaTrader 4 allows you to write and test on historical data of the so-called advisors (Expert Advisors), which are ideal for writing, mechanical trading system (MTS).

For writing the adviser should be in the editor program MetaEditor 4 select the File menu, point to New.. " We have a "Wizard adviser." After choosing the type of object as the "Advisor" and clicking the "Next", we turn to the dialog, which you need to specify the name of the created adviser, author, links to resources and parameters adviser.

For definiteness let Adviser name MyFirstExpert, graphs "Author" and "Reference" can be left unchanged.

Now add the parameters adviser. They will be used during the attachment of advisers to the schedule for sending quotes to the program some values.

The right of the table "Settings" and press "Add" button and see that the list has the option "Param1" type int (integer) with no initial value. Clicking the mouse on the table fields that correspond to this parameter, we will be able to edit its name, type, or the default value. Let us change the name of the parameter to StopLoss, its type to double, and the default value enter "5". After all this, push the button "Finish" and proceed to the generated "Wizard advisers" skeleton code future adviser.

Established skeleton present title, which indicates we have entered the second phase of "Wizard of advisers" "Name", "author" and "Reference".

For the ad title should be a global variable, and three are still empty function "init", "deinit" and "start". The function "init" has one parameter "StopLoss", which was given us in the third phase of "Wizard of advisers." It also has the type specified by us and double the default value "5".

The function "init" preserves the input parameter "StopLoss" in the global variable with a very similar name "g_StopLoss". This is done to ensure that after the conclusion of the function "init", the value of its input parameter was not lost. Since the parameter is a function of the variable visible only within the body of this function, then, is not whether we have a global variable "g_StopLoss", other options would not be able to get the input parameter value "StopLoss" function "init". Preserving the same value for "StopLoss" in the global variable "g_StopLoss", we ensure the availability of the input parameter value to all the functions of adviser to the whole duration of the program.

If the third phase of "Wizard of advisers, we have indicated a greater number of parameters, it generates a code that contains the global" doubles "for each of them. Naturally, those of the parameters that are needed only during initialization, may not have global counterparts, "and we can safely remove unnecessary global variables after the" Wizard of advisers. "

The value function "init", "deinit" and "start" has been discussed in previous issues Forex Magazine and, nevertheless, recall again that the main phase of the Adviser is in the function "start". That it is performed each time a change takes place quotes traded instrument, and it is responsible for analyzing the market situation and deal-making, based on signals of indicators included in the described vehicle.

Now, in order not to overload the article unnecessary detail, let us aside created skeleton adviser and proceed to self-study examples Adviser "MACD.mq4", supplied with the editor program MetaEditor 4. Suggest steps to consider each of the three functions, and understand the essence, an overall scheme of the advisor, which we explain in the next article.




Alexander Ivanov
to Forex Magazine

No comments: