Education MQL II. Lesson 15
Hello dear readers. Today, we check the validity of a classic trading system. Those who read the classic books on TA, I think, knows such a rule. In the trend need to trade in the direction of trend indicators (eg moving averages), and with the assistance flete oscillators.
15.1 Algorithm
In fact, only the definition of trend is already more than a serious question. The trend will be determined by the indicator ADX, I think you will not be against it, because This is trendsledyaschy indicator. If the ADX is growing and has become the largest in the last N values, the position will be open in the direction of the rolling average. If there is no trend, ie ADX has a low value, then look at the value of the oscillator. If the oscillator in the extreme zone, then open a position (on the rebound from a zone). As an oscillator, will use the indicator Stochastic, then you can replace or add another.
Closing the position will be implemented as a stop order, or condition. The condition is, the disappearance of the trend to open positions in the trend and achieving the opposite extreme zone Stochastic, for positions open in flete. In the external variables, we laid out during ADX, Stochastic, and the average; Stochastic area for the opening position.
15.2 Expert
/ * [[
Name: = Trend-flet
Link: = fxtest.ru
Lots: = 1.00
Stop Loss: = 0
Take Profit: = 0
Trailing Stop: = 0
]] * /
defines: PerMA (21), PerADX (14), StochK (5), StochD (3), Stochslow (3), UpZone (75), DownZone (25)
WindowADX (35), ADXmax (20), ADXmin (15), MApips (4);
var: Stoch1 (0), Stoch2 (0), ADX1 (0), ADX2 (0), Ma1 (0), Ma3 (0), cnt (0), f (0), tr (0);
/ *
PerMA-period MA
PerADX-period ADX
StochK, StochD, Stochslow-periods Stochastics
UpZone (75), DownZone (25) Extreme Zone Stochastics
WindowADX (35), the window of comparison ADX
ADX ADXmax-value from which it is believed that this trend
ADXmin-zngachenie ADX which considered that it flet
MApips-tilt MA
* /
if curtime-LastTradeTime <5 * 3600 then exit; / / Time limit
Ma1 = ima (PerMa, mode_sma, 1); / / AI
Ma3 = ima (PerMa, mode_sma, 3);
Stoch1 = iSTO (StochK, StochD, Stochslow, MODE_SMA, MODE_MAIN, 1); / / Stochastics
Stoch2 = iSTO (StochK, StochD, Stochslow, MODE_SMA, MODE_MAIN, 2);
ADX1 = iADX (PerADX, MODE_MAIN, 1); / / ADX
ADX2 = iADX (PerADX, MODE_MAIN, 2);
if TotalTrades = 0 then tr = 0; / / tr defines the trend, if it is equal to 1, the transaction is opened as a trend fletovaya 2, 0-No Deal
if TotalTrades <1 then (
f = 0 / / flag ADX
for cnt = 1 to WindowADX (if ADX1
/ / WindowADX-box determines the breakdown
if f = 0 and ADX1> ADXmax then (/ / if the ADX more
if ma1-ma3> MApips * point then (tr = 1; SetOrder (op_buy, lots, ask, 3, bid-stoploss * point, bid + takeprofit * point, green); exit;);
if ma1-ma3 <-MApips * point then (tr = 1; SetOrder (op_sell, lots, bid, 3, ask + stoploss * point, ask-takeprofit * point, red); exit;);
/ / Transaction trend
);
if ADX1
if Stoch1
if Stoch1> UpZone and Stoch1> Stoch2 then (tr = 2; SetOrder (op_sell, lots, bid, 3, ask + stoploss * point, ask-takeprofit * point, red);
exit;);
/ / fletovye Deal
);
);
if TotalTrades> 0 then
(
for cnt = 1 to TotalTrades
(
if OrderValue (cnt, VAL_TYPE) <= OP_SELL and OrderValue (cnt, VAL_SYMBOL) = Symbol then
(
If OrderValue (cnt, VAL_TYPE) = OP_BUY then
(
if (adx1
/ / conditions for the closure of trend and fletovoy longovoy deals
(
CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), Bid, 3, Violet);
Exit;
);
);
If OrderValue (cnt, VAL_TYPE) = OP_SELL then
(
if (adx1
(
CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), ask, 3, Violet);
/ / conditions for the closure of trend and fletovoy shortovoy deals
Exit;
);
);
);
);)
15.3 Conclusion
Perhaps many will say that the algorithm is not very versatile and that it clearly ubytochen, but the expert and does not purport to be the role of the expert workshop. On the methodological side, the expert and not so simple and I am sure that readers who want to learn the language perfectly, make sure it is something underlined.
As usual I will wait for your letters, if there will be many questions, or would be particularly interesting, answer them in the next issue.
Company
Halhalyan Arthur
Technical support for traders
artur@fxtest.ru
Halhalyan Arthur
Technical support for traders
artur@fxtest.ru
No comments:
Post a Comment