mql ii training & expert advisors (alpari)
TRANSCRIPT
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
1/75
Experts Advisors - mechanical trading
systems on MetaQuotes Language II
The trader makes a decision on an input in the market(or closing of a position) in case ofobservance of the certain conditions, i.e. adheres to the certain algorithm at opening and closing
of positions. Such algorithm usually name trading tactics(Expert Advisors). sually they are!ritten and tested in such kno!n analytical packages as "etaStock or TradeStation. #ut ho! to
connect trading tactics !ith the real account$ To connect so that it is direct from expert system to
kno! and operate at any moment the open positions exposed by !arrants and stops... %hether&robably such$ 'es, such it is possible in "etaTrader.
%hat the counselor or Expert Advisor represents$ t is the mechanical trading system("TS)!ritten in specialied language "eta*uotes +anguage("*+) and having a binding to the
certain schedule. The counselor can !ork not only in a mode of informing on an opportunity to
make the transaction, but can automatically make also transactions on trading to the account,directing orders directly on a trading server. The code of the counselor can be closed from
extraneous eyes by the pass!ord. Expert Advisors support testing strategy for the historical
data !ith display on schedules of a point of opening - closing of a position.
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 0 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
2/75
http://www.alpari.org/ru/experts/articles/mql2/1.php
Training MQL II
7Section Experts8 70 7408 9/: 94:
The Lesson # 1
1.1 From the author
;ello, dear readers< "y name is ;alhal=an Arthur, am the author of pro=ect >xtest.ru, !e
professionally are engaged in development and realiation of mechanical trading systems. ,
probably, am better than others kno!, as far as, this heading, since ?5 @ of our orders, it =ustexperts on "*+ under much kno!n terminal "eta Trader (further bude to name it "T) is
necessary for traders. shall not result here comparative tables and characteristics, but in my personal opinion "T for today is the most successful domestic terminal, for trade on >orex and>B. As, only it has the built C in environment of programming. That "T many our and use
some !estern dilingovye the centers is important also. >or the sake of =ustice, it is necessary to
notice, that "T has a number of restrictions and defects, and his ideal terminal to name
difficultly, but !e shall hope for his further improvement by developers.
oncerning mechanical trade already there !as a uncountable Duantity of disputes, think, there
is no sense to press in polemic. >or a Duestion this almost rhetorical, and trading strategy and a
!ay of its realiation, the private affair of everyone. #ut am deeply confident, that theopportunity a !riting of experts is useful to any trader. %ith help "*+ it is possible not only to
create experts for trade, this %ednesday programming opens enough ample opportunities. The!riting of o!n indicators, gathering of the statistical information from the historical data, the
every possible assistants, notifying a sound signal about those or others changes in the market,all this !ill be to you under force.
o! the computer became an integral part of many technological processes. t is especially
actual for problems of great volumes the digital information connected to processing !ith !hat
!e and collide at a stock exchange. All kno!, that at a stock exchange those players !ho aremuch stronger than the ma=ority !in only. ertainly, in a !ord some parameters are more
strongly included, and one of important is technical maintenance of the trader.
Summing up, !ant to tell. These lessons !ill be useful to all traders using a technical expertisein trade, and !ishing to expand the opportunities.
1.2 Creation of the first expert
>or creation of the first expert it is feasible the follo!ingF
0. %e shall start "T.
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 4 of 23
http://www.alpari.org/ru/experts/articles/mql2/1.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fmarkets%2Fforex%2Fforex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fmarkets%2Fforex%2Fforex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fmarkets%2Fcfd%2Fcfd.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.alpari.org/ru/experts/articles/mql2/1.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fmarkets%2Fforex%2Fforex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fmarkets%2Fcfd%2Fcfd.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
3/75
4. n the dropping out menu "ervice", !e shall click on " Editor MetaQuotes Language", or !e shall press !.
/. #efore you the environment of programming "eta Editor .G. Hn panels of tools or from the menu "!ile" press an icon "e$", also it is possible to
use %trl&.
3. n the appeared menu choose " Expert Advisor 'rogram ".1. n the follo!ing menu, under the order enterF the name, the author, the reference, the
note, Duantity lotov("Lots"), stoploss(" top Loss "), te=kprofit(" Ta(e pro)it ") and
tre=lingstop(" Trailing top ").2. %e shall press "!urther" and "is ready".
6. Hn the screen !e shall see the beginning of a code of our expertF
/*[[Name: = Expert1Author: = Your namein!: = http: // "our.we#siteots: = 1.$$
%top oss: = &$'a!e (ro)it: = $'railing %top: = 2$++*/
All data !hich have been entered at creation of the expert, !ere displayed in the beginning(cap) of his code. At desire you can change any value. IariablesF "Lots", "top Loss "(in a code of the expert, further Stop +oss it is !ritten !ithout a blank as
!ell both follo!ing variables), " Ta(e 'ro)it " and " Trailing top " are registeredvariables "*+ and !ill directly participate in !ork of the expert. >rom a tester !hich is
directly in "T, these variables can be changed, entered at creation of the expert of value
!ill be values poumolchani=u.
?. >urther go sectionF "de)ines", "array" and "var". #ehind them there is a body of theexpert.
05. Add to the expert the follo!ing blockF
,e)ines: per1-$Arra": Arra"Name[1..&+-$0ar: per2-$
n section "de)ines" external variables !hich values can be changed in a tester are
described. n section "Array", files, and section "var" are described is necessary for the
description of internal variables, the expert. After the name of section the colon is put,then go the name of variables, after the name in brackets value of a variable by default(at
us variables are by default eDual 5) is underlined, after the termination of the description
of any section the semicolon is put. n section of files, after the name of a file in sDuare brackets there is his dimension. n our case it is an oneCdimensional file from /o
elements, value of each element by default eDually 5. per1 and per* are names of
variables, Arrayame C the name of a file. %e shall discuss detailed rules of the
description of variables at the follo!ing lesson.
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age / of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
4/75
00. After these three sektsy there is body of the expert. t is necessary to note, that any of
sektsy can not be, also can not be and any of sektsy. The body of the expert can be made
bet!een operators +egin,,, end, and can be bet!een braces .,,,/, choose.
04. #y tradition !hich has developed at studying programming languages, !e shall deduce
on the screen a !ord &rivet, or any another. n "*+ there are some functions for aconclusion of the text, !e shall take advantage of function %omment.
0/. %e shall add to the text of the program this function in braces.
omment-3(ri0et34
After function !e finish. The deduced !ord should be in double inverted commas and
parentheses.
0G. %e receive the text of the programF
/*[[Name: = Expert1Author: = "our namein!: = http: // "our.we#siteots: = 1.$$%top oss: = &$'a!e (ro)it: = $'railing %top: = 2$++*/
,e)ines: per1-$Arra": Arra"Name[1..&+-$0ar: per2-$
omment-3(ri0et34
03. %e click on !0 or on an icon !ith a tick on the panel of problems for compilation of ourexpert.
01. %e come in "T, in navigator(%trl&) in vkladke ounselors, !e find our expert.
%e click on it 4 times a mousy, !e agree to attach it to the schedule.
n the appeared !indo! it is chosen vkladku Testing of strategy . n this !indo! in aright top corner !e choose model of testing " 2L% point3)ast4 " and !e press +utton" tart ".
02. Hn the termination of testing in the left top corner of a !indo! !ith bars it is seen our
!ord &rivet.
n the follo!ing lesson !e shall study lexicon of language "*+ . n more details
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age G of 23
http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
5/75
'ours faithfully, ;alhal=an Arthur.
arturJfxtest.ru
fxtest.ru
The original of clause C >HKEL "AMANE $ 0 from 54.54.455G
7Section Experts8 70 7408 9/: 94:
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 3 of 23
mailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D1%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D1%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
6/75
The Lesson # *
;ello, dear readers. Today !e shall in details disassemble types of variables, !e shall getacDuainted to operators of giving and the instruction i) - then.
2.1 Variables of numerical type
Iariables as you kno!, are necessary for storage of any information, !ith an opportunity at any
moment to it to address or change her. Iariables of numerical type, on logic store numbers.
0ar: 5-$6 N-$ // 7nternal 0aria#les 5 an, N6 poumolchani8u// their 0alues it is equal $.// 'hese are 0aria#les o) numerical t"pe since on
// to ,e)ault the" are equal to the speci)ie, num#er// the termination o) the ,escription o) 0aria#les6 as well as// an" other instruction 9// )inishes 33 . 7) "ou ha0e notice, #e)ore// each line there is a ,ou#le slash // so one;line comments/* are ,esignate, 7s alrea," usual6 polnostrochn"8 the comment */
5=1// gi0ing is carrie, out usual is )amiliar// equalit" 3=3
N=1$*2// in the right part can #e written ,own mathematical// expressions with )our the #asic mathematical // actions
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
7/75
// 0aria#les o) line t"pe since poumolchani8u are equal to a text line// the name o) a 0aria#le can to comprise )igures6 #ut the name o) a0aria#le // cannot #egin with )igure
string& = 3slo0o3string&=string1or wor! with text lines there is onl" one line operator6 the 0aria#lestring& is ,esignate, 3alse(lie) is formed. t is less C OPO , aieuoa C OQ O, it is
eDual C O R O, it is not eDual C OPQ O, it is less than or eDual C OPRO aieuoa eee $aaii C OQ R O.
2.4 Instruction if-then
&robably, there is no trading expert !ho has no this instruction. Since the situation in the market
all time varies all time is necessary that that !ith !hat that to compare or check. >or this purposethis instruction also is used.
f(condition) then(action an event at the validity of a condition)else(action an event at lohnosti conditions)
else is a unessential part of the instruction.
ExampleF
7) !? n then !=!
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
8/75
These variables can have only 4 values True(true) or >alse(lie). They are used as flags allo!ing
something or forbidding. %ith variables of logic type logic operators !orkF and, or, not.
@ar: !-'rue6 n-)alse! = >ree9argin? = 1$$$
7) not ! then exit4
There is a compulsory output from the expert if free marha less or it is eDual 0555.
%e can !rite also i) (56 True or i) (7!alse and all this !ill have one sense. nstead of !hat
after i) to !rite a logic variable and to check her on eDuality true, it is possible to !rite simply a
variable, and instead of check on eDuality >alse, before a variable the logic operator not, as inour case is put.
7) !? $ an, #? $ then exit
The operator and(E) groups conditions, action after then !ill be executed only at the validity ofall conditions.
7) !? $ or #? $ then exit
The operator or(or) chooses even one true condition. .e. if any of t!o variables is more 5 that
action !ill be executed.
The operator not(not), is applied to logic variables. >or variables of numerical type the relative
operator not eDually is used 56.
'ours faithfully, ;alhal=an Arthur.artur)xtest.ru )xtest.ru
'he original o) clause ; >BCED 9AAF7NE G 2 )rom $H.$2.2$$I
[%ection 3Experts3+ [1 [21+ &414
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 6 of 23
mailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D2%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F1.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F1.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D2%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F1.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
9/75
The Lesson # 8
;ello dear readers< &robably, t!o previous lessons !ere not so interesting since it !asimpossible to see results of the !ork personally. #elieve, they !ere necessary for the further,
highCgrade !ork. n this lesson !e shall learn to open positions and !e shall disassemble syntax
of the reference to a file of Duotations.
3.1 Function "et#r$er
%ith the help of function etrder it is possible to open positions on purchase and sale under
the current price or to place the postponed !arrants.
%etBr,er-operation6 lots6 price6 slippage6 stoploss6 ta!epro)it6 color
•
operation C type of operation(opbuy, opsell, opbuylimit, opbuystop, opselllimit oropsellstop)
• lots C Duantity lotov
• price C the price of the transaction or the postponed !arrant
• slippage C as much as possible allo!able proskalyvanie
• stoploss C level Stop +oss of the !arrant
• ta(epro)it C level Take &rofit of the !arrant
• color C color on the schedule.
3.1.1. #peration%operations&
Hperation can divide 4 kinds, it is an input under the current price or installation of the postponed !arrant.
>or an input under the current price operation !ill look likeF op9+uy or op9sellF
• p9+uy C purchase of the contract under the current price, in price should be specified
as( .
• p9sell C sale of the contract under the current price, in price should be specified +id.
>or exhibiting the postponed !arrant operation !ill look likeF op9+uylimit, op9+uystop,
op9selllimit or op9sellstop.
f !e !ant to expose the postponed !arrant on purchase provided that the current price +elo$ the prices of execution of the !arrant operation !ill look like op9+uystop. .e. !e plan, that the
price !ill go further in the same direction(on breakdo!n, up!ards).
f !e !ant to expose the postponed !arrant on sale provided that the current price +elo$ the
prices of execution of the !arrant operation !ill look like op9selllimit. .e. !e plan, that the price !ill be developed and there !ill be in an opposite direction(turn).
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age ? of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
10/75
f !e !ant to expose the postponed !arrant on purchase provided that the current price a+ove
the prices of execution of the !arrant operation !ill look like op9+uylimit. .e. !e plan, that the
price !ill be developed and there !ill be in an opposite direction(turn).
f !e !ant to expose the postponed !arrant on sale provided that the current price a+ove the
prices of execution of the !arrant operation !ill look like op9sellstop. .e. !e plan, that the price!ill go further in the same direction(on breakdo!n, do!n!ards).
3.1.2. 'ots% loty &
>or the instruction of Duantity lotov in the !arrant, you can !rite particularly number, for
example, 0 or 4. recommend to !rite reserved variable Lots since in "T you can directly putany Duantity lotov, thus your expert becomes more flexible.
3.1.3. (rice%the price of execution of the )arrant&
>or an input under the current price operations op9+uy or op9sell, it is necessary to use the prices as( and +id accordingly. >or an input the postponed !arrants it is possible either to !ritethe concrete price or to use expression of such kindF UU ask/5Upoint UU. %hat does it mean$ t
means current ask(for example, 0.4655) to add /5 items, i.e. the price of an input 0.46/5. 'oint
is the price of item on concrete currency pair, for EKSB pointR5.5550, for SBV&' pointR5.50. The price of item !ill be defined itself, it "T !ill make for you. t is possible to
!rite and soF as(&:,:::1 and it !ill be correct but !hat to connect such expert to SBV&' it it
!ould be necessary to alter. >or a !riting of more flexible experts recommend to use al!aysthe reserved variable point.
3.1.4. "lippa!e% pros*al+yvanie &
f proskalyvanie !ill make the big sie, than specified operation of the !arrant !ill be re=ected.
"ost likely(if a condition of an input !ill not change) the expert !ill try to open repeatedly a position, and !ill open it only in the event that proskalyvanie !ill make sie less specified.
3.1.. "toploss% stoploss &
t is necessary to understand, that stoploss it is simple value of the price at !hich the position
!ill be closed compulsorily. T.e in a field stoploss, it is possible to !rite the concrete pricesimply.
>or the instruction stoplossa recommend to leave a variable stoploss, and at creation of theexpert(or in a cap of the expert) to expose the necessary sie. Bue to this your expert becomes
more flexible and the sie stoplossa can be changed directly in "T, in ad=ustments of the expert.
Expression !ill look likeF UU askstoplossUpoint UU. t is fair for constant stoplossa.
f you !ant to have dynamic(changing) stoploss, it can be considered in a variable. >or exampleF
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 05 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
11/75
" sl7L;1
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
12/75
3.2. he reference to a file to uotations
'ou can use these names or reduced, they in brackets. Keferences to files of Duotations it iscarried out, as !ell as to usual elements of a file through sDuare brackets. The index 5, is the
current bar, 0 last, etc. .e. c;1HKEL "AMANE $ / from 01.54.455G
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 04 of 23
mailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D3%26idpart%3D2mailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D3%26idpart%3D2
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
13/75
7Section Experts8.. 74 7408 9G: 94:
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 0/ of 23
http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F4.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F4.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F4.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F2.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
14/75
The Lesson #
;ello, dear readers. Today !e shall get acDuainted to operators of cycles. Also !e shall !rite the
ne! expert.
4.1. he !eneral sve$ena about cycles
The cycle is an operator !ho repeats a fragment of the program the prisoner in a body of a cycle
until !ill !ork a condition set by the user. ycles are freDuently used for !ork !ith files, in our
case it is files from Duotations or values of indicators.
3c;:< &c;1< &c;*8 is average arithmetic three prices, or simple sliding average !ith the period
of averaging /. #ut business is much more difficultly if it is necessary to take average arithmetic!ith the period /5, for this purpose it is much easier to use a design of a kindF
)or i=$ to &$sr=sror example,
freDuently it is necessary to find maximal ;igh or minimal +o!, for some last bars, for
exhibiting stoplossa.
+etOs find minimal +o!, for installation stoplossa for longa. Search !e shall carry out from last
05 bars(generated).
9in=[1+>or i=1 to 1$i) [i+ Kmin then min=[i+4
+etOs find maximal ;igh, for installation stoplossa for shorta.
9axL=L[1+>or i=1 to 1$i) L[i+? 9axL then 9axL=L[i+4
o! !hile in details to disassemble the cycles available in "*+.
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 0G of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
15/75
4.2. Cycle For
ycle >or provides performance of the instructions made in a body of a cycle specified user,number of times.
)or i = 1 to 1$ #egin// a #o," o) a c"cleen,
i C it is a variable !hich !ill increase for unit, on each iteration of a cycle. n our example initial
value of a variable is eDual 0, final 05, t.e the cycle of 05 times !ill execute a body of a cycle.nitial and final value can be anyone, but final should be more. f you !ant, that the cycle
counted a variable in other party(aside reduction) instead of key!ord To it is necessary to use
?o$nto.
)or i=1$ ,ownto 1 #egin// a #o," o) a c"cleen,
This cycle also !ill be executed 05 times, only the variable !ill decrease from 05 up to 0.
4.3. Cycle hile
This cycle, differs from !or that the Duantity of iterations is not kno!n beforehand. The body of
a cycle is carried out, !hile the condition of a cycle is satisfied.
while a? ##egin// a #o," o) a c"cle
en,
a6 + is a condition of a cycle.
4.4. Instruction rea*
nstruction @rea( ahead of schedule interrupts performance of cycle !or or hile. t is actual if
the cycle is used for search of any element, and it has been found. This instruction can be appliedonly in a body of a cycle. f some cycles are enclosed each other the nearest cycle(a cycle in
!hich body the instruction is enclosed directly) interrupts.
)or i=1 to 1$$
i) l[i+? l[i
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
16/75
4.. Instruction Continue
nstruction %ontinue ahead of schedule interrupts performance of the current iteration and begins performance of a cycle all over again. t is the instruction it is applied, for example, !hen
already clearly, that at the given stage of the necessary element is not present and it is necessary
to go further, not executing some instructions in a body of a cycle.
4.,. he expert
Today !e shall !rite the expert for game on ravorotnyh candles molot and hung up, in their
strongest displays !hen the prices of opening and closing are eDual(!ithout a body). Algorithm
not complex. f after the bull movement !e have a candle !ith a long top shado! and short bottom !e !ait the follo!ing bear candle and on its closing !e sell. f after the bear movement
!e have svechku !ith a long bottom shado! and short top !e !ait bull svechki and !e buy.
Stoplossy !e place on long shado!s plus, the specified Duantity of items.
/*[[ Name: = Expert&Author: = >xtest.ruin!: = )orextimes.ruots: = 1.$$%top oss: = 2$'a!e (ro)it: = I$'railing %top: = $
++*/
,e)ines: tenmax1-1$6 tenmin1-6 telo,o1-0ar:tenmax-$6 tenmin-$6 telo,o-$
// Me multipl" all 0aria#les not the price o) itemtenmax=tenmax1*point // a long sha,owtenmin=tenmin1*point // a short sha,owtelo,o=telo,o1*point // a #o," o) a #ar up to ra0orotno8 can,lesi) 'otal'ra,es=1 then exit // we lea0e i) there is an open position
i)--o[I+;c[I+? telo,o an,-o[&+;c[&+? telo,oor-o[&+;c[&+? 2*telo,othen // or one in 2 times is more than 2 a0erage
// a con,ition on purchase presence o) a ,escen,ing tren,// )rom 2o not short s0eche86 or last long #ear
i) o[2+ =c[2+ an,-h[2+;o[2+ Ktenminan,-o[2+;l[2+? tenmax an, o[1+? c[1+then
%etBr,er-opJ#u"6 16 as!6 &6 l[2+;%toposs*point6#i,
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
17/75
At the follo!ing lesson !e shall start to study the indicators !hich have been built C in in "T.
'ours faithfully, ;alhal=an Arthur.arturJfxtest.ru
fxtest.ru
The original of clause C >HKEL "AMANE $ G from 4/.54.455G
7Section Experts8.. 7/ 7408 93: 9/:
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 02 of 23
http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D4%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D4%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F3.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
18/75
The Lesson # B
;ello dear readers<
Today !e shall learn to !rite experts !ith use of the built C in indicators. n "T very many
indicators of a classical technical expertise, so a field for actions rather big are realied. At theend of the lesson !e shall !rite the expert.
.1. "yntax of the in$icator in !eneral5 a *in$
i7n,-perio,6 mo,e6 shi)t
• Ind C the conditional name of the indicator
•
'eriod C the period of averaging• Mode C specifies !hat of values of the indicator more often is accepted(for indicators
from t!o or more lines)
• hi)t C the index specifies, !hat serial value of the indicator to take for calculation(5
these indicators current value, 0Clast, 4Cbefore last, etc. by analogy to indexes at
Duotations)
#efore the name o) indicator Ind there is a letter i, it is necessary for all indicators in "T.
.2. "li$in! avera!e
Sliding average are the most !idespread indicator. Therefore !ould like to disassemble thisindicator in more detail.
i9A-perio,6 maJmetho,6 shi)t
• period C the period of averaging
• ma9method C this parameter is underlined for a method of calculation of average, the
parameter can accept the follo!ing valuesF "HBES"A, "HBEE"A,
"HBES""A, "HBE+%"A
• hi)t C the index specifies, !hat serial value of the indicator to take for calculation(5
these indicators current value, 0Clast, 4Cbefore last, etc. by analogy to indexes at
Duotations).
ExamplesF
• iMA3*1C M?E9MAC 14 C the last value sliding average of simple type !ith the period
of averaging 40
• iMA3DC M?E9EMAC :4 C the current value sliding average eksponentsialnogo type
!ith the period of averaging ?.
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 06 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
19/75
#y default indicators are under construction from the prices of closing, therefore values of
indicators !ith an index 5, t.e the current values on a formed bar all time !ill vary together !ith
the price.
.3. xten$e$%expan$e$& in$icators
As already spoke, indicators are under construction from the prices of closing(close) more
often. t not al!ays satisfies to inDuiries of users, therefore in arsenal "T is extended(expanded)
indicators. #y the current moment exists 2 extended indicatorsF
ABL extendedF
iAODEx-perio,6 applie,Jprice6 mo,e6 shi)t
extendedF
i7Ex-perio,6 applie,Jprice6 shi)t
#olinger bands extendedF
iPan,sEx-perio,6 ,e0iation6 #an,sJshi)t6 applie,Jprice6 mo,e6 shi)t
"AB extendedF
i9AOEx-)astJemaJperio,6slowJemaJperio,6 signalJperio,6 applie,Jprice6 mo,e6 shi)t
"oving average extendedF
i9AEx-perio,6 maJmetho,6 maJshi)t6 applie,Jprice6 shi)t
"omentum extendedF
i9omEx-perio,6 applie,Jprice6 shi)t
KS extendedF
iC%7Ex-perio,6 perio,26 applie,Jprice6 mo,e6 shi)t
f you have noticed, any of the expanded indicators has a parameter applied9price. This
parameter can accept 2 valuesF &KE+HSE, &KEH&E, &KE;M;, &KE+H%,&KE"EBA, &KET'&A+ and &KE%EM;TEB. .e. the indicator can be under
construction from the price of closing, the price of opening, a ceiling price, a floor price,&KE"EBA((highlo!)-4), &KET'&A+((highlo!close)-/),&KE%EM;TEB((highlo!closeclose)-G). All names of the expanded indicators come to
an end letters Ex, and only it differ from names of the same standard indicators.
.4. he expert
>or fastening kno!ledge, !e shall !rite the expert. t !ill use 4 indicators, sliding average !ith
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 0? of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
20/75
the big period and KS. f KS is higher than the top one determined by us, it !as developed
do!n!ards and average is directed do!n!ards the expert !ill sell. f KS belo! bottom one, it
!as developed up!ards and average is directed up!ards it is bought. The output from a positionis carried out on the exposed stops.
/*[[
Name: = ExpertIAuthor: = >xtest.ruin!: = )orextimes.ruots: = 1.$$%top oss: = I$'a!e (ro)it: = I$'railing %top: = $++*/
,e)ines: per-Q6 Rpone-Q$6 Oownone-&$6 Pig'ren,-1$$// per ; perio, C%7// Rpone6 Oownone ; o0eron"6// Pig'ren, ; the perio, o) a0erage showing a glo#al tren,
0ar: r1-$6 r2-$6 m1-$6 m2-$// r1;last 0alue C%7 r2;#e)ore last 0alue C%7
r1=iC%7-per6 1r2=iC%7-per6 2m1=i9A-Pig'ren,6 9BOEJ%9A6 1 // 9A simple t"pe-%9Am2=i9A-Pig'ren,6 9BOEJ%9A6 2
i) 'otal'ra,es K1 then// to pla" i) open positions are not present
i) r2? r1 an, r2? Rpone an, m1 Km2then// i) the extremum was )orme, an, it is higher than the top one6// an, a glo#al tren, ,ownwar,s6 sell
%etBr,er-opJsell6 lots6 #i,6 &6 as!
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
21/75
arturJfxtest.ru
fxtest.ru
The original of clause C >HKEL "AMANE $ 3 from 50.5/.455G
7Section Experts8.. 7G 7408 91: 9G:
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 40 of 23
mailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D5%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F6.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F4.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F6.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F4.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D5%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F6.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F4.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
22/75
The Lesson #
;ello dear readers< Today !e shall learn to supervise open positions. At the end of the lesson !eshall !rite the expert. Serious difference of this expert from last !ill be that the output from a
position !ill be carried out not only on stop to the !arrant, but also on a condition of closing.
,.1. 6uantity of open positions
>or Duantity of open positions variable TotalTrades ans!ers. f you !ant to have al!ays onlyone open position it is possible to use a designF
7) 'otal'ra,es=$ then//..
4
Hr
7) 'otal'ra,es=1 then exit
,.2 Function #r$erValue
>unction rder=alue parameters of value of an open position.
SyntaxF Br,er@alue-position6 mo,e
• 'osition C a serial number of an open position
• Mode C this parameter to accept set of values depending on that !hat parameter of an
open position it can is necessary to receive.
Mode can have the follo!ing appearanceF
• =AL9%LE'FI%E C the current price of closing
• =AL9%LETIME C vrem=aakryti=a
• =AL9%MMET C the comment
• =AL9LT C Duantity lotov
• =AL9'E'FI%E C the price of opening of a position
• =AL9'ETIME C time of opening of a position
• =AL9 'F!IT C current profit
• =AL9T'L C the price of operation stoplossa
• =AL9A' C the current s!ap for carry of a position
• =AL9GM@L C currency pair
• =AL9TAHE'F!IT C the price of operation te=kprofita
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 44 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
23/75
• =AL9TI%HET C number of a position
• =AL9TG'E C type of a position(buy, sell, etc.).
;aving some open positions, or even one, for identification of parameters of an open position are
convenient to use a cycle )or.
)or cnt=1 to 'otal'ra,es // it is an open positionG B(JPRY or B(J%E
i) Br,er@alue-cnt6 @AJ'Y(E K=B(J%E an,Br,er@alue-cnt6 @AJ%Y9PB =%"m#ol then // the tool coinci,esG
7) Br,er@alue-cnt6 @AJ'Y(E =B(JPRY then
// the long position actions 4 44
s open
,.3. Function 7o$ify#r$er
This function is necessary !hat to change established stop the !arrant and te=k profit. >or
example, this function is used for podhati=a stoplossa(tre=ling stop).
SyntaxF
9o,i)"Br,er-or,er6 price6 stoploss6 ta!epro)it6 color
• rder C on this parameter identification of the concrete !arrant is carried out
• toploss C ne! stoploss• Ta(epro)it C ne! te=kprofit
• %olor C color in !hich the badge on the schedule of the prices !ill be painted.
Example of change stoplossaF
7) 'railing%top? $ then // the user has expose, in a,8ustments tre8ling;stop // means we go it to chec!
7)-Pi,;Br,er@alue-cnt6 @AJB(EN(C7E?-(oint*'railing%top then
7) Br,er@alue-cnt6 @AJ%'B(B%% K-Pi,;(oint*'railing%top then
9o,i)"Br,er-Br,er@alue-cnt6 @AJ'75E'6 Br,er@alue-cnt6
@AJB(EN(C7E6Pi,;(oint*'railing%top6 Br,er@alue-cnt6 @AJ'A5E(CB>7'6 Ce,Exit
4 4 44
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 4/ of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
24/75
,.4 Function Close#r$er
%ith the help of this function closing an open position is carried out. "ore often it occurs atoperation of the established condition. .e. together !ith the operator i)-then.
SyntaxF
loseBr,er-or,er6 lots6 price6 slippage6 color
• rder C on this parameter identification of the concrete !arrant is carried out
• Lots C Duantity lotov at an open position
• lippage C proskalyvanie
• %olor C color in !hich the badge on the schedule of the prices !ill be painted.
ExampleF
loseBr,er-Br,er@alue-cnt6@AJ'75E'6 Br,er@alue-cnt6 @AJB'%6 Pi,6 &6 @iolet
,. xpert
>or a basis !e shall take the expert from the last lesson, since his purpose C fastening of amaterial.
/*[[Name: = ExpertAuthor: = >xtest.ruin!: = )orextimes.ruots: = 1.$$
%top oss: = S$'a!e (ro)it: = S$'railing %top: = $++*/
,e)ines: per-Q6 Rpone-Q$6 Oownone-&$6 Pig'ren,-1$$// per ; perio, C%7// Rpone6 Oownone ; o0eron"// Pig'ren, ; the perio, o) a0erage6 showing a glo#al tren,
0ar: r1-$6 r2-$6 m1-$6 m2-$6 cnt-$// r1 ; last 0alue C%7// r2 ; #e)ore last 0alue C%7
r1=iC%7-per6 1r2=iC%7-per6 2m1=i9A-Pig'ren,6 9BOEJ%9A6 1 // 9A simple t"pe-%9Am2=i9A-Pig'ren,6 9BOEJ%9A6 2
i)'otal'ra,es K1 then // to pla" i) open positions are not present
// i) the extremum was )orme, an, it is higher top o0eron"6
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 4G of 23
http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
25/75
// an, a glo#al tren, 0nih6 selli)r2? r1 an,r2? Rponean,m1 Km2 then
%etBr,er-opJsell6 lots6 #i,6 &6 as!
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
26/75
'ours faithfully, ;alhal=an Arthur.
arturJfxtest.ru
fxtest.ru The original of clause C >HKEL "AMANE $ 1 from 56.5/.455G
7Section Experts8.. 73 7408 92: 93:
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 41 of 23
mailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D6%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F7.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F7.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D6%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F7.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F5.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
27/75
The Lesson # 0
;ello, dear readers< n this lesson !e shall !rite the expert. +etters has come not so much, themost interesting the algorithm of trader "eraba from Wharkov !as.
/.1. 8l!orithm
Essence of the expert in increase in the sie lota after closing the unprofitable transaction. This
method refers to "artingel. After reception of the loss the ne! position !ith the increasedDuantity lotov opens, and received profit should block the last losses. Hur expert !ill be rather
simple, but the method can be developed indefinitely. A signal to action(to the first purchase or
sales at absence of an open position) !ill be a turn of indicator "AB(fast "AB). &urchase iscarried out at opening of the follo!ing bar, at negative "AB, formed an extremum, sale, on the
contrary, accordingly. The signal to the first transaction has been chosen casually, it is possible touse any another. Mame is planned on ta=mfre=me 03 and next. After reception of the loss(!orksstoploss), the ne! position in the same party if second time is received the loss opens, the
position opens again in the same party, but last time. .e. %e have only / positions !hich can
open in one party, it is made on a case of the big trend. f there !ill be a strong and long trend,
!e shall receive a heavy loss, but !e shall not lose the deposit. The periods of averaging "AB,all / stoplossa, / te=kprofita, and / Duantities lotov are ad=usted. !as not engaged in ad=ustment
of the expert, it is necessary to do it under the concrete tool and concrete ta=mfre=m.
0,*, The expert
/*[[Name: = ExpertQAuthor: = )xtest.ruin!: = )orextimes.ruots: = 1.$$%top oss: = $'a!e (ro)it: = $'railing %top: = $++*/
,e)ines: 9AO)ast-126 9AOslow-26 9AOsignal-H6 sl1-&$6 sl2-&$6,e)ines: sl&-&$6 tp1-2$6 tp2-2$6 tp&-2$6 lot1-16 lot2-26 lot&-Q
/*7ienaiea External 0aria#les6 a,8ustment 9AO6 stops an, quantit" loto0 */
0ar:mac,1-$6 mac,2-$6 mac,&-$6 #1-$6 ss-$6 s#-$6 )#-$6 )s-$
/*mac,1;mac,&;0alues )ast 9AO#1;#alance #e)ore opening the last positionss;quantit" o) open positions on sales#;quantit" o) open positions on purchase
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age 42 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
28/75
)#;signal 9AO to the )irst purchase)s;signal 9AO to the )irst sale*/
i) >ree9argin K1$$$ then exit // an output at shortage )ree marhe
i) 'otal'ra,es=$ then // at a#sence o) open positions
i) #alance? #1 then )#=$ )s=$ ss=$ s#=$4
/* 7) the #alance has increase, a)ter closing last transactionto null all 0aria#les */
mac,1=i9AO-9AO)ast6 9AOslow6 9AOsignal6 9BOEJ9A7N6 1/* calculation )ast 9AO*/mac,2=i9AO-9AO)ast6 9AOslow6 9AOsignal6 9BOEJ9A7N6 2mac,&=i9AO-9AO)ast6 9AOslow6 9AOsignal6 9BOEJ9A7N6 &
i) mac,1 K$ an, mac,2 K$ an, mac,& K$ an, mac,1? mac,2
an, mac,&? mac,2 an, s#=$ an, ss=$then )#=1
i) mac,1? $ an, mac,2? $ an, mac,&? $ an, mac,1 Kmac,2an, mac,& Kmac,2 an, ss=$ an, s#=$then )s=1
/*oneiae" Extrema */
i) )#=1 an, s#=$ then /* i) the signal to purchase was an, it is )irst warrant that to #u"
to cancel a signal to purchase to equate 1 to the counter o) openpositions on purchase6 the current #alance */
)#=$ is )ixe, s#=1 #1=Palance%etBr,er-opJ#u"6 lot16 as!6 &6 #i,;sl1*point6 #i,
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
29/75
i) )s=1 an, ss=$ then /* i) were a signal to sale an, it is )irst warrant that to sell
to cancel a signal to sale an, to equate 1 to the countero) open positions on sale6 the current #alance */
)s=$ is )ixe, ss=1 #1=Palance%etBr,er-opJsell6 lot16 #i,6 &6 as!
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
30/75
The Lesson #
;ello, dear readers< Today !e shall start to study to !rite o!n indicators.
0.1. he user in$icators in the expert
Ialues of the user indicator for his use in the expert are transferred !ith the help of function
i%ustom. nstead of section ?e)ines in experts there is section Inputs, she has the same sense. n
section Inputs there are external variables, their values can be changed, not changing a code ofthe indicator. The indicator can consist their maximum of t!o, a minimum of one data file, the
first is designated "HBE>KST, the second C "HBESEHB.
>or example, section Inputs looks likeF
7nputs: N#ars-$$6 pe,io,-21
.e. at us t!o external variables and the indicator, naprmer , looks like one line. The reference toindicators in the expert !ill look likeF
iustom-39"7n,icator36 $$6216 9BOEJ>7C%'6 $
%hereF
• I%ustom C function user indicators,
• MyIndicator C the name of the indicator, is !ritten in double inverted commas,
•
B:: C value of the first parameter,• *1 C value of the second paremetra,
• M?E9!IFT C the data undertake their first file indiktora,
• : C last value of the indicator(on the current bar).
Expression i%ustom3"MyIndicator"C B::C*1C M?E9!IFTC :4 !ill be identical to this
i%ustom3"MyIndicator"C M?E9!IFTC :4 since parameters of variables are not obligatory but if other values of the indicator !anted to use, than are specified poumolchani=u, it !ould be
necessary to register them necessarily.
0.2. "tructure of the in$icator
As it has been told above instead of section de)ines, in indicators there is section Inputs, the
code of the indicator begins !ith it and. n general that, the very first goes cap of the indicator,
but !e shall consider her in the follo!ing item of the lesson.
7nputs: perio,-216 Pars-$$ // external 0aria#les@ar: per-$6 shi)t-$ // internal 0aria#les
// >urther there is a co,e o) the in,icator
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age /5 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
31/75
"etaEditor automatically creates a code of such kindF
%etoopount-$// loop )rom )irst #ar to current #ar-with shi)t=$>or shi)t=Pars;1 Oownto $ Pegin
%et7n,ex@alue-shi)t6 $En,
t means, that the indicator !ill be dra!n from the beginning of history up to the end, it is
possible to use such kindF
>or shi)t=$ to Pars;1 Pegin%et7n,ex@alue-shi)t6 $
En,
So the indicator !ill be dra!n from the end of history, i.e. from the current bar and to come to anend the last. %hat method you choose to solve to you, but to cost to remember, that complex user
indicators rather strongly brake !ork "T and conseDuently indicators do not appear on all
history. n this case it is better to dra! the indicator from last(current) bar. As you have alreadyunderstood, filling of a file is carried out by a cycle, in this case cycle !or.
>unction etIndex=alue3shi)tC :4 fills in a file of the indicator for each bar. hi)t is a cell of afile of the indicator(one cell is one bar), 5 is a value !hich it !ill be appropriated. Since files can
be t!o, therefore for the second file function looks likeF %et7n,ex@alue2-shi)t6 $.
The indicator !hich !ill form the channel bet!een maximal and floor prices(; and +)F
/*[[Name: = L;lAuthor: = )xtest.ruin!: = )orextimes.ru%eparate Min,ow: = No>irst olor: = Plue>irst Oraw '"pe: = ine>irst %"m#ol: = 21QRse %econ, Oata: = Yes%econ, olor: = Ce,%econ, Oraw '"pe: = ine%econ, %"m#ol: = 21S++*/
@aria#le: shi)t-$
>or shi)t=$ to Pars;1 Pegin%et7n,ex@alue-shi)t6 h[shi)t+%et7n,ex@alue2-shi)t6 l[shi)t+
En,
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age /0 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
32/75
>reDuently it happens it is necessary to use value of the indicator in the past. >or this purpose
function JetIndex=alue3shi)t4, !here shi)t C number of a cell of a file of the indicator is used.
>unction JetIndex=alue accordingly can look like JetIndex=alue* .
0.3. (arameters of $isplay of the in$icator
&arameters of the indicator for it prorisovyvani=a are in the top part of a code, cap of the
indicator.
eparate indo$K 7 o means, that the schedule of the indicator !ill be dra!n in the same
!indo!, as the schedule of the prices. Thus, deduce a trendC!atching indicators and indicators of
value !hich not strongly differ from values of the prices. Hther!ise eparate indo$K 7 Ges then the indicator is deduced in a separate !indo!, it is usual ostsill=atory. n this case value of
the indicator can strongly differ from values of the prices, i.e., for example, values are estimated
in percentage.
?ra$ TypeK 7 Line means, the indicator !ill be constructed as a line. &robably also constructionof the histogram or a conclusion of a symbol. n case the indicator !ill look as a symbol, in a
code of the indicator it is necessary to register a code of a symbol.
seecond?ataK 7 Ges means that the indicator !ill consist of t!o files, in our case of t!o lines.
!irst %olor, !irst ?ra$ Type and !irst ym+ol concern to the first file of the indicator. econd
%olor, econd ?ra$ Type and econd ym+ol C kovtoromu.
Minimum %hart Limits, Maximum %hart Limits is minimal and maximal value of borders.
These are unessential parameters !hich specify borders of the screen for display of the indicator.Are applied in case borders of display of the indicator are kno!n beforehand.
n the follo!ing lesson !e shall continue studying the user indicators on examples.
'ours faithfully, ;alhal=an Arthur.
arturJfxtest.ru
fxtest.ru The original of clause C >HKEL "AMANE $ 6 from 44.5/.455G
7Section Experts8.. 72 7408 9?: 92:
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age /4 of 23
http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F9.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F9.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D8%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F9.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F7.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F9.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F7.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F9.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D8%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F9.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F7.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
33/75
The Lesson # D
;ello, dear readers< Today !e shall !rite the expert and the user indicator. The expert !ill trade!ith use of the indicator.
9.1. 8l!orithm an$ a co$e of the in$icator
The indicator uses t!o data files, it !ill consist of t!o lines. #oth lines are sliding average. The
first average is under construction from the ceiling prices, the second C from minimal. >or this purpose !e use the standard expanded indicator sliding average. t has such appearanceF i9AEx-perio,6 maJmetho,6 maJshi)t6 applie,Jprice6 shi)t
n the indicator !e have one external variable, she defines the period of average.
/*[[Name: = uro0niAuthor: = )orextimesin!: = )xtest.ru%eparate Min,ow: = No>irst olor: = Plue>irst Oraw '"pe: = ine>irst %"m#ol: = 21QRse %econ, Oata: = Yes%econ, olor: = Ce,%econ, Oraw '"pe: = ine%econ, %"m#ol: = 21S
++*/
7nputs: per-21@aria#le: shi)t-$6 L9a-$6 l9a-$%etoopount-$// loop )rom )irst #ar to current #ar-with shi)t=$>or shi)t=Pars;1 Oownto $ Pegin
L9a=i9AEx-per6 9BOEJE9A6 $6 (C7EJL7L6 shi)t9a=i9AEx-per6 9BOEJE9A6 $6 (C7EJBM6 shi)t%et7n,ex@alue-shi)t6 L9a%et7n,ex@alue2-shi)t6 9a
En,
Algorithm very simple, therefore do not !rite the explanatory.
9.2. 8l!orithm an$ a co$e of the expert
The expert checks presence of a trend and traces position of the price concerning lines of theindicator. &resence of a trend is checked very primitivelyF last three values sliding by average, if
each follo!ing more previous a trend bull, differently bear !ill be checked up. f at the bull trend
the price less than bottom average the user indicator, is carried out purchase if at the bear trend
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age // of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
34/75
the price more than the top line of the indicator is carried out sale.
The output is carried out both on stop to !arrants, and on a condition. A condition of an output isachievement of an opposite line of the user indicator.
There are t!o external variablesF per C defines the period of the indicator, perMa C defines the period of average, determining a direction of a trend.
There is a restriction on time for opening of a position. t is made that some positions on one bardid not open. The condition looks likeF
i) curtime;ast'ra,e'ime KI*&$$ then exit
>igure before U/155, this value ta=mfrema in hours.
/*[[Name: = expertRro0niAuthor: = )orextimesin!: = )xtest.ruots: = 1.$$%top oss: = &$'a!e (ro)it: = $'railing %top: = $++*/
,e)ines:per-6 per9a-210ar:L9a$-$6 9a$-$6 9a1-$6 9a2-$6 9a&-$6 cnt-$i) curtime;ast'ra,e'ime KI*&$$ then exit
/*L9a$=iustom-3uro0ni36 per6 9BOEJ>7C%'6 $
9a$=iustom-3uro0ni36 per6 9BOEJ%EBNO6 $*/
L9a$=i9AEx-per6 9BOEJE9A6 $6 (C7EJL7L6 $9a$=i9AEx-per6 9BOEJE9A6 $6 (C7EJBM6 $
9a1=i9AEx-per9a6 9BOEJE9A6 $6 (C7EJclose6 19a2=i9AEx-per9a6 9BOEJE9A6 $6 (C7EJclose6 29a&=i9AEx-per9a6 9BOEJE9A6 $6 (C7EJclose6 &
i) 'otal'ra,es=$ then i) 9a1;9a2? $ an, 9a2;9a&? $ an, as! K9a$ then
%etBr,er-opJ#u"6 lots6 as!6 &6 #i,;stoploss*point6
#i,
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
35/75
exit 44
i) 'otal'ra,es? $ then )or cnt=1 to 'otal'ra,es
i) Br,er@alue-cnt6 @AJ'Y(E K=B(J%E an,
Br,er@alue-cnt6 @AJ%Y9PB =%"m#ol then
7) Br,er@alue-cnt6 @AJ'Y(E =B(JPRY then
i) #i,? L9a$ then
loseBr,er-Br,er@alue-cnt6 @AJ'75E'6Br,er@alue-cnt6 @AJB'%6 Pi,6 &6 @iolet
Exit 4 4
7) Br,er@alue-cnt6 @AJ'Y(E =B(J%E then
i) as! K9a$ then
loseBr,er-Br,er@alue-cnt6 @AJ'75E'6Br,er@alue-cnt6 @AJB'%6 as!6 &6 @iolet
Exit 4 4 4 44
As testing of experts !ith use of the user indicators is carried out very slo!ly, the variables usingthe user indicator, akommentirovany. omments can be removed for check of !ork of the
indicator.
'ours faithfully, ;alhal=an Arthur.
arturJfxtest.ru
fxtest.ru
The original of clause C >HKEL "AMANE $ ? from 4?.5/.455G 7Section Experts8.. 76 7408 905: 96:
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age /3 of 23
mailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D9%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F10.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F8.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F10.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F8.phpmailto:[email protected]://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Ffxtest.ru%2Fhttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.forextimes.ru%2Fmagazine%2Fget.php3%3Fid%3D9%26idpart%3D2http://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Findex.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F21.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F10.phphttp://www.online-translator.com/url/tran_url.asp?lang=en&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&url=http%3A%2F%2Fwww.alpari.org%2Fru%2Fexperts%2Farticles%2Fmql2%2F8.php
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
36/75
The Lesson # 1:
;ello, dear readers. Today !e shall !rite the expert on algorithm !hich !as sent by Sergey"at=uha. As !e shall disassemble the Duestions sent in the letter. think, they !ill be interesting
to all.
1:.1. 6uestions from the letter
The letter !as sent by Sergey "at=uha and his friends Evgenie, &aul, Andrey and Bmitry from"osco!. !ant to thank once again these people for interest to magaine and it is concrete to a
heading.
*uestionsF
0. %ithin the frame!ork of training a !riting of experts, indicators and the experts !orking
on the basis of indicators, !hether it is possible to create such indicator !hich !ould
sho! results of !ork of the expert.
>or example, it !ould be possible to sho! directly in a !indo! of the schedule of the
prices lines(pieces of lines) from the moment of opening till the moment of closing of the!arrant !ith mixture for example on sie bid or ask, having painted them for presentation
in different colors. t !ould be possible to add and pieces Stop+ossCia carrying to the
concrete !arrant(at once very !ell !as it is seen dra!n in Stop+oss).
4. And in a separate !indo!(not in a !indo! of the schedule of the prices) it !ould be possible to sho! a condition of the account or percent of the profit, for example, !ith thehelp of histograms. Then it !ould be easily possible to define(at small scale ta=mfre=ma)
in !hat periods of a trend the expert !orks most effectively.
%hether but do not kno! probably it basically...
The ans!erF
nfortunately, it to make it is impossible. The user indicators are under construction at once, i.e.
all elements of a file of the indicator are determined. And the tester !hich has been built C in in"T, models passage of the price on the historical data for an estimation of potential of "TS.
Therefore the indicator cannot be used as means of debugging though, certainly, it !ould be veryconvenient. t is necessary to be content curve profitableness. hope, in ne! version "T thereport on testing !ill increase, and ne! !ays of debugging !ill be entered.
1:.2. 8l!orithm of the expert
The algorithm of the expert also has been sent by Sergey "at=uho=. ;ere itF
(-var-!!!-apps-conversion-tmp-scratch/-/0123/101.doc, rev.4553.5353.02/6, printed / "ay 4501) &age /1 of 23
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
37/75
0. Each subseDuent !arrant has an opposite direction(if it !as closed buy !ill open sell and
on the contrary).
4. %arrants have no Take&rofitCia./. losing is carried out only !ith help Stop+oss of !arrants.
G. Stop+oss should be necessarily podhimaemym(tre=lingCstop).
;ere are necessary, think, only t!o variablesF it is sie Stop+oss and a certain variable !hich
!ould define a step through !hich it !ould be tightened Stop+oss( so !rite about certain because to me and to my friends too !orking on >HKEL, the example !ith TrailingStop and a
principle of his action in 1 lesson a little is not clear, and it can and does not approach for the
given purposes).
1:.3. he expert
/*[[Name: = expert1$Author: = )orextimes
in!: = )xtest.ruots: = 1.$$%toposs: = 2$'a!e(ro)it: = 1$$$'railing%top: = 2$++*/
0ar:cnt-$6 )1-$6 )-$i) 'otal'ra,es=$ then i) )1=$ then
)1=1 )=2
%etBr,er-opJ#u"6 lots6 as!6 &6 #i,;stoploss*point6#i,
-
8/17/2019 MQL II Training & Expert Advisors (Alpari)
38/75
#egin /* it is a long positionG */ 7) Br,-cnt6 @AJ'Y(E =B(JPRY then/* ,linna8apoitsi8a */ /* all o0er again we shall chec! up ; whether is pro)it at this
transaction more than a le0el tre8ling stopG Me chec! Pi,6as position PRY */
7)-Pi,;Br,-cnt6 @AJB(EN(C7E?-'railing%top*(oint then
/* "es6 the position has pro)it more than 0alue tre8ling stop-)or example &$