Thursday, February 19, 2009

Writing Experts For MetaTrader . Lesson number 16

Education MQL II. Lesson number 16



Hello dear readers. Today we write, an expert on the algorithm, which sent me Aleksei Prokofew. Here is a quote from his letters.



"The best tool for trading on the currency pair EUR / USD during the day - trading system Oscillator + CCI. Positions in this open system of oscillators at the intersection of the zero line (for a 4-hour and hourly charts). Signaled to close a position is the opposite crossing point oscillators 100 (long positions) or a mark -100 (short position).



I would like to see in the examination of the expert in the magazine ... "



I asked whether the oscillator is at stake.



"The answer to the question:



RSI, while crossing the center line - to open. Closure of the values 70 and 30 ... "



So what, we are trying to formalize all of this.



Algorithm



I think it makes sense to write a few experts. The first expert will only work on the CCI. Sign in to carry out long after crossing the zero line from the bottom up. Out on the cross down the value 100.



Log in shorts will be carried out after crossing the zero line from top to bottom. Quit crossing from the bottom up value -100.



All care at the last crossing of the bar, is opening a new bar.



The second nominee is, we add the RSI. I think open and close positions on the intersection RSI 70 and 30 is not much point, and a letter is not clear how to reconcile the two indicators. RSI therefore propose to make the filter and allow to enter the market signals from CCI in the "correct" values of RSI. Ie at the entrance to the long RSI must be at least less than 50, at the entrance of the shorts at least 50 more. Limits values laid out in the external variables.



Conclusion



The first expert (without filter RSI), when testing on historical data EUR / USD H4 showed unsatisfactory results. Therefore, the trade will never fit. A second expert in the same historical data has shown better results for the year 261, paragraph 3, for 15 transactions, 221 point maximum drodauna. The truth is, with more "soft" values of RSI number of transactions increases, but the result is not satisfactory.



Maybe, I do not fully understand the algorithm expert, so perhaps in the next issue of the system will be upgraded.



/ * [[

Name: = CCI

Author: = forextimes.ru

Link: = www.forextimes.ru

Lots: = 1.00

Stop Loss: = 100

Take Profit: = 200

Trailing Stop: = 0

]] * /

Defines: per (14);

var: cnt (0), cci1 (0), cci2 (0);

if CurTime-LastTradeTime <8 * 3600 then exit; / / limit to the number of opening the frequency of transactions (for H4 2 bars)



cci1 = icci (per, 1); / / value cci

cci2 = icci (per, 2);



if TotalTrades = 0 then (

If FreeMargin <1000 then Exit;



if cci2 <0> 0 and cci1 <100 then (SetOrder (op_buy, lots, ask, 3, bidstoploss *

point, bid + takeprofit * point, blue); exit;);

if cci2> 0 and cci1 <0> -100 then (

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

exit;);



);



/ / conditions for entry, additional conditions cci1 <100,> -100, for that would be a condition for opening does not coincide with the closure condition



if TotalTrades> 0 then / / No open positions

(

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 / / open long

(



/ / if cci2> 100 and cci1 <100 then



if cci2> 100 and cci2> cci1 then / / condition to the closing

(



CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), Bid, 3, Violet);



Exit;

);



);



If OrderValue (cnt, VAL_TYPE) = OP_SELL then / / open short

(



/ / if cci2 <-100 and cci1> -100 then



if cci2 <-100 and cci2
(

CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), ask, 3, Violet);



Exit;

);



);



);

);)



A second expert, with the additional condition of RSI.



/ * [[

Name: = CCI2

Author: = forextimes.ru

Link: = www.forextimes.ru

Lots: = 1.00

Stop Loss: = 100

Take Profit: = 200

Trailing Stop: = 0

]] * /

Defines: perCCI (14), perRSI (14), RSIUp (60), RSIDown (40) / / period CCI, RSI, RSI levels

var: cnt (0), cci1 (0), cci2 (0), rsi1 (0);



if CurTime-LastTradeTime <8 * 3600 then exit;



cci1 = icci (perCCI, 1);

cci2 = icci (perCCI, 2);

rsi1 = irsi (perRSI, 1);



if TotalTrades = 0 then (

If FreeMargin <1000 then Exit;



if cci2 <0> 0 and cci1 <100 and rsi1
SetOrder (op_buy, lots, ask, 3, bid-stoploss * point, bid + takeprofit * point, blue);

exit;);

if cci2> 0 and cci1 <0> -100 and rsi1> RSIUp then (

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

exit;);



);



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 cci2> 100 and cci1 <100 then



/ / if cci2> 100 and cci2> cci1 then

(



CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), Bid, 3, Violet);



Exit;

);



);



If OrderValue (cnt, VAL_TYPE) = OP_SELL then

(



if cci2 <-100 and cci1> -100 then



/ / if cci2 <-100 and cci2
(



CloseOrder (OrderValue (cnt, VAL_TICKET), OrderValue (cnt, VAL_LOTS), ask, 3, Violet);



Exit;

);



);



);

);)







Company

Halhalyan Arthur

Technical support for traders

artur@fxtest.ru

No comments: