Monday, February 23, 2009

Learning to write by experts for Meta Trader. Lesson number 13

Education MQL II. Lesson 13

Hello dear readers. On crossing the medium, has already said a lot, a LED that works on this principle (MACD). Yet even an expert and easy, it seemed to me quite interesting. Under certain parameters yield quite high. And above all, he reverse-type, a new position, and the closure of this last (opposite direction). I will not anticipate. So, all of Pryadko.

15.1. Algorithm
The expert determines the access point by using two moving averages, let him be EMA, different averaging periods. Fast and slow mean (ie, less the period of fast, slow, respectively, with a large). As a trend, such a system would sell quite well, but in the Flat all can be quite sad. To improve this point in the expert introduces an additional condition, not only what should happen intersection, but also after the AI should disperse at N points (this value, as well as periods of medium to be in the external variable). Ie series is not deep intersections, up, down, up, down in the Flat will be simply ignored. In other words the crossing should have a "margin". The expert is always in the market. As soon as the crossing happens, MA changed its mutual status, is the current closure and opening of the opposite position. Stop specially exhibited reach for what would be the opening of the new position going into the intersection only after testing and selecting the desired parameters can be put, and normal foot. Sign implemented on the next bar.

Conclusion
In the expert settings play an important role. The parameters which are now the default is not a bad show to watch pound. Quite interesting parameters, evra, M5 fast 2 slow 4 Npips 10. Of course, these parameters can be perepodognannymi would be interesting if some of the readers will check the system to a long history (it may in part).

I can not say confidently that it would be in the next issue, write, and perhaps in the next room you will see the answers to their questions or their expert.

/ * [[
Name: = 2MA
Author: = Fxtest.ru
Link: = forextimes.ru
Lots: = 1.00
Stop Loss: = 5000
Take Profit: = 5000
Trailing Stop: = 0
]] * /

defines: fast (6), slow (9), Npips (7) / / external variables, periods of AI and
/ / Npips-number of stock
var: cnt (0), fb (0), fs (0), fup (0), fdown (0), fast2 (0), fast1 (0), slow2 (0), slow1 (0);

if CurTime-LastTradeTime <10 then exit; / / actually close the old position
/ / And open the new, we can not because of restrictions on the timeout, so
/ / We stand up to his

If FreeMargin <1000 then Exit; / / output in the lack of a free margin
if fb = 1 then (fb = 0; SetOrder (op_buy, lots, ask, 3, bid-stoploss * point, bid + takeprofit * point, green); exit;);
if fs = 1 then (fs = 0; SetOrder (op_sell, lots, bid, 3, ask + stoploss * point, ask-takeprofit * point, red); exit;);


/ / Fb and fs flags, they needed that would withstand a timeout, and open the respective positions

fast2 = iMA (FAST, MODE_EMA, 2); / / before the importance of rapid secondary
fast1 = iMA (FAST, MODE_EMA, 1); / / past the average value of rapid
slow2 = iMA (SLOW, MODE_EMA, 2); / / before the value of slow secondary
slow1 = iMA (SLOW, MODE_EMA, 1); / / last value of the slow secondary

if TotalTrades <1 then (/ / if there are no positions opened it ...

if fup = 1 and (fast1-slow1)> Npips * point then
(Fup = 0; SetOrder (op_buy, lots, ask, 3, bid-stoploss * point, bid + takeprofit * point, green);
exit;); / / open the first position if it is long
if fdown = 1 and (slow1-fast1)> Npips * point then
(Fdown = 0; SetOrder (op_sell, lots, bid, 3, ask + stoploss * point, ask-takeprofit * point, red);
exit;); / / open the first position if it is short

If fast2 slow1 then (fup = 1; fdown = 0; exit;);
if fast2> slow2 and fast1
);

if TotalTrades> 0 then / / after the opening of the first position on the expert will always look for the possibility of "coup"
(
for cnt = 1 to TotalTrades
(
if OrderValue (cnt, VAL_TYPE) <= OP_SELL and / / buy, or sell
OrderValue (cnt, VAL_SYMBOL) = Symbol then / / tool match
(
If OrderValue (cnt, VAL_TYPE) = OP_BUY then / / if you buy ...
(
if (slow1-fast1)> Npips * point then / / condition for a coup
(
CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), Bid, 3, Violet); / / zakrtyie
fs = 1 / / flag at the opening of the opposite position
Exit;
);

);

If OrderValue (cnt, VAL_TYPE) = OP_SELL then / / if you sell
(

if (fast1-slow1)> Npips * point then / / condition for a coup
(
CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), ask, 3, Violet); / / zakrtyie
fb = 1; / / flag at the opening of the opposite position
Exit;
);

);
);
);)




Company
Halhalyan Arthur
Technical support for traders
artur@fxtest.ru

No comments: