Pages

Subscribe:

Thursday, May 26, 2011

the period and the average size

Good day dear readers! Today we will write a very simple expert. But with this idea for me some customers have already addressed. The question is inclined sliding average trend.
18.1 Algorithm

General idea as well. Sliding average with a period (greater than 50;). We take the value of the last bar, this value is considered current. Value and some cookies back as the 5th For example, either in an upward tendency, and we March (70) is inclined upwards. So we had, MA hypotenuse, some bars back (5) horizontal cathetus, and the difference between last value and M r value of 5 bars back vertical cathetus, formed rectangular triangle. And the idea of ​​a tendency to be named to the angle between MA (hypotenuse) and a horizontal cathetus. But suddenly we are few, but.

First, units of measurement of vertical cathetus - elements, and horizontal bars.

Second, although our Board and a period, however, not straight line because the angle between the curve and straight line (horizontal cathetus) to take absolutely not true.

Well, and thirdly, it is sufficient to change the scale of the timetables of the visual angle of the slope will change.

Proceeding from all the following is higher, I have decided to leave the angles in degrees, to determine the size of the affection of consumers.

The best and more simple way of defining Dr. inclination I have decided to choose a preset size vertical cathetus in points. That we, for example, always a difference between the last value and the value MA 4 bars back, and get a certain size, the more this size, is more sympathetic.

Whether as an additional signal input would be to define the current price is above the MA for longa and lower shorta.

So the final algorithm.

The long entry is performed if the difference between the value of the Board at the last bar and returned more than the specified size and cost of closing the last bar is more than 4 MB of bars last bar of 10 items or more.

Log in blinkers, rather, respectively.

Is carried out conditional return passage MA by price. That is a condition for closing longa surplus value r above the close price.

The external variables that will put the period and the average size in points down trend.
18.2 Expert


/ * [[
Name: = NaklonMa
Author: = forextimes
Link: = fxtest.ru
Many: = 1.00
Stop Loss: = 50
Take Profit: = 1000
Trailing Stop: = 100
]] * /
define: tr (10), after (70);
var: CNT (0), K (0);

k = 0; / / obnudenie flag down trend

If the IMA (Mon, MODE_SMA, 1)-IMA (Mon, MODE_SMA, 4)> * tr point then {k = 1;};
/ * Condition for vozhodjashchy trend * /

If the IMA (Mon, MODE_SMA, 1)-IMA (Mon, MODE_SMA, 4) <-tr * Point then {k =- 1;};
/ * Condition for nizhodjashchy trend * /

If TotalTrades = 0, then
{/ / If otkryh positions are not present ...

if k = 1 and c [1]-IMA (Mon, MODE_SMA, 1)> 10 * point then
{Setorder (op_buy, very, ask, 3, draft-StopLoss * point
+ * TakeProfit service point, blue);
exit;
};
if k =- 1 and IMA (Mon, MODE_SMA, 1) - [1] Tues> 10 * point then
{Setorder (op_sell, very tender, 3, Ask + * StopLoss point
Ask-TakeProfit * point, red);
exit;
} / / Check the additional condition and arrangement of orders
};
If TotalTrades> 0, then
/ / In order to check the condition of detention if there are open positions
{
for CNT = 1 TotalTrades
{
If OrderValue (CNT, VAL_TYPE) <= OP_SELL and
OrderValue (CNT, VAL_SYMBOL) = Symbol then
{
If OrderValue (CNT, VAL_TYPE) = OP_BUY then
If {Tues [1] / / Condition to exit longa
{CloseOrder (OrderValue (CNT, VAL_TICKET),
OrderValue (CNT, VAL_LOTS), bid, 3, Violet);
Exit;
};
};
If OrderValue (CNT, VAL_TYPE) = OP_SELL then
If {Tues [1]> IMA (Mon, MODE_SMA, 1), then
{CloseOrder (OrderValue (CNT, VAL_TICKET),
OrderValue (CNT, VAL_LOTS), to ask, 3, Violet);
/ / Condition to exit shorta
Exit;
};
};
};
};
};

18.3 Conclusion

Although a large withdrawal of expert turns of history (Evra I4), a positive result. For I1 and I'm less parameters we choose, but I think that performance will worsen an expert in transitioning to smaller frames.

0 comments:

Post a Comment