Thursday, May 26, 2011

MA Per-period

Hello dear readers. I congratulate all Orthodox holiday.
Today we will write expert, trade will be carried out only in the direction of the trend signals will reversive (ie in terms of job creation will ever deputy), one expert will be used only sliding average.
11.1. Algorithm
To play average slip direction is possible in many ways. In our experts will compare the last value before last and if the average difference over the built-quantity items, we will close the old position and open a new one.
As a closing of a position, has suddenly opened the contrary, the expert maintained tajmaut DTS.
As the expert, as against the latter may be associated with several tools and trade them both will happen.
11.2. Expert

/ * [[
Name: = MA
Author: = fxtest.ru
Link: = forextimes.ru
Many: = 1.00
Stop Loss: = 2000
Take Profit: = 2000
Trailing Stop: = 0
]] * /
define: Npips (2) Per (21) / / 2 external variables Npips-difference between the values ��MA, MA Per-period
var: CNT (0) and (0), fb (0), FS (0), MA1 (0), MA2 (0);

If CurTime-LastTradeTime <10 then exit; / / 10 naeoiaiue oaeiaoo

/ / Value r that is recorded in separate variables, for convenience (MA - EMA, you can change type)
MA1 = IMA (Mon, MODE_EMA, 1);
MA2 = IMA (Mon, MODE_EMA, 2);

S = 0; / / counter of open jobs in the beginning we had every time null

if fb = 1 then
{
fb = 0;
SetOrder (op_buy, very, ask, 3, draft-stoploss * Point,
+ * takeprofit service point, green);
exit;
};

/ / Opening on opposite positions on condition of equality (fb = 1 or fs = 1)
if fs = 1 then
{
fs = 0;
SetOrder (op_sell, very tender, 3, Ask + * stoploss point
Ask-takeprofit * point, red);
exit;
};

for CNT = 1 TotalTrades
{
If OrderValue (CNT, VAL_SYMBOL) = Symbol then a = a +1;
};

/ / We count on a cycle amount of open spaces on the current tool
if <1, then
{
/ / Anee ioe? Uouo iiceoee IAO Oi ...
if the MA1-MA2> Npips * point then
{
SetOrder (op_buy, very, ask, 3, draft-stoploss * Point,
+ * takeprofit service point, green);
exit;
};

If MA2-MA1> Npips * point then
{
SetOrder (op_sell, very tender, 3, Ask + * stoploss point
Ask-takeprofit * point, red);
exit;
};
/ * Define the opportunity to open position,
reporting in this block of an expert will go just 1 times * /
};

If> 0, then
{
/ / If open positions are checking the possibility of closing
for CNT = 1 TotalTrades
{
If OrderValue (CNT, VAL_TYPE) <= OP_SELL and / Eee buy sell
OrderValue (CNT, VAL_SYMBOL) = Symbol then / / eino? Oiaio niaiaaaao
{
If OrderValue (CNT, VAL_TYPE) = OP_BUY then / / anee buy ...
{
If MA2-MA1> Npips * point then / / condition for closure
{
CloseOrder (OrderValue (CNT, VAL_TICKET),
OrderValue (CNT, VAL_LOTS), bid, 3, Violet); / / close
fs = 1; / / flag at the opening of the opposing position
Exit;
};
};
If OrderValue (CNT, VAL_TYPE) = OP_SELL then / / if you sell
{
if the MA1-MA2> Npips * point then / / condition for closure
{
CloseOrder (OrderValue (CNT, VAL_TICKET),
OrderValue (CNT, VAL_LOTS), to ask, 3, Violet); / / close
fb = 1; / / flag at the opening of the opposing position
Exit;
};
};
};
};
};

The expert stops are exposed, unattainable that the position will be closed only on the condition. Certainly it is not working expert, but we have seen here some new approaches, methodically it would be very useful.
It is still not resolved, it will be the next message, it means to write, show activity and will probably be your algorithm on the pages of the next issue.

No comments:

Post a Comment

Powered by Blogger.