Writing an advisor for MetaTrader 4 forex. Part 2


In a previous publication "Writing an adviser for MetaTrader 4 forex. Part 1 "we have elaborated on the basic functions that must be taken into account when creating advisor. Today we continue with the series and discuss how to operate forex trading advisor under the trade-analytical platform Meta Trader 4.


Naturally, at this stage, mechanical forex trading system for us to understand just somewhere on the level of touch, that, behold, there is somewhere something. Therefore, we will focus on the initial level and analyze everything in order. So. In MetaTrader 4 as an example of Counsel, which is the default, before MACD Sample.


MACD Sample - is an elementary forex trading advisor, the original of which is made by the company MetaQuotes. In this Advisor Forex MT4 modified by 4-hour chart GBP / USD. But there may be other modifications. The MACD is present in virtually all commercial and analytical platforms. Advisor on MACD uses in its work the intersection of 4 different MACD + 2 moving averages. They help determine the direction of the position, which will be next. Counselor MACD uses in its work Trailing Stop (trailing stop). In connection with such a feature of the mechanical forex trading system suffers little loss. But the peculiarity of this advisor forex is that it should always be included in order to stop losing trades.


In a previous article, we also stopped at such functions as init (), deinit () and start (). It is about the last we'll talk in more detail. The fact that this function is the principal advisor in the forex market, so the operating features of this function should be thoroughly explored. Again, what this function is called MT4 each time after the quotes will vary. It is the function start () will conduct market analysis, and close deals based on signals from the indicators that are included in the automated trading system forex.


Below we will describe the order of process performance function start (). The work function is divided into several blocks. We describe the order of blocks. All of them, except for the first two, usually performed exactly the function start (). So:


1. First, you need to get the original data. These data are obtained by using the function init (). We already wrote about this feature, but in any case once again recall that it serves for the three most important tasks: when you run MT4, by changing the time period schedule and when we connects forex advisor to the schedule.


2. The next item - to change the price. Every time there is a modification, advisor forex refers to the function start (). But if the function is not time to do its work until the formation of a new tick, the tick for a new start () is not called. The very same analysis of price changes is analyzed using the internal algorithms MT4.


3. Make sure it is worth considering one nuance. Each mechanical forex trading system must comply with certain pauses in the query to a server that accepts requests for placement of orders. Different companies set different time limits on the number and range queries. This interval can be calculated independently, and can be considered. This is not so in principle, albeit important. Generally, as a rule, the interval in the implementation of requests to the server, receiving requests for the transaction is approximately 10 seconds. If during this time will be made several requests, they will be rejected and you will give an error.


4. The next point where we implement Advisor Forex - setting the parameters of the indicators that are used in a mechanical trading system forex. The efficiency of all the parameters will be determined during the natural filtering.


5. Next comes the block, which examines the number of warrants which currently are open. It is worth to remember about the number of queries that can be done at a certain time. This software can be "wired" to use a certain number of orders. Generally, however, limit the use of warrants may be set depending on the amount of funds in your trading deposit. That is, you must define the limit of open orders, ie their maximum number in the light of the above features.


At the moment, our work should be limited to the search parameters for successful entry into the market. Therefore, we analyze the values of indicators and trying to understand whether there are open positions related conditions. If these conditions are not revealed, we continue to work - go to Part Adviser, responsible for monitoring open positions. If there are conditions that favor the transaction, then try to open a position.


6. Further, we expect to correct all the conditions for placing orders. There may be a lot of recommendations. Everything depends on the volatility of the currency pair, time interval of trade, or even some specific preferences that you have. In any case, be sure to always use stop loss orders and take profit. Once you finalize the placement of orders, you must complete the function start () and pass control to MT4.


In conclusion, once again a closer look Advisor MACD, which is by default in Me4.


1. When we run forex advisor, is receiving data and their verification. For these actions corresponds to the function init (). As we have said, there are nuances in the user queries when the user specifies a set of short-term needs. In this case, do not check a 10-second limit.


2. Then check how many orders we can place in this case, if an open position. If the currently open positions are not available, we can analyze the feasibility of a display. If there is no need to conduct such an analysis, then pass to the next item.


3. We control the open positions


And the last statement, which we will mention - the operator return. This statement terminates the function, which is performed at the moment and returns control to the program that caused it.


The whole scheme, which we have proposed in this paper is the simplest algorithm, so any mechanical forex trading system can be built on this basis.

"Forex Never Lose Trade"