Wednesday, January 28, 2009

Education MQL II Lesson number 3

Education MQL II Lesson number 3


Halhalyan Arthur
fxtest.ru
artur@fxtest.ru

Hello dear readers! Perhaps the two previous lesson was not very interesting, because could not have been to see the results of their labor. Believe me, they were necessary to further, to work. In this lesson we will learn to open positions and explain sintak-handling system to the array of quotations.
3.1. Feature SetOrder

Using the SetOrder could open positions for buying and selling at the current price or to arrange deferred warrant.

SetOrder (operation, lots, price, slippage, stoploss, takeprofit, color)

SetOrder (operation, the number of lots, the price, the maximum allowable slippage, stoploss, teykprofit, color)
3.1.1. Operation (Operation)

Transactions can be divided 2 species, the entrance to the current price, or set the pending order.

To enter the current price of the operation would take the form: op_buy or op_sell.

Op_buy-purchase contract for the current price of should be pointed .

Op_sell-sale contract for the current price of should be pointed .

To be placed pending order operation would imetvid: op_buylimit, op_buystop, op_selllimit iliop_sellstop.

If we want to put a pending warrant for the purchase, provided that the current price is below the price of the warrant of execution, the operation will look op_buystop. Ie We plan that the price will go further in that direction (naproboy, top).

If we want to put a pending warrant for the sale on condition that the current price is below the price of the warrant of execution, the operation will look op_selllimit. Ie We plan that the price spread and go in the opposite direction (turn).

If we want to put a pending warrant for the purchase, provided that the current price above the price the warrant of execution, the operation will look op_buylimit. Ie We plan that the price spread and go in the opposite direction (turn).

If we want to put a pending warrant for the sale on condition that the current price above the price the warrant of execution, the operation will look op_sellstop. Ie We plan that the price will go further in that direction (naproboy, down).
3.1.2. lots (lots)

To specify the number of lots in the warrant, you can write a specific number, for example, 1 or 2. I recommend to write reserved variable, because directly to the MT, you can put any number of lots, thus your expert will be more flexible.
3.1.3.Price (price of a warrant of execution)

To log on the current price op_buy operations or op_sell, you need to use the ask price and bid, respectively. To enter is pending order or you can write a specific price or to use an expression of this type: ask +30 * point. What does this mean?

That means the current ask (for example, 1.2800), added 30 points, ie entry price 1.2830. Point is the price point for a particular currency pair, for EURUSD point = 0.0001, for USDJPY point = 0.01. The price point to define itself, it will do for you, MT. You can write so: ask +0.0001 and it would be correct, but to connect this to the expert USDJPY it will have to redo. In order to write more flexible Experts recommend that you always use reserved variable point.
3.1.4. Slippage (slip)

If the slippage would be greater than this value, the activation order will be rejected. Most likely (if the condition of entry will not change), the expert will try to re-open position and open it only if the slippage would be less than the specified value. I use 3 or 4 points.
3.1.5. Stoploss (loss)

It should be understood that the stoploss is just a value price, which will close the position by force. Ie in the field, you can simply write a specific price.

For guidance, I recommend leaving variable stoploss, as in the creation of an expert (or cap expert) exhibit the desired amount. This will be your expert more flexible and value stoploss can be changed directly in the MP in your expert. Tribute will be kind: ask + stoploss * point. A variable is always remember! This is true for the permanent stoplossa.

If you want to have a dynamic (changing) stoploss, it can take in a variable. For example: 1]> This means that the stoploss is the minimum price last bar. Below I will discuss the details.
3.1.6. Takeprofit (teykprofit)

All that is stated in paragraph 3.1.5. fully applied and for takeprofit. More to say nothing.
3.1.7. Color (Color)

This field specifies the color, which will be painted an arrow in the quotation at the opening position. Also, the arrow will appear in front of the price of which has burst warrant. MT supports a lot of flowers, for example: gray, gray, red, blue, etc.
3.1.8 Examples of use SetOrder.

A warrant for the purchase of:

SetOrder (op_buy, lots, ask, 3, bid-stoploss * point, bid + takeprofit * point, green);

A warrant for sale:

SetOrder (op_sell, lots, bid, 3, ask + stoploss * point, ask-takeprofit * point, red);

Pay attention to the foot of the bid deemed to warrant a purchase and ask for a warrant for sale. This fact and meet the place because, to actually planted, for example, 30 points foot, it must be considered from the real price of the closure order! But do not be surprised if you see in the tool, for example, closing the position on stoplossu, not at 30 points ty loss, but at 35, spread nobody lifted.

Pending orders:

SetOrder (op_sellstop, 1, bid-50 * point, 3, (bid-50 * point) + StopLoss * Point, (bid-50 * point)-TakeProfit * Point, blue);
ho = h [1];
SetOrder (op_buystop, lots, ho, 3, ho-StopLoss * Point, ho + TakeProfit * Point, blue);
3.2. Appeal to the array of quotes.

Arrays quotations are the following names. Close (C)-closing price, Open (O)-opening price, High (H)-the maximum price, Low (L)-a minimum price, Volume (V) - the volume.

You can use these names or abbreviations, they are in parentheses. Appeals to the array of quotations carried out as to the usual array through the brackets. Index 0 is the current bar, 1 last, etc. Ie c [1], the closing price of the last bar, o [0]-opening price of the bar, h [2], the maximum price before the bar. Keep in mind that referring to the current bar (indeks0), you can be sure to change only outside its opening price, however the rest of the parameters (H, L, V, C) may change over time. The names of the arrays with the indices H, C, etc. The expert will be understood as meaning the current bar, that is, with a score of 0 (H = H [0], C = C [0]), etc.

Now create the first trading expert. We are together on the steps to create an expert in the first lesson, and I think you do not have problems. If there are any, look in there.

In the settings of an expert vystavlyaem stoplos in 40 points, teykprofit 100, the number of lots 1. You can then experiment with other values. Testing for the H1, such as the euro.

/ * [[Name: = Expert2
Author: = Fxtest
Link: = forextimes.ru
Lots: = 1.00
Stop Loss: = 40
Take Profit: = 100
Trailing Stop: = 0]] * /
if totaltrades = 1 then exit; / / 1 if you already have a go (this is the number of open positions)
if c [1]-h [2]> 10 * point then SetOrder (op_buy, lots, ask, 3, l [1]-stoploss * point, bid + takeprofit * point, green);
if l [2]-c [1]> 10 * point then SetOrder (op_sell, lots, bid, 3, h [1] + stoploss * point, ask-takeprofit * point, red);

Congratulations to the first trading expert. In addition totaltrades will not explain anything, unnecessarily in this lesson is to understand all the algorithms, in order to consolidate the material urge to look. There will also be helpful if you try to remake it and poeksperimentiru-ete with the foot.

In the next lesson, we explain the cycles and write a more complex expert.

No comments: