Monday, February 2, 2009

Education MQL II. Lesson 7



Hello dear readers! Today, as I promised, we will write expert. Letters came not so much the most interesting algorithm was Merab trader from the city of Kharkov.



7.1. Algorithm



The essence of an expert in increasing the size of the lot after the closure of unprofitable transaction. This method is called Martingel. After a loss to a new position with an increased number of lots, and the resulting profit to cut past losses. Our expert will be fairly simple, but the method can be developed indefinitely. Signaled to the action (for the first buying or selling in the absence of open positions) will turn the indicator MACD (fast MACD). Purchase is carried out at the opening of the next bar, while the negative MACD, formed the extreme, selling, by contrast, respectively. The signal to the first transaction has been chosen randomly, you can use any other. The game is scheduled for taymfreyme, M15 and nearby. Upon receipt of the loss (stoploss is triggered), a new position in the same direction, if the second time received a loss, the position opens again in the same direction, but the last time. Ie we have only 3 positions, which may occur in one direction, it is done in case of a large trend. If there is a strong and long-lasting trend, we get a big loss, but does not lose the deposit. Configures averaging periods MACD, all stoplossa 3, 3 teykprofita, and 3, the number of lots. The setting for an expert, I did not, it should be done under a specific tool and specific taymfreym. Do you need the expert, you decide. For me, these methods are very, not psychologically comfortable. But on Martingela been a large number of conversations in the forums, I am pleased that we are a little touched upon this topic. Perhaps someone from readers interested in them and would eventually be convinced of the contrary. In the expert setting is very important, you can also change the signal to the first step. If you, dear readers, have questions, be sure to write, I will try to help you.



In the next issue we will begin to write your own indicators.



7.2. Expert



/ * [[

Name: = Expert

7Author: = fxtest.ru

Link: = forextimes.ru

Lots: = 1.00

Stop Loss: = 0

Take Profit: = 0

Trailing Stop: = 0

]] * /

defines: MACDfast (12), MACDslow (26), MACDsignal (9), sl1 (30), sl2 (30), sl3 (30), tp1 (20), tp2 (20), tp3 (20), lot1 (1 ), lot2 (2), lot3 (7);



/ * Description of external variables, settings, MACD, the foot and the number of lots * /



var: macd1 (0), macd2 (0), macd3 (0), b1 (0), ss (0), sb (0), fb (0), fs (0);

/ *

macd1-macd3 - meaning fast MACD

b1-balance to open the last position

ss-number of open items for sale

sb-number of open positions for buying

fb-MACD signal to the first purchase

fs-MACD signal to the first sale

* /



if FreeMargin <1000 then exit; / / output in the lack of a free margin



if TotalTrades = 0 then (/ / if no open positions



if balance> b1 then (fb = 0; fs = 0; ss = 0; sb = 0;)

/ * If your balance has increased since the closure of the last transaction is set to zero all the variables * /



macd1 = iMACD (MACDfast, MACDslow, MACDsignal, MODE_MAIN, 1); / * calculation of fast MACD * /

macd2 = iMACD (MACDfast, MACDslow, MACDsignal, MODE_MAIN, 2);

macd3 = iMACD (MACDfast, MACDslow, MACDsignal, MODE_MAIN, 3);



if macd1 <0> macd2 andmacd3> macd2 and sb = 0 and ss = 0 then fb = 1;

if macd1> 0 and macd2> 0 and macd3> 0 and macd1


/ * extrema conditions * /



if fb = 1 and sb = 0 then / * if there was a signal to buy and this is the first order is to buy

signal to cancel the purchase equal to 1 meter of open positions in purchasing, fixed current balance * /

(fb = 0; sb = 1; b1 = Balance; SetOrder (op_buy, lot1, ask, 3, bid-sl1 * point, bid + tp1 * point, green); exit;);



if Balance


/ * If the balance has decreased, and was opened on 1 position, equating to a 2 meter open positions for buying and open 2 nd position * /



(sb = 2; b1 = Balance; SetOrder (op_buy, lot2, ask, 3, bid-sl2 * point, bid + tp2 * point, green); exit;);



if balance


/ * If the balance has decreased, and was opened on 2 nd position, equating to 0 count of open positions for buying and opening the 3rd position

0 is equivalent since This last entry in the series * /



(fb = 0; sb = 0; SetOrder (op_buy, lot3, ask, 3, bid-sl3 * point, bid + tp3 * point, green); exit;);



/ / Sales



if fs = 1 and ss = 0 then



/ * If there was a signal to sell, and this is the first order is to sell the signal to cancel the sale and equated to 1 meter of open positions in sales, recorded current balance * /



(fs = 0; ss = 1; b1 = Balance; SetOrder (op_sell, lot1, bid, 3, ask + sl1 * point, ask-tp1 * point, red); exit;);



if Balance


/ * If the balance declined to equate it to sell 2 of the count of open positions on the sale, recorded current balance * /



(ss = 2; b1 = Balance; SetOrder (op_sell, lot2, bid, 3, ask + sl2 * point, ask-tp2 * point, red); exit;);



if balance


/ * If the balance is reduced to sell for the last time * /



(ss = 0; SetOrder (op_sell, lot3, bid, 3, ask + sl3 * point, ask-tp3 * point, red); exit;);



);





Company «Fxtest»

Halhalyan Arthur

Technical support for traders

artur@fxtest.ru

No comments: