mql4 manual.pdf

Upload: flathon

Post on 02-Jun-2018

546 views

Category:

Documents


4 download

TRANSCRIPT

  • 8/11/2019 mql4 manual.pdf

    1/162

    MetaQuotes Language 4

    MQL4 quick referenceAccount InformationArray FunctionsCommon functionsConversion functions

    Custom Indicator functionsDate & Time functionsFile functionslo!al "aria!les functionsMat# & Trig$!%ect functionsre'defined "aria!les(tandard Constants(tring functionsTec#nical Indicator callsTrading functions)indo* functions

    MQL4 quick reference

    A!out MetaQuotes Language 4(ynta+Data ty,es$,erations & -+,ressions$,eratorsFunctions"aria!lesre,rocessor

    A!out MetaQuotes Language 4

    MetaQuotes Language 4 (MQL4) is a new built-in language for programming trading strategies. This language allowsto create your own Epert !d"isors that render the trade process management automatic and are perfectly suitablefor implementing your own trade strategies. !lso# with the help of MQL4 you can create your own $ustom %ndicators#&cripts and Libraries of functions.

    ! large number of functions necessary for the analysis of the current and past 'uotations# the basic arithmetic andlogic operations are included in MQL4 structure. There are also basic indicators built in and commands of orderplacement and control.

    The MetaEditor 4 tet editor that highlights different constructions of MQL4 language is used for writing the programcode. %t helps users to orient in the epert system tet 'uite easily. !s an information boo for MQL4 language weuse MetaQuotes Language ictionary. ! brief guide contains functions di"ided into categories# operations# reser"edwords# and other language constructions and allows finding the description of e"ery element we use.

    *rograms written in MetaQuotes Language 4 ha"e different features and purposes+

    Epert !d"isors is a mechanical trade system (MT&) lined up to a certain plot. The !d"isor can not onlyinform you about a possibility to strie bargains# but also can mae deals on the trade account automaticallyand direct them right to the trade ser"er. Lie most trade systems# the terminal supports testing strategieson historical data with displaying on the chart the spots where trades come in and out.

    $ustom %ndicators are an analogue of a technical indicator. %n other words# $ustom %ndicators allow to createtechnical indicators in addition to those already integrated into client terminal. Lie built-in indicators# theycannot mae deals automatically and are aimed only at implementing analytical functions.

    &cripts are programs intended for single eecution of some actions. ,nlie Epert !d"isors# &cripts are notrun tic wise and ha"e no access to indicator functions.

    Libraries are user functions libraries where fre'uently used blocs of user programs are stored.

    (ynta+

    Format

    http://help//mql4ref_quick_refhttp://help//grp_accounthttp://help//grp_arrayshttp://help//grp_commonhttp://help//grp_conv_funcshttp://help//grp_custom_indhttp://help//grp_datetimehttp://help//grp_fileshttp://help//grp_globalshttp://help//grp_mathhttp://help//grp_objectshttp://help//grp_varshttp://help//grp_std_consthttp://help//grp_stringshttp://help//grp_tech_indicatorshttp://help//grp_tradinghttp://help//grp_windowshttp://help//mqlref_about_mql4http://help//mqlref_syntaxhttp://help//mqlref_data_typeshttp://help//mqlref_ops_and_exprhttp://help//mqlref_opshttp://help//mqlref_functionshttp://help//mqlref_varshttp://help//mqlref_prephttp://help//mqlref_formathttp://help//mql4ref_quick_refhttp://help//grp_accounthttp://help//grp_arrayshttp://help//grp_commonhttp://help//grp_conv_funcshttp://help//grp_custom_indhttp://help//grp_datetimehttp://help//grp_fileshttp://help//grp_globalshttp://help//grp_mathhttp://help//grp_objectshttp://help//grp_varshttp://help//grp_std_consthttp://help//grp_stringshttp://help//grp_tech_indicatorshttp://help//grp_tradinghttp://help//grp_windowshttp://help//mqlref_about_mql4http://help//mqlref_syntaxhttp://help//mqlref_data_typeshttp://help//mqlref_ops_and_exprhttp://help//mqlref_opshttp://help//mqlref_functionshttp://help//mqlref_varshttp://help//mqlref_prephttp://help//mqlref_format
  • 8/11/2019 mql4 manual.pdf

    2/162

    CommentsIdentifiers.eserved *ords

    Format

    &paces# tabs# line feedform feed symbols are used as separators. ou can use any amount of such symbols instead

    of one. ou should use tab symbols to enhance the readability of the tet .

    Comments

    Multi line comments start with / symbols and end with / symbols. &uch comments cannot be nested. &inglecomments start with symbols# end with the symbol of a new line and can be nested into multi line comments.$omments are allowed where blan spaces are possible and tolerate any number of spaces.

    Eamples+

    // single comment

    /* multi-

    line // nested single comment

    comment

    */

    Identifiers

    %dentifiers are used as names of "ariables# functions# and data types. The length of an identifier cannot eceed 01characters.

    &ymbols you can use+ the numbers 2-3# Latin capital and small letters a-# !-5 (recognied as different symbols)# thesymbol of underlining (6). The first symbol cannot be a number. The identifier must not coincide with any reser"edword.

    Eamples+NAME1 namel Total_5 Paper

    .eserved *ords

    The identifiers listed below are fied reser"ed words. ! certain action is assigned to each of them# and they cannotbe used for other purposes+

    Data ty,es Memory classes $,erators $t#er

    bool etern brea false

    color static case truedatetime continue

    double default

    int else

    string for

    "oid if

    return

    switch

    while

    Data ty,es

    Data ty,es overvie*Integer constants

    http://help//mqlref_commentshttp://help//mqlref_identifiershttp://help//mqlref_reserved_wordshttp://help//mqlref_data_types_overviewhttp://help//mqlref_int_consthttp://help//mqlref_commentshttp://help//mqlref_identifiershttp://help//mqlref_reserved_wordshttp://help//mqlref_data_types_overviewhttp://help//mqlref_int_const
  • 8/11/2019 mql4 manual.pdf

    3/162

    Literal constants/oolean constantsFloating',oint num!er constants(tring constantsColor constantsDatetime constants

    Data ty,es overvie*

    The main data types are+

    %nteger (int) 7oolean (bool) Literals (char) &tring (string) 8loating-point number (double) $olor (color) atetime (datetime)

    9e need the $olor and atetime types only to facilitate "isualiation and entering those parameters that we set fromepert ad"isor property tab or custom indicator :%nput parameters: tab. The data of $olor and atetime types arerepresented as integer "alues.

    9e use implicit type transformation. The priority of types at a transformation in ascending order is the following+

    int (bool,color,datetime!

    double!

    string!

    7efore operations (ecept for the assignment ones) are performed# the data ha"e been transferred to the maimumprecision type. 7efore assignment operations are performed# the data ha"e been transferred to the integer type.

    Integer constants

    Decimal0numbers from 2 to 3; 5ero should not be the first number.Eamples+

    1", 111, -#5$ 1%%&

    1e+adecimal0numbers from 2 to 3# letters a-f or !-8 to represent the "alues 12-1

  • 8/11/2019 mql4 manual.pdf

    4/162

    Eamples+

    int a 9 A!

    int b 9 :!

    int c 9 ;! // code %'A#

    int d 9 .'AE! // s111!

    double b 9 -#5$>1%%&!

    double c 9 %>%%%1!

    double d 9 1$!

    8loating-point constants can assume "alues from >.>e-02@ to 1.@e02@. %f a constant eceeds this range# the resultwill not be defined.

    (tring constants

    &tring constant is a succession of !&$%%-code characters enclosed in double 'uotes+ :$haracter constant:.

    ! string constant is an array of characters enclosed in 'uotes. %t is of the string type. Each string constant# e"en if itis identical to another string constant# is sa"ed in a separate memory space. %f you need to insert a double 'uote (:)into the line# you must place a re"erse slash (C) before it. ou can insert any special character constants into the lineif they ha"e a re"erse slash (C) before them. The length of a string constant lies between 2 and >

  • 8/11/2019 mql4 manual.pdf

    5/162

    +%'%%,%'%%,%' // blue

    // named color

    2ed

    Bello?

    ClacD

    // integer-3alued representation

    %' // ?ite

    1$&&&"15 // ?ite

    %'%%%%% // green

    "&$ // green

    Datetime constants

    atetime constants can be represented as a character line consisting of A parts for "alue of year# month# date# hour#minutes# and seconds. The constant is enclosed in simple 'uotes and starts with a character.atetime constant can "ary from Ian 1# 13?2 to ec 01# >20?.Eamples+

    "%%@>%1>%1 %%F%% // Ne? Bear

    1#%>%&>1# 1"F%F"&1#>%&>1#% 1"F%F"&

    1#>%&>1#% 1" //e4ual to 1#%>%&>1# 1"F%%F%%

    %1>%1>"%%@ //e4ual to %1>%1>"%%@ %%F%%F%%

    1"F%F"& //e4ual to Gcompilation dateH 1"F%F"&

    //e4ual to Gcompilation dateH %%F%%F%%

    $,erations & -+,ressions

    -+,ressions

    Arit#metical o,erationsT#e o,eration of assignment$,erations of relation/oolean o,erations/it*ise o,erations$t#er o,erationsrecedence rules

    -+,ressions

    !n epression consists of one or more operands and operation characters. !n epression can be written in se"eral

    lines.Eample+

    aII! b 9 1%! ' 9 (

  • 8/11/2019 mql4 manual.pdf

    6/162

    The operations of addingsubtracting 1 cannot be implemented in epressions.Eample+

    int a9!

    aII! // 3alid e'pression

    int b9(aII*! // in3alid e'pression

    T#e o,eration of assignment

    Gote+ The "alue of the epression that includes this operation is the "alue of the left operand following the bindcharacter.

    Assigning te < 3alue to te ' 3ariable < 9 '!

    Adding ' to te < 3ariable < I9 '!

    7ubtracting ' )rom te < 3ariable < -9 '!

    Multipl

  • 8/11/2019 mql4 manual.pdf

    7/162

    is true. The "alue of this epression is true if the "alues of both and y are true.Eample+

    i)(pR9' pLThe binary-coded representation of is shifted to the right by y digits; the free digits on the right will be filled witheroes.Eample+

    ' 9 '

    7itwise operation !G of binary-coded and y representations. The "alue of the epression contains 1 (true) in alldigits where both and y are not e'ual to ero; the "alue of the epression contains 2 (false) in all other digits.Eample+

    b 9 ((' 7itwise operation E=$L,&%PE of binary-coded and y representations. The epression contains 1 in all digits

    where and y ha"e different binary "alues; the "alue of the epression contains 2 in all other digits.Eample+

    b 9 ' Q

    Gote+ 7itwise operations are eecuted with integers only.

    $t#er o,erations

    %ndeing. !t addressing to i element of array# the "alue of the epression e'uals the "alue of the "ariable numberedas i.Eample+

    arra

    The call of function with 1#>#...#n arguments. The epression accepts the "alue returned by the function. %f thereturned "alue is of the "oid type# you cannot place such function call on the right in the assignment operation. Mindthat the epressions 1#>#...#n are surely eecuted in this order.Eample+

    double 79AsD-"5*Point!

    double TP9AsDI"5*Point!

    int ticDet9Order7end(7

  • 8/11/2019 mql4 manual.pdf

    8/162

    recedence rules

    Each group of operations in the table has the same priority. The higher the priority is# the higher the position of thegroup in the table is.The eecution order determines the grouping of operations and operands.

    ( unction call rom le)t to rigt

    GH Arra< element selection

    R Negation rom le)t to rigt

    S Cit?ise negation

    - 7ign canging operation

    * Multiplication rom le)t to rigt

    / i3ision

    K Module di3ision

    I Addition rom le)t to rigt

    - 7ubtraction

    e)t si)t rom le)t to rigt

    LL 2igt si)t

    ess tan rom le)t to rigt

    9 ess tan or e4uals

    L Ureater tan

    L9 Ureater tan or e4uals

    99 E4uals rom le)t to rigt

    R9 Not e4ual

    Cit?ise AN operation rom le)t to rigt

    Q Cit?ise e'clusi3e O2 rom le)t to rigt

    Cit?ise O2 operation rom le)t to rigt

    ogical AN rom le)t to rigt

    ogical O2 rom le)t to rigt

    9 Assignment rom rigt to le)t

    I9 Assignment addition

    -9 Assignment subtraction

    *9 Assignment multiplication

    /9 Assignment di3ision

    K9 Assignment module

    LL9 Assignment rigt si)t

    9 Assignment le)t si)t

    9 Assignment bit?ise AN

    9 Assignment bit?ise O2

    Q9 Assignment e'clusi3e O2

    , +omma rom le)t to rigt

    ,se parentheses to change the eecution order of the operations.

    $,erators

    Format and nestingCom,ound o,erator-+,ression o,erator/reak o,eratorContinue o,erator.eturn o,erator

    Conditional o,erator ifConditional o,erator if'else(*itc# o,eratorCycle o,erator *#ileCycle o,erator for

    http://help//mqlref_format_nestinghttp://help//mqlref_comp_ophttp://help//mqlref_expr_ophttp://help//mqlref_break_ophttp://help//mqlref_continue_ophttp://help//mqlref_return_ophttp://help//mqlref_if_ophttp://help//mqlref_if_else_ophttp://help//mqlref_switch_ophttp://help//mqlref_while_ophttp://help//mqlref_for_ophttp://help//mqlref_format_nestinghttp://help//mqlref_comp_ophttp://help//mqlref_expr_ophttp://help//mqlref_break_ophttp://help//mqlref_continue_ophttp://help//mqlref_return_ophttp://help//mqlref_if_ophttp://help//mqlref_if_else_ophttp://help//mqlref_switch_ophttp://help//mqlref_while_ophttp://help//mqlref_for_op
  • 8/11/2019 mql4 manual.pdf

    9/162

  • 8/11/2019 mql4 manual.pdf

    10/162

    int sum9%!

    )or(int i9%!iarra

  • 8/11/2019 mql4 manual.pdf

    11/162

    V

    09$!

    W

    // Nested operators

    i)('99a

    V

  • 8/11/2019 mql4 manual.pdf

    12/162

    breaD!

    W

    Cycle o,erator *#ile

    wile (expression)

    operator;

    %f the epression is true# the operator is eecuted till the epression becomes false. %f the epression is false# thecontrol will be gi"en to the net operator.

    Gote+ !n epression "alue has been defined before the operator is eecuted. Therefore# if the epression is falsefrom the "ery beginning# the operator is not eecuted at all.Eample+

    ?ile(Dn

    V

    is omitted# it is considered constantly true. The 8 (;;) operator is a continuous cycle e'ui"alent to

    the 9S%LE(l) operator.Each of the epressions 1 to 0 can consist of se"eral epressions united by a comma operator B#B.Eample+

    //

    )or(i9%,J9n-l!in!iII,J--

    aGiH9aGJH!

    Functions

    Function definitionFunction call

    (,ecial functions init56 deinit5 and start5

    Function definition

    http://help//mqlref_func_defhttp://help//mqlref_func_callhttp://help//mqlref_special_funcshttp://help//mqlref_func_defhttp://help//mqlref_func_callhttp://help//mqlref_special_funcs
  • 8/11/2019 mql4 manual.pdf

    13/162

    ! function is defined by return "alue type declaration# by formal parameters and a compound operator (bloc) thatdescribes actions the function eecutes.Eample+

    double // t

  • 8/11/2019 mql4 manual.pdf

    14/162

    Defining glo!al varia!lesDefining e+tern varia!lesInitiali7ing varia!les-+ternal function definition

    Definitions

    efinitions are used to define "ariables and to declare types of "ariables and functions defined somewhere else. !definition is not an operator. Pariables must be declared before being used. nly constants can be used to initialie"ariables.

    T#e !asic ty,es are0

    string - a string of characters; int - an integer; double - a floating-point number (double precision); bool - a boolean number :true: or :false:.

    Eample+

    string MessageCo'!

    int Orders!

    double 7%1>%1 %%F%%!

    e'tern color cModi)

    double mG&HG5%H! //T?o-dimensional arra< o) se3en arra

    nly an integer can be an array inde. Go more than four-dimensional arrays can be declared.

    Defining local varia!les

    The "ariable declared inside any function is local. The scope of a local "ariable is limited to limits of the functioninside which it is declared. The local "ariable can be initialied by outcome of any epression. E"ery call of functioneecute the initialiation of local "ariables. Local "ariables are stored in memory area of corresponding function.

    Formal ,arametersEamples+

    3oid )unc(int ', double >>

    W

    8ormal parameters are local. &cope is the bloc of the function. 8ormal parameters must ha"e names differing fromthose of eternal "ariables and local "ariables defined within one function. %n the bloc of the function to the formalparameters some "alues can be assigned. 8ormal parameters can be initialied by constants. %n this case# theinitialiing "alue is considered as a default "alue. The parameters following the initialied parameter should be

    http://help//mqlref_def_globalhttp://help//mqlref_def_externhttp://help//mqlref_init_varhttp://help//mqlref_extrn_funchttp://help//mqlref_def_globalhttp://help//mqlref_def_externhttp://help//mqlref_init_varhttp://help//mqlref_extrn_func
  • 8/11/2019 mql4 manual.pdf

    15/162

    initialied# as well.

    7y calling this function the initialied parameters can be omitted# instead of them defaults will be substituted.

    Eample+

    )unc(1", %>5!

    *arameters are passed by "alue. These are modifications of a corresponding local "ariable inside the called functionwill not be reflected in any way in the calling function. %t is possible to pass arrays as parameters. Sowe"er# for anarray passed as parameter# it is impossible to change the array elements.

    There is a possibility to pass parameters by reference. %n this case# modification of such parameters will be reflectedon corresponded "ariables in the called function. To point# that the parameter is passed by reference# after a datatype# it is necessary to put the modifier O.

    Eample+

    3oid )unc(int ', double >>

    W

    !rrays also can be passed by reference# all modifications will be reflected in the initial array. The parameters thatpassed by reference# cannot be initialied by default "alues.

    (tatic varia!les

    The memory class :static: defines a static "ariable. The specifier :static: is declared before a data type.Eample+

    V

    static int )lag

    W

    &tatic "ariables are constant ones since their "alues are not lost when the function is eited. !ny "ariables in a bloc#ecept the formal parameters of the function# can be defined as static. The static "ariable can be initialied bycorresponded type constant# as against a simple local "ariable which can be initialied by any epression. %f there isno eplicit initialiation# the static "ariable is initialied with ero. &tatic "ariables are initialied only once before

    calling :init(): function. That is at eit from the function inside which the static "ariable is declared# the "alue of this"ariable being not lost.

    Defining glo!al varia!les

    They are defined on the same le"el as functions# i.e. they are not local in any bloc.Eample+

    int Ulobal_)lag!

    int start(

    V

    >>> W

    &cope of global "ariables is the whole program. Hlobal "ariables are accessible from all functions defined in theprogram. They are initialied with ero if no other initial "alue is eplicitly defined. The global "ariable can beinitialied only by corresponded type constant. %nitialiation of global "ariables is made only once before eecution of:init(): function.

    Gote+ it is not necessary to confuse the "ariables declared at a global le"el# to global "ariables of $lient Terminal#access to which is carried out by HlobalPariable...() function.

    Defining e+tern varia!les

    The memory class :etern: defines an etern "ariable. The specifier :etern: is declared before a data type.Eample+

    e'tern double 8nputParameter1 9 1>%!

    int init(

  • 8/11/2019 mql4 manual.pdf

    16/162

    V

    >>>

    W

    Etern "ariables define input data of the program# they are accessible from a property program sheet. %t is notmeaningful to define etern "ariables in scripts. !rrays cannot represent itself as etern "ariables.

    Initiali7ing varia!les

    !ny "ariable can be initialied during its definition. !ny permanently located "ariable is initialied with ero (2) if noother initial "alue is eplicitly defined. Hlobal and static "ariables can be initialied only by constant of correspondedtype. Local "ariables can be initialied by any epression# and not Fust a constant. %nitialiation of global and static"ariables is made only once. %nitialiation of local "ariables is made each time by call of corresponded functions.

    /asic ty,esEamples+

    int mt 9 1! // integer initiali0ation

    // initiali0ation )loating-point number (double precision

    double p 9 MarDet8n)o(7

  • 8/11/2019 mql4 manual.pdf

    17/162

    Xde)ine P8 %>1@

    Xde)ine +OMPANB_NAME 6MetaZuotes 7o)t?are +orp>6

    The compiler will replace each occurrence of an identifier in your source code with the corresponding "alue.

    Controlling com,ilation

    'propert identifier_alue

    The list of predefined constant identifiers. Eample+Xpropert< linD 6ttpF//???>meta4uotes>net6

    Xpropert< cop6

    Xpropert< stacDsi0e 1%"@

    Constant Ty,e Descri,tion

    lin string a lin to the company website

    copyright string the company name

    stacsie int stac sie

    indicator6chart6window "oid show the indicator in the chart window

    indicator6separate6window "oid show the indicator in a separate window

    indicator6buffers int the number of buffers for calculation# up to @

    indicator6minimum int the bottom border for the chart

    indicator6maimum int the top border for the chart

    indicator6colorG color the color for displaying line G# where G lies between 1 and @

    indicator6le"elG doublepredefined le"el G for separate window custom indicator# where G liesbetween 1 and @

    show6confirm "oid before script run message bo with confirmation appears

    show6inputs "oidbefore script run its property sheet appears; disables show6confirmproperty

    The compilerwill write the declared "alues to the settings of the eecutable module.

    Including files

    Gote+ The include command line can be placed anywhere in the program# but usually all inclusions are placed atthe beginning of the source code.'include *file_name+

    Eample+

    Xinclude ?in">L

    The preprocessor replaces this line with the content of the file win0>.h. !ngle bracets mean that the file win0>.h willbe taen from the default directory (usually# terminal6directoryCepertsCinclude). The current directory is notsearched.Tinclude :file6name:Eample+

    Xinclude 6m6

    The compiler replaces this line with the content of the file mylib.h. &ince this name is enclosed in 'uotes# the searchis performed in the current directory (where the main file of the source code is located). %f the file is not found in thecurrent directory# the error will be messaged.

    Im,orting functions and ot#er modules 'import file_name

    func1();

    func2();

  • 8/11/2019 mql4 manual.pdf

    18/162

    'import

    Eample+

    Ximport 6user">dll6

    int MessageCo'A(int Ynd,string lpTe't,string lp+aption,

    int uT

  • 8/11/2019 mql4 manual.pdf

    19/162

    Print(6account currenc< is 6, Account+urrenc

  • 8/11/2019 mql4 manual.pdf

    20/162

    ArrayInitiali7e5ArrayIs(eries5ArrayMa+imum5ArrayMinimum5Array.ange5Array.esi7e5Array(etAs(eries5Array(i7e5

    Array(ort5

    intArrayBsearc!(

    doublearray"#$ doublevalue$ intcount%&'LEA**A+$ intstart%,$intdirection%M-EA.CEN-)

    eturns the inde of the first occurrence of a "alue in the first dimension of array if possible# or the nearest one# if the occurrenceis not found.The function cannot be used with string arrays and serial numeric arrays.3ote07inary search processes only sorted arrays. To sort numeric arrays use!rray&ort()functions.

    arameters

    array89 - The numeric array to search for.

    value - The "alue to search for.

    count - $ount of elements to search for. 7y default# it searches in the whole array.

    start - &tarting inde to search for. 7y default# the search starts on the first element.

    direction - &earch direction. %t can be any of the following "alues+ME6!&$EG searching in forward direction#ME6E&$EG searching in the bacward direction.

    (am,le

    datetime da

  • 8/11/2019 mql4 manual.pdf

    21/162

    intArrayCopy*ates(double0 destarray"#$ stringsymbol%N1LL$ inttimerame%,)

    $opies rates to the two-dimensional array from chart ate%nfo array# where second dimension has A elements+2 - time#1 - open#> - low#0 - high#4 - close#

    < - "olume.3ote0,sually retrie"ed array used to pass large blocs of data to the LL functions.

    arameters

    dest:array89 - eference to the two-dimensional destination numeric array.

    sym!ol - symbol name# by default# current chart symbol name is used.

    timeframe - Time frame# by default# the current chart time frame is used. %t can be any of Time frame enumeration"alues.

    (am,le

    double arra

  • 8/11/2019 mql4 manual.pdf

    22/162

    boolArray3etAs.eries(ob/ectarray"#)

    eturns true if array is organied as a series array (array elements indeed from last to first) otherwise return false.

    arameters

    array89 - !rray to chec.

    (am,le

    i)(Arra1 double m

  • 8/11/2019 mql4 manual.pdf

    23/162

    array89 - The numeric array to search for.

    count - &cans for the count of elements in the array.

    start - &tart searching on the start inde.

    (am,le

    double num_arra

  • 8/11/2019 mql4 manual.pdf

    24/162

    arameters

    array89 - !rray of any type.

    (am,le

    int count9Arra

  • 8/11/2019 mql4 manual.pdf

    25/162

    voidAlert(777)

    isplays a dialog bo containing the user-defined data. *arameters can be of any type. !rrays cannot be passed to the !lertfunction. ata of double type printed with 4 decimal digits after point. To print with more precision use oubleTo&tr()function.ata of bool# datetime and color types will be printed as its numeric presentation. To print "alues of datetime type as stringcon"ert it by TimeTo&tr()function.

    (ee also0$omment()and *rint()functions.

    arameters

    222 - !ny "alues# separated by commas.

    (am,le

    i)(+loseG%HL7ignale3el

    Alert(6+lose price coming 6, +loseG%H,6RRR6!

    stringClient8erminalName()

    eturns $lient Terminal Game.

    (am,le

    Print(6Terminal name is 6,+lientTerminalName(!

    stringCompanyName()

    eturns $ompany name

    (am,le

    Print(6+ompan< name is 6,+ompan

  • 8/11/2019 mql4 manual.pdf

    26/162

    int3et8ic9Count()

    The HetTic$ount() function retrie"es the number of milliseconds that ha"e elapsed since the system was started. %t is limited tothe resolution of the system timer.

    (am,le

    int start9UetTicD+ount(!

    // do some ard calculation>>>

    Print(6+alculation time is 6, UetTicD+ount(-start, 6 milliseconds>6!

    void'ide8est4ndicators(bool!ide)

    The function sets a flag hiding indicators called by the Epert !d"isor. !fter the chart has been tested and opened the flaggedindicators will not be drawn on the testing chart. E"ery indicator called will first be flagged with the current hiding flag.

    arameters

    #ide - T,E - if indicators must be hidden# otherwise# 8!L&E.

    (am,le

    ideTest8ndicators(true!

    bool4sConnected()

    eturns true if client terminal has opened connection to the ser"er# otherwise returns false.

    (am,le

    i)(R8s+onnected(

    V

    Print(6+onnection is broDenR6!

    return(%!

    W

    // E'pert bod< tat need opened connection

    // >>>

    bool4s-emo()

    eturns true if epert runs on demo account# otherwise returns false.

    (am,le

    i)(8semo( Print(68 am ?orDing on demo account6!

    else Print(68 am ?orDing on real account6!

    bool4s-llsAllo6ed()

    eturns true if LL function call is allowed for the epert# otherwise returns false. (ee also %sLibraries!llowed()#%sTrade!llowed().

    (am,le

    Ximport 6user">dll6

    int MessageCo'A(int Ynd ,string s0Te't, string s0+aption,int nT>>

    >>>

    i)(8sllsAllo?ed(99)alse

    V

    Print(6 call is not allo?ed> E'perts cannot run>6!

    return(%!

    W // e'pert bod< tat calls e'ternal )unctions

    MessageCo'A(%,6an message6,6Message6,MC_O\!

    http://help//IsLibrariesAllowedhttp://help//IsTradeAllowedhttp://help//IsLibrariesAllowedhttp://help//IsTradeAllowed
  • 8/11/2019 mql4 manual.pdf

    27/162

    bool4sLibrariesAllo6ed()

    eturns true if epert can call library function# otherwise returns false. (ee also%slls!llowed()# %sTrade!llowed().

    (am,le

    Ximport 6somelibrare'@6

    int some)unc(!

    >>>

    >>>

    i)(8sibrariesAllo?ed(99)alse

    V

    Print(6ibrar< call is not allo?ed> E'perts cannot run>6!

    return(%!

    W

    // e'pert bod< tat calls e'ternal )unctions

    some)unc(!

    bool4s.topped()

    eturns true if epert in the stopping state# otherwise returns false. This function can be used in the cycles to determine epertunloading.

    (am,le

    ?ile(e'prR9)alse

    V

    i)(8s7topped(99true return(%!

    // long time procesing c>>

    W

    bool4s8esting()

    eturns true if epert runs in the testing mode# otherwise returns false.

    (am,le

    i)(8sTesting( Print(68 am testing no?6!

    bool4s8radeAllo6ed()

    eturns true if trade is allowed for the epert# otherwise returns false. (ee also%slls!llowed()# %sLibraries!llowed().

    (am,le

    i)(8sTradeAllo?ed( Print(6Trade allo?ed6!

    doubleMar9et4no(stringsymbol$ inttype)

    eturns "alue from Maret watch window.

    arameters

    sym!ol - %nstrument symbol.

    ty,e - eturning data type inde. %t can be any of Maret information identifiers"alue.

    (am,le

    double 3ar!

    3ar9MarDet8n)o(6E276,MOE_C8!

    intMessageBo2(stringte2t%N1LL$ stringcaption%N1LL$ intlags%EMP8+)

    The Message7o function creates# displays# and operates a message bo. The message bo contains an application-defined

    http://help//IsDllsAllowedhttp://help//IsTradeAllowedhttp://help//IsDllsAllowedhttp://help//IsLibrariesAllowedhttp://help//const_market_idshttp://help//IsDllsAllowedhttp://help//IsTradeAllowedhttp://help//IsDllsAllowedhttp://help//IsLibrariesAllowedhttp://help//const_market_ids
  • 8/11/2019 mql4 manual.pdf

    28/162

  • 8/11/2019 mql4 manual.pdf

    29/162

    (am,le

    int ticDet!

    ?ile(true

    V

    ticDet9Order7end(7%,AsD,,%,%,6e'pertcomment6,"55,%,+2_NONE!

    i)(ticDet9%

    V

    int error9UetastError(!

    i)(error991@ breaD! // not enoug mone"@&@1, 5!

    // 3alue is 1>"@&

    doubleNormali5e-ouble(doublevalue$ intdigits)

    ounds floating point number to specified decimal places.

    arameters

    value - 8loating point "alue.

    digits - *recision format# number of digits after decimal point (2-@).

    (am,le

    double 3ar19%>1"@5$!

    Print(Normali0eouble(3ar1,5!

    // outputF %>1"@$

    double.tr8o-ouble(stringvalue)

    $on"erts string representation of number to type double.

    arameters

    value - &tring containing "alue in fied number format.

    (am,le

    double 3ar97trToouble(61%>"1"6!

    int.tr8o4nteger(stringvalue)

    $on"erts string representation of number to type integer.

    arameters

    value - &tring containing integer number.

    (am,le

    int 3ar197trTo8nteger(61%"@6!

    datetime.tr8o8ime(stringvalue)

    $on"erts string in the format :yyyy.mm.dd hh+mi: to type datetime.

    arameters

    value - &tring "alue of datetime format such as :yyyy.mm.dd hh+mi:.

    (am,le

    datetime 3ar1!

    3ar197trToTime(6"%%>>1" 1&F56!

    3ar197trToTime(61&F56! // returns ?it current date

    3ar197trToTime(6"%%>>1"6! // returns ?it midnigt time 6%%F%%6

    string8ime8o.tr(datetimevalue$ intmode%84ME-A8E:84MEM4N18E.)

    eturns time as string in the format :yyyy.mm.dd hh+mi:.

    arameters

  • 8/11/2019 mql4 manual.pdf

    32/162

    value - *ositi"e number of seconds from 22+22 Ianuary 1# 13?2.

    mode - ptional data output mode can be one or combination of+T%ME6!TE get result in form :yyyy.mm.dd:#T%ME6M%G,TE& get result in form :hh+mi:#T%ME6&E$G& get result in form :hh+mi+ss:.

    (am,le

    strign 3ar19TimeTo7tr(+urTime(,T8ME_ATET8ME_7E+ON7!

    Custom Indicator functions

    Indicator/uffers5IndicatorCounted5IndicatorDigits5Indicator(#ort3ame5(etInde+Arro*5(etInde+/uffer5(etInde+Dra*/egin5(etInde+-m,ty"alue5(etInde+La!el5

    (etInde+(#ift5(etInde+(tyle5(etLevel(tyle5(etLevel"alue5

    void4ndicatorBuers(intcount)

    !llocates memory for buffers used for custom indicator calculations. $annot be greater than @ and less than indicator6buffersproperty. %f custom indicator re'uires additional buffers for counting then use this function for pointing common buffers count.

    arameters

    count - 7uffers count to allocate. &hould be up to @ buffers.

    (am,leXpropert< indicator_separate_?indo?

    Xpropert< indicator_bu))ers 1

    Xpropert< indicator_color1 7il3er

    //---- indicator parameters

    e'tern int astEMA91"!

    e'tern int 7lo?EMA9"$!

    e'tern int 7ignal7MA9#!

    //---- indicator bu))ers

    double ind_bu))er1GH!

    double ind_bu))er"GH!

    double ind_bu))erGH!//I------------------------------------------------------------------I

    // +ustom indicator initiali0ation )unction

    //I------------------------------------------------------------------I

    int init(

    V

    //---- " additional bu))ers are used )or counting>

    8ndicatorCu))ers(!

    //---- dra?ing settings

    7et8nde'7t

  • 8/11/2019 mql4 manual.pdf

    33/162

    //---- name )or ataYindo? and indicator sub?indo? label

    8ndicator7ortName(6OsMA(6IastEMAI6,6I7lo?EMAI6,6I7ignal7MAI66!

    //---- initiali0ation done

    return(%!

    W

    int4ndicatorCounted()eturns bars count that does not changed after last indicator launch. %n most cases same count of inde "alues do not need forrecalculation. ,sed for optimiing calculations.

    (am,le

    int start(

    V

    int limit!

    int counted_bars98ndicator+ounted(!

    //---- cecD )or possible errors

    i)(counted_bars% return(-1!

    //---- last counted bar ?ill be recounted

    i)(counted_barsL% counted_bars--! limit9Cars-counted_bars!

    //---- main loop

    )or(int i9%! ilimit! iII

    V

    //---- ma_si)t set to % because 7et8nde'7i)t called abo?e

    E'tClueCu))erGiH9iMA(N,%,]a?sPeriod,%,MOE_7MMA,P28+E_ME8AN,i!

    E't2edCu))erGiH9iMA(N,%,TeetPeriod,%,MOE_7MMA,P28+E_ME8AN,i!

    E'timeCu))erGiH9iMA(N,%,ipsPeriod,%,MOE_7MMA,P28+E_ME8AN,i!

    W

    //---- done

    return(%! W

    void4ndicator-igits(intdigits)

    &ets default precision format for indicators "isualiation.

    arameters

    digits - *recision format# number of digits after decimal point.

    (am,le

    Xpropert< indicator_separate_?indo?

    Xpropert< indicator_bu))ers 1

    Xpropert< indicator_color1 7il3er

    //---- indicator parameters

    e'tern int astEMA91"!

    e'tern int 7lo?EMA9"$!

    e'tern int 7ignal7MA9#!

    //---- indicator bu))ers

    double ind_bu))er1GH!

    double ind_bu))er"GH!

    double ind_bu))erGH!

    //I------------------------------------------------------------------I

    // +ustom indicator initiali0ation )unction

    //I------------------------------------------------------------------I

    int init(

    V

    //---- " additional bu))ers are used )or counting>

  • 8/11/2019 mql4 manual.pdf

    34/162

    8ndicatorCu))ers(!

    //---- dra?ing settings

    7et8nde'7t

    8ndicatorCu))ers(!

    //---- dra?ing settings

    7et8nde'7t

  • 8/11/2019 mql4 manual.pdf

    35/162

  • 8/11/2019 mql4 manual.pdf

    36/162

    7et8nde'Cu))er(1,ind_bu))er"!

    7et8nde'Cu))er(",ind_bu))er!

    //---- name )or ataYindo? and indicator sub?indo? label

    8ndicator7ortName(6OsMA(6IastEMAI6,6I7lo?EMAI6,6I7ignal7MAI66!

    //---- initiali0ation done

    return(%!

    W

    void.et4nde2Empty;alue(intinde2$ doublevalue)

    &ets drawing line empty "alue. 7y default# empty "alue line is EM*T6P!L,E. Empty "alues are not drawn and not show in theata9indow.

    arameters

    inde+ - Line inde. &hould be from 2 to ?.

    value - Gew empty "alue.

    (am,le

    7et8nde'Empt%%%1!

    void.et4nde2Label(intinde2$ stringte2t)

    &ets drawing line description for showing in the ata9indow.

    arameters

    inde+ - Line inde. &hould be from 2 to ?.

    te+t - Label tet. G,LL means that inde "alue does not show in the ata9indow.

    (am,le

    //I------------------------------------------------------------------I

    // 8cimoDu \inDo

  • 8/11/2019 mql4 manual.pdf

    37/162

    7et8nde'Cu))er(,7panC_Cu))er!

    7et8nde'ra?Cegin(,\iJunI7enDou-1!

    7et8nde'7i)t(,\iJun!

    //---- o?n \umo bounding line does not so? in te ataYindo?

    7et8nde'abel(,N!

    //----

    7et8nde'7t

  • 8/11/2019 mql4 manual.pdf

    38/162

    void.et4nde2.tyle(

    intinde2$ inttype$ intstyle%EMP8+$ int6idt!%EMP8+$colorclr%CL*NNE)

    &ets new type# style# width and color for a gi"en indicator line.

    arameters

    inde+ - Line inde. &hould be from 2 to ?.

    ty,e - &hape style.$an be one of rawing shape styleenumeration.

    style - rawing style. Ecept &TLE6&L% style all other styles "alid when width is 1 piel.$an be one of &hape styleenumeration.

    EM*T "alue indicates that style does not changed.*idt# - Line width. "alid "alues - 1#>#0#4##0#4#1@!

    Date & Time functions

    CurTime5Day5

    Day$f)eek5Day$f

  • 8/11/2019 mql4 manual.pdf

    39/162

    datetimeCur8ime()

    eturns the last nown ser"er time# number of seconds elapsed from 22+22 Ianuary 1# 13?2.

    (am,le

    i)(+urTime(-OrderOpenTime($% return(%!

    int-ay()eturns the current day of the month.

    (am,le

    i)(a#0#4##..#0#4#).

    (am,le

  • 8/11/2019 mql4 manual.pdf

    40/162

  • 8/11/2019 mql4 manual.pdf

    41/162

  • 8/11/2019 mql4 manual.pdf

    42/162

    File)rite(tring5

    voidFileClose(int!andle)

    $loses file pre"iously opened by 8ilepen() functions.

    arameters

    #andle - 8ile handle# returned by 8ilepen() functions

    (am,le int andle9ileOpen(6)ilename6, 8E_+7[8E_2EA!

    i)(andleL%

    V

    // ?orDing ?it )ile >>>

    ile+lose(andle!

    W

    voidFileClose(int!andle)

    $loses file pre"iously opened by 8ilepen() functions.

    arameters

    #andle - 8ile handle# returned by 8ilepen() functions

    (am,le

    int andle9ileOpen(6)ilename6, 8E_+7[8E_2EA!

    i)(andleL%

    V

    // ?orDing ?it )ile >>>

    ile+lose(andle!

    W

    voidFileFlus!(int!andle)

    8lushes all data stored in the file buffer to dis.

    arameters

    #andle - 8ile handle# returned by 8ilepen() functions.

    (am,le

    int bars_count9Cars!

    int andle9ileOpen(6mcs36,8E_+7[8E_Y28TE!

    i)(andleL%

    V

    ileYrite(andle, 6X6,6OPEN6,6+O7E6,68U6,6OY6! )or(int i9%!ibars_count!iII

    ileYrite(andle, iI1,OpenGiH,+loseGiH,igGiH, o?GiH!

    ilelus(andle!

    >>>

    )or(int i9%!ibars_count!iII

    ileYrite(andle, iI1,OpenGiH,+loseGiH,igGiH, o?GiH!

    ile+lose(andle!

    W

    boolFile4sEnding(int!andle)

    eturns logical true if file pointer is at the end of the file# otherwise returns false. To get the detailed error information# callHetLastError()function.

    arameters

    http://help//FileWriteStringhttp://help//GetLastErrorhttp://help//FileWriteStringhttp://help//GetLastError
  • 8/11/2019 mql4 manual.pdf

    43/162

    #andle - 8ile handle# returned by 8ilepen() functions.

    (am,le

    i)(ile8sEnding(1

    V

    ile+lose(1!

    return()alse!

    W

    boolFile4sLineEnding(int!andle)

    8or $&P file returns logical true if file pointer is at the end of the line# otherwise returns false. To get the detailed errorinformation# call HetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    (am,le

    i)(ile8sineEnding(1

    V

    ile+lose(1!

    return()alse! W

    intFilepen(stringilename$ intmode$ intdelimiter%7T6!

    return()alse!

    W

    http://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastError
  • 8/11/2019 mql4 manual.pdf

    44/162

    // ?orD ?it )ile

    // >>>

    ile+lose(andle!

    intFile*eadArray(int!andle$ ob/ect0 array"#$ intstart$ intcount)

    eads the indicated count of elements from the binary file to array. eturns actual read elements count.To get the detailed error information# call HetLastError() function. 3ote07efore reading the data# array must be resied to asufficient sie.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    array89 - !rray where data will be stored.

    start - &toring start position into array.

    count - $ount of elements to read.

    (am,le

    int andle!

    double 3arradat6, 8E_C8N8E_2EA!

    i)(andleL%

    V

    ile2eadArra bytes) or LGH6P!L,E(4 bytes).

    (am,le

    int andle!

    int 3alue!

    http://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastError
  • 8/11/2019 mql4 manual.pdf

    45/162

    andle9ileOpen(6mdat6, 8E_C8N8E_2EA!

    i)(andleL%

    V

    3alue9ile2ead8nteger(1,"!

    ile+lose(andle!

    W

    doubleFile*eadNumber(int!andle)

    ead the number from the current file position to the delimiter. nly for $&P files. To get the detailed error information# callHetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    (am,le

    int andle!

    int 3alue!

    andle9ileOpen(6)ilename>cs36, 8E_+7[, !!

    i)(andleL%

    V 3alue9ile2eadNumber(andle!

    ile+lose(andle!

    W

    stringFile*ead.tring(int!andle$ intlengt!%,)

    ead the string from the current file position. !pplied to both $&P and binary files. 8or tet files string will be read to the delimiterand for binary file string will be read for the count of characters indicated. To get the detailed error information# callHetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    lengt# - eading characters count.

    (am,le

    int andle!

    string str!

    andle9ileOpen(6)ilename>cs36, 8E_+7[8E_2EA!

    i)(andleL%

    V

    str9ile2ead7tring(andle!

    ile+lose(andle!

    W

    boolFile.ee9(int!andle$ intoset$ intorigin)

    Mo"es the file pointer to a specified location. The 8ile&ee() function mo"es the file pointer associated with handle to a newlocation that is offset bytes from origin. The net operation on the file occurs at the new location. %f successful# function returnsT,E. therwise# it returns 8!L&E. To get the detailed error information# call HetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() functions.

    offset - ffset in bytes from origin.

    origin - %nitial position. Palue can be one of this constants+&EEY6$, - from current position#

    &EEY6&ET - from begin#&EEY6EG - from end of file.

    (am,le

    int andle9ileOpen(6)ilename>cs36, 8E_+7[8E_2EA, !!

    i)(andleL%

    http://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastError
  • 8/11/2019 mql4 manual.pdf

    46/162

    V

    ile7eeD(andle, 1%, 7EE\_7ET!

    ile2ead8nteger(andle!

    ile+lose(andle!

    andle9%!

    W

    intFile.i5e(int!andle)

    eturns file sie in bytes. To get the detailed error information# call HetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    (am,le

    int andle!

    int si0e!

    andle9ileOpen(6mdat6, 8E_C8N8E_2EA!

    i)(andleL%

    V

    si0e9ile7i0e(andle! Print(6mdat si0e is 6, si0e, 6 b

  • 8/11/2019 mql4 manual.pdf

    47/162

    ileYrite(andle, +loseG%H, OpenG%H, igG%H, o?G%H, TimeTo7tr(orderOpen!

    ile+lose(andle!

    W

    intFile&riteArray(int!andle$ ob/ectarray"#$ intstart$ intcount)

    9rites array to the binary file. !rrays of type int# bool# datetime and color will be written as 4 bytes integers. !rrays of typedouble will be written as @ bytes floating point numbers. !rrays of string will be written as one string where elements will bedi"ided by $arriage return and Line feed symbols (2 2!).eturns the number of elements wrote# or a negati"e "alue if an error occurs. To get the detailed error information# callHetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    array89 - !rray to write.

    start - &tarting inde into array to write.

    count - $ount of elements to write.

    (am,le

    int andle!

    double CarOpen[aluesG1%H!

    // cop< )irst ten bars to te arra< )or(int i9%!i1%! iII

    CarOpen[aluesGiH9OpenGiH!

    // ?riting arra< to te )ile

    andle9ileOpen(6mdat6, 8E_C8N8E_Y28TE!

    i)(andleL%

    V

    ileYriteArra

  • 8/11/2019 mql4 manual.pdf

    48/162

    "alue will be written as 1 bytes integer and if sie is LGH6P!L,E# "alue will be written as 4 bytes integer. eturns actual writtenbytes count.To get the detailed error information# call HetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    value - Palue to write.

    si7e - ptional format flag. %t can be any of the following "alues+$S!6P!L,E (1 byte)#&ST6P!L,E (> bytes)#LGH6P!L,E (4 bytes# default).

    (am,le

    int andle!

    int 3alue91%!

    andle9ileOpen(6)ilename>dat6, 8E_C8N8E_Y28TE!

    i)(andle1

    V

    Print(6cant open )ile error-6,UetastError(!

    return(%!

    W

    ileYrite8nteger(andle, 3alue, 7O2T_[AE!

    //>>>

    ile+lose(andle!

    intFile&rite.tring(int!andle$ stringvalue$ intlengt!)

    9rites string to the binary file from current file position. eturns actual written bytes count.To get the detailed error information# call HetLastError()function.

    arameters

    #andle - 8ile handle# returned by 8ilepen() function.

    value - Tet to write.

    lengt# - $ounts of characters to write.(am,le

    int andle!

    string str96some string6!

    andle9ileOpen(6)ilename>bin6, 8E_C8N8E_Y28TE!

    i)(andle1

    V

    Print(6cant open )ile error-6,UetastError(!

    return(%!

    W

    ileYrite7tring(1, str, !

    ile+lose(andle!

    lo!al "aria!les functions

    lo!al"aria!leC#eck5lo!al"aria!leDel5lo!al"aria!leet5lo!al"aria!le(et5lo!al"aria!le(et$nCondition5lo!al"aria!lesDeleteAll5

    bool3lobal;ariableC!ec9(stringname)

    eturn logical true if global "ariable eists# otherwise returns false. To get the detailed error information# call HetLastError()function.

    http://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GlobalVariableCheckhttp://help//GlobalVariableDelhttp://help//GlobalVariableGethttp://help//GlobalVariableSethttp://help//GlobalVariableSetOnConditionhttp://help//GlobalVariablesDeleteAllhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GlobalVariableCheckhttp://help//GlobalVariableDelhttp://help//GlobalVariableGethttp://help//GlobalVariableSethttp://help//GlobalVariableSetOnConditionhttp://help//GlobalVariablesDeleteAllhttp://help//GetLastError
  • 8/11/2019 mql4 manual.pdf

    49/162

    arameters

    name - Hlobal "ariable name.

    (am,le

    // cecD 3ariable be)ore use

    i)(RUlobal[ariable+ecD(6g16

    Ulobal[ariable7et(6g16,1!

    bool3lobal;ariable-el(stringname)

    eletes global "ariable. %f the function succeeds# the return "alue will be true. %f the function fails# the return "alue is false. To getthe detailed error information# call HetLastError().

    arameters

    name - Hlobal "ariable name.

    (am,le

    // deleting global 3ariable ?it name 6g3ar_16

    Ulobal[ariableel(6g3ar_16!

    double3lobal;ariable3et(stringname)

    eturns global "ariable "alue. To chec function failure# chec error information by calling HetLastError().

    arameters

    name - Hlobal "ariable name.

    (am,le

    double 319Ulobal[ariableUet(6g16!

    //---- cecD )unction call result

    i)(UetastError(R9% return()alse!

    //---- continue processing

    datetime3lobal;ariable.et(stringname$ doublevalue)

    &ets global "ariable "alue. %f it does not eist# the system creates a new "ariable. %f the function succeeds# the return "alue is lastaccess time. %f the function fails# the return "alue is 2. To get the detailed error information# call HetLastError().

    arameters

    name - Hlobal "ariable name.

    value - Gumeric "alue to set.

    (am,le

    //---- tr< to set ne? 3alue

    i)(Ulobal[ariable7et(6CarsTotal6,Cars99%

    return()alse! //---- continue processing

    bool3lobal;ariable.etnCondition(stringname$ doublevalue$ doublec!ec9value)

    &ets the new "alue of the global "ariable if the current "alue e'uals to the third parameter chec6"alue. %f there is no "ariable atall# the function will return false and set the "alue of E6HL7!L6P!%!7LE6GT68,G constant to LastError. 9hensuccessfully eecuted# the function returns true# otherwise it does false. To recei"e the information about the error# callHetLastError() function.The function can be used as a semaphore for the access to common resources.

    arameters

    name - Hlobal "ariable name.

    value - Gumeric "alue to set.

    c#eck:value - Palue to compare with the current global "ariable "alue.

    (am,le

    int init(

    V

    //---- create global 3ariable

    http://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastErrorhttp://help//GetLastError
  • 8/11/2019 mql4 manual.pdf

    50/162

    Ulobal[ariable7et(6ATA8E_7EM6,%!

    //>>>

    W

    int start(

    V

    //---- tr< to locD common resource

    ?ile(R8s7topped(

    V

    //---- locDing

    i)(Ulobal[ariable7etOn+ondition(6ATA8E_7EM6,1,%99true breaD!

    //---- ma< be 3ariable deleted^

    i)(UetastError(99E22_UOCA_[A28ACE_NOT_ON return(%!

    //---- sleeping

    7leep(5%%!

    W

    //---- resource locDed

    // >>> do some ?orD

    //---- unlocD resource

    Ulobal[ariable7et(6ATA8E_7EM6,%! W

    void3lobal;ariables-eleteAll()

    eletes all global "ariables. This function ne"er fails.

    (am,le

    Ulobal[ariableseleteAll(!

    Mat# & Trig

    Mat#A!s5Mat#Arccos5Mat#Arcsin5Mat#Arctan5Mat#Ceil5Mat#Cos5Mat#-+,5Mat#Floor5Mat#Log5Mat#Ma+5

    Mat#Min5Mat#Mod5Mat#o*5Mat#.and5Mat#.ound5Mat#(in5Mat#(qrt5Mat#(rand5Mat#Tan5

    doubleMat!Abs(doublevalue)

    eturns the absolute "alue (modulus) of the specified numeric "alue.

    arameters

    value - Gumeric "alue.

    (am,le

    http://help//MathAbshttp://help//MathArccoshttp://help//MathArcsinhttp://help//MathArctanhttp://help//MathCeilhttp://help//MathCoshttp://help//MathExphttp://help//MathFloorhttp://help//MathLoghttp://help//MathMaxhttp://help//MathMinhttp://help//MathModhttp://help//MathPowhttp://help//MathRandhttp://help//MathRoundhttp://help//MathSinhttp://help//MathSqrthttp://help//MathSrandhttp://help//MathTanhttp://help//MathAbshttp://help//MathArccoshttp://help//MathArcsinhttp://help//MathArctanhttp://help//MathCeilhttp://help//MathCoshttp://help//MathExphttp://help//MathFloorhttp://help//MathLoghttp://help//MathMaxhttp://help//MathMinhttp://help//MathModhttp://help//MathPowhttp://help//MathRandhttp://help//MathRoundhttp://help//MathSinhttp://help//MathSqrthttp://help//MathSrandhttp://help//MathTan
  • 8/11/2019 mql4 manual.pdf

    51/162

    double d'9->1@15#, d

    // calc MatAbs

    d1@15#

    doubleMat!Arccos(double2)The Math!rccos function returns the arccosine of in the range 2 to Z radians. %f is less than -1 or greater than 1# Math!rccosreturns an indefinite (same as a 'uiet GaG).

    arameters

    + - Palue between -1 and 1 arc cosine of which should be calculated.

    (am,le

    double '9%>"$#$,

    "&&11

    doubleMat!Arcsin(double2)

    The Math!rcsin function returns the arcsine of in the range -Z> to Z> radians. %f is less than -1 or greater than 1# arcsinereturns an indefinite (same as a 'uiet GaG).

    arameters

    + - Palue the arcsine of which should be calculated

    (am,le

    double '9%>"$#$,

    "&&11

    doubleMat!Arctan(double2)

    The Math!rctan returns the arctangent of . %f is 2# Math!rctan returns 2. Math!rctan returns a "alue in the range -Z> to Z>radians.

    arameters

    + - ! number representing a tangent.(am,le

    double '9-$">@",

    5$#$

    doubleMat!Ceil(double2)

    The Math$eil function returns a numeric "alue representing the smallest integer that is greater than or e'ual to .

    arameters+ - Gumeric "alue.

    (am,le

    double

  • 8/11/2019 mql4 manual.pdf

    52/162

    is 6, is 6, is -"*/

    doubleMat!Cos(doublevalue)

    eturns the cosine of the specified angle.

    arameters

    value - !n angle# measured in radians.

    (am,le

    double pi9>1@15#"$55!

    double ',

    '9pi/"!

    5&%9%

    doubleMat!E2p(doubled)

    eturns "alue the number eraised to the power d. n o"erflow# the function returns %G8 (infinite) and on underflow# MathEpreturns 2.

    arameters

    d - ! number specifying a power.

    (am,le

    double '9">%"55%#,

    !

    Print(6Te )loor o) "> is 6, is 6,

  • 8/11/2019 mql4 manual.pdf

    53/162

    'uiet GaG). %f is 2# they return %G8 (infinite).

    arameters

    + - Palue whose logarithm is to be found.

    (am,le

    double '9#%%%>%,

    $ doublevalue?)

    eturns maimum "alue of two numeric "alues.

    arameters

    value= - 8irst numeric "alue.

    value> - &econd numeric "alue.

    (am,le

    double result9MatMa'(1>%,Cid!

    doubleMat!Min(doublevalue>$ doublevalue?)

    eturns minimum "alue of two numeric "alues.

    arameters

    value= - 8irst numeric "alue.

    value> - &econd numeric "alue.

    (am,le

    double result9MatMin(1>%,AsD!

    doubleMat!Mod(doublevalue$ doublevalue?)

    i"ides two numbers and returns only the remainder.

    arameters

    value - i"idend "alue.

    value> - i"ider "alue.

    (am,le

    double '9-1%>%,%,0!

    09MatMod(',

  • 8/11/2019 mql4 manual.pdf

    54/162

    intMat!*and()

    The Mathand function returns a pseudorandom integer in the range 2 to 2?fff (0>?A?). ,se the Math&randfunction to seed thepseudorandom-number generator before calling rand.

    (am,le

    Mat7rand(ocalTime(!

    // ispla< 1% numbers>

    )or(int i9%!i1%!iII

    Print(6random 3alue 6, Mat2and(!

    doubleMat!*ound(doublevalue)

    eturns "alue rounded to the nearest integer of the specified numeric "alue.

    arameters

    value - Gumeric "alue to round.

    (am,le

    double is 6,@ is 6,@ is -"

    doubleMat!.in(doublevalue)

    eturns the sine of the specified angle.

    arameters

    value - !n angle# measured in radians.

    (am,le

    double pi9>1@15#"$55!

    double ',

    '9pi/"! 5&%9%

    doubleMat!.qrt(double2)

    The Math&'rt function returns the s'uare-root of . %f is negati"e# Math&'rt returns an indefinite (same as a 'uiet GaG).

    arameters

    + - *ositi"e numeric "alue.

    (am,le

    double 4uestion9@5>5, ans?er!

    ans?er9Mat74rt(4uestion!

    i)(4uestion%

    Print(6ErrorF Mat74rt returns 6,ans?er,6 ans?er6!

    else

    Print(6Te s4uare root o) 6,4uestion,6 is 6, ans?er!

    //OutputF Te s4uare root o) @5>5 is $>&

    voidMat!.rand(intseed)

    The Math&rand() function sets the starting point for generating a series of pseudorandom integers. To reinitialie the generator#use 1 as the seed argument. !ny other "alue for seed sets the generator to a random starting point. Mathandretrie"es the

    http://help//MathSrandhttp://help//MathRandhttp://help//MathSrandhttp://help//MathRand
  • 8/11/2019 mql4 manual.pdf

    55/162

    pseudorandom numbers that are generated. $alling Mathand before any call to Math&rand generates the same se'uence ascalling Math&rand with seed passed as 1.

    arameters

    seed - &eed for random-number generation.

    (am,le

    Mat7rand(ocalTime(!

    // ispla< 1% numbers>

    )or(int i9%!i1%!iII

    Print(6random 3alue 6, Mat2and(!

    doubleMat!8an(double2)

    MathTan returns the tangent of . %f is greater than or e'ual to >A0# or less than or e'ual to ->A0# a loss of significance in theresult occurs# in which case the function returns an indefinite (same as a 'uiet GaG).

    arameters

    + - !ngle in radians.

    (am,le

    double pi9>1@15#"$55!

    double ',

    //OutputF MatTan(%>&5$91

    $!%ect functions

    $!%ectCreate5$!%ectDelete5$!%ectDescri,tion5

    $!%ectFind5$!%ectet5$!%ectetFi!oDescri,tion5$!%ectet(#ift/y"alue5$!%ectet"alue/y(#ift5$!%ectet"isi!ility5$!%ectMove5$!%ect3ame5$!%ectsDeleteAll5$!%ect(et5$!%ect(etFi!oDescri,tion5$!%ect(etTe+t5$!%ect(et"isi!ility5$!%ects.edra*$!%ectsTotal5$!%ectTy,e5

    boolb/ectCreate(

    stringname$ inttype$ int6indo6$ datetimetime>$ doubleprice>$datetimetime?%,$ doubleprice?%,$ datetimetime@%,$ doubleprice@%,)

    $reate obFect with specified name# type and initial coordinates in the specified window. $ount of coordinates related from obFecttype (1-0). %f the function succeeds# the return "alue will be true. %f the function succeeds# the return "alue is true. %f the functionfails# the return "alue is false. To get the detailed error information# call HetLastError(). 8or obFects with type 7I6L!7EL firstcoordinate ignored. To set coordinate for label use bFect&et()function to set 7I**6=%&T!G$Eand 7I**6%&T!G$Eproperties.3ote0$oordinates must be passed with both part - time and price. 8or eample+ bFect 7I6PL%GE re'uired 1 coordinate parttime. 7ut function wants also the seconds part of coordinate price.

    arameters

    http://help//ObjectCreatehttp://help//ObjectDeletehttp://help//ObjectDescriptionhttp://help//ObjectFindhttp://help//ObjectGethttp://help//ObjectGetFiboDescriptionhttp://help//ObjectGetShiftByValuehttp://help//ObjectGetValueByShifthttp://help//ObjectGetVisibilityhttp://help//ObjectMovehttp://help//ObjectNamehttp://help//ObjectsDeleteAllhttp://help//ObjectSethttp://help//ObjectSetFiboDescriptionhttp://help//ObjectSetTexthttp://help//ObjectSetVisibilityhttp://help//ObjectsRedrawhttp://help//ObjectsTotalhttp://help//ObjectTypehttp://help//GetLastErrorhttp://help//ObjectSethttp://help//const_obj_propshttp://help//const_obj_propshttp://help//ObjectCreatehttp://help//ObjectDeletehttp://help//ObjectDescriptionhttp://help//ObjectFindhttp://help//ObjectGethttp://help//ObjectGetFiboDescriptionhttp://help//ObjectGetShiftByValuehttp://help//ObjectGetValueByShifthttp://help//ObjectGetVisibilityhttp://help//ObjectMovehttp://help//ObjectNamehttp://help//ObjectsDeleteAllhttp://help//ObjectSethttp://help//ObjectSetFiboDescriptionhttp://help//ObjectSetTexthttp://help//ObjectSetVisibilityhttp://help//ObjectsRedrawhttp://help//ObjectsTotalhttp://help//ObjectTypehttp://help//GetLastErrorhttp://help//ObjectSethttp://help//const_obj_propshttp://help//const_obj_props
  • 8/11/2019 mql4 manual.pdf

    56/162

    name - ,ni'ue obFect name.

    ty,e - bFect type. %t can be any of the bFect type enumeration"alues.

    *indo* - 9indow inde where obFect will be added. 9indow inde must be greater or e'ual to 2 and less than 9indowsTotal().

    time= - Time part of first point.

    ,rice= - *rice part of first point.

    time> - Time part of second point.

    ,rice> - *rice part of second point.

    time? - Time part of third point.

    ,rice? - *rice part of third point.(am,le

    // ne? te't obJect

    i)(RObJect+reate(6te't_obJect6, OC]_TET, %, "%%@>%">"% 1"F%, 1>%%@5

    V

    Print(6errorF cant create te't_obJectR code X6,UetastError(!

    return(%!

    W

    // ne? label obJect

    i)(RObJect+reate(6label_obJect6, OC]_ACE, %, %, %

    V

    Print(6errorF cant create label_obJectR code X6,UetastError(! return(%!

    W

    ObJect7et(6label_obJect6, OC]P2OP_87TAN+E, "%%!

    ObJect7et(6label_obJect6, OC]P2OP_B87TAN+E, 1%%!

    boolb/ect-elete(stringname)

    eletes obFect with specified name. %f the function succeeds# the return "alue will be true. %f the function succeeds# the return"alue is true. %f the function fails# the return "alue is false. To get the detailed error information# call HetLastError().

    arameters

    name - eleting obFect name.

    (am,le

    ObJectelete(6te't_obJect6!

    stringb/ect-escription(stringname)

    eturn obFect description. To get error information# call HetLastError()function.

    arameters

    name - bFect name.

    (am,le

    // ?riting carts obJect list to te )ile

    int andle, total!

    string obJ_name,)name!

    // )ile name

    )name96obJlist_6I7

  • 8/11/2019 mql4 manual.pdf

    57/162

    ile+lose(andle!

    W

    intb/ectFind(stringname)

    eturn obFect ownerBs window inde. %f the function fails# the return "alue will be -1. To get the detailed error information# callHetLastError()function.

    arametersname - bFect name to chec.

    (am,le

    i)(ObJectind(6line_obJect"6R9?in_id' return(%!

    doubleb/ect3et(stringname$ intinde2)

    eturns obFects property "alue by inde. To chec errors# call HetLastError()function.

    arameters

    name - bFect name.

    inde+ - bFect property inde. %t can be any of the bFect properties enumeration"alues.

    (am,le

    color old+olor9ObJectUet(6line1"6, OC]P2OP_+OO2!

    stringb/ect3etFibo-escription(stringname$ intinde2)

    8unction returns description of 8ibonacci le"el. The amount of 8ibonacci le"els depends on the obFect type. The maimum amountof 8ibonacci le"els ne"er eceeds 0>.To get the detailed error information# call HetLastError() function.

    arameters

    name - bFect name.

    inde+ - %nde of the 8ibonacci le"el.

    (am,le

    Xinclude stdlib>m4L >>>

    string te't!

    )or(int i9%!i"!iII

    V

    te't9ObJectUetiboescription(M ma< be obJectss le3el count less tan "

    i)(UetastError(R9E22_NO_E22O2 breaD!

    Print(M

  • 8/11/2019 mql4 manual.pdf

    58/162

    arameters

    name - bFect name

    s#ift - 7ar inde.

    (am,le

    double price9ObJectUet[alueC%">"5 1"F%, 1>"@5!

    stringb/ectName(intinde2)

    eturns obFect name by inde.

    arameters

    inde+ - bFect inde on the chart. bFect inde must be greater or e'ual to 2 and less than bFectsTotal().

    (am,le

    int obJ_total9ObJectsTotal(!

    string name!

    )or(int i9%!iobJ_total!iII

    V

    name9ObJectName(i!

    Print(i,6ObJect name is 6 I name!

    W

    intb/ects-eleteAll(int6indo6$ inttype%EMP8+)

    emo"es all obFects with specified type and on the specified subwindow of the chart. eturns remo"ed obFects count.

    arameters

    *indo* - 9indow inde from obFects will be deleted. 9indow inde must be greater or e'ual to 2 and less than 9indowsTotal().

    ty,e - ptional obFect type to delete.%t can be any of the bFect type enumeration"alues or EM*T constant to delete all obFects withany types.

    (am,le

    http://help//const_obj_visiblehttp://help//const_obj_visiblehttp://help//const_obj_typeshttp://help//GetLastErrorhttp://help//ObjectsTotalhttp://help//WindowsTotalhttp://help//const_obj_typeshttp://help//const_obj_visiblehttp://help//const_obj_visiblehttp://help//const_obj_typeshttp://help//GetLastErrorhttp://help//ObjectsTotalhttp://help//WindowsTotalhttp://help//const_obj_types
  • 8/11/2019 mql4 manual.pdf

    59/162

    ObJectseleteAll(", OC]_8NE! // remo3es all ori0ontal line obJects )rom ?indo? (inde' ">

    boolb/ect.et(stringname$ intinde2$ doublevalue)

    $hanges named obFects property with new "alue. %f the function succeeds# the return "alue will be true. %f the function fails# thereturn "alue will be false. To get the detailed error information# call HetLastError().

    arameters

    name - bFect name.

    inde+ - bFect "alue inde. %t can be any of bFect properties enumeration"alues.

    value - Gew "alue for property.

    (am,le

    // mo3ing )irst coord to last bar time

    ObJect7et(6M

  • 8/11/2019 mql4 manual.pdf

    60/162

    ObJect7et[isibilit

  • 8/11/2019 mql4 manual.pdf

    61/162

    intBars

    Gumber of bars on the chart.

    int counter91!

    )or(int i91!i9Cars!iII V

    Print(+loseGi-1H!

    W

    doubleBid

    7id price (the &ellerBs price).

    i)(i278(N,%,1@,P28+E_+O7E,%L&5 V

    Order7end(6E276,OP_7E,ots,Cid,,CidI7toposs*Point,Cid-TaDePro)it*Point,

    6M< order X"6,,"%%5>1%>1% 1"F%,2ed!

    return(%!

    W

    doubleClose"#

    eturns the closing price of the bar being referenced.

    int andle, bars9Cars!

    andle9ileOpen(6)ile>cs36,8E_+7[8E_Y28TE,!!

    i)(andleL%

    V

    // ?rite table columns eaders

    ileYrite(andle, 6Time!Open!ig!o?!+lose![olume6!

    // ?rite data

    )or(int i9%! ibars! iII

    ileYrite(andle, TimeGiH, OpenGiH, igGiH, o?GiH, +loseGiH, [olumeGiH!

    ile+lose(andle!

    W

    int-igits

    Gumber of digits after decimal point for the current symbol.

    Print(oubleTo7tr(+loseGi-1H, igits!

    double'ig!"#

  • 8/11/2019 mql4 manual.pdf

    62/162

    eturns the highest price of the bar referenced.

    int andle, bars9Cars!

    andle9ileOpen(6)ile>cs36, 8E_+7[8E_Y28TE, !!

    i)(andleL%

    V

    // ?rite table columns eaders

    ileYrite(andle, 6Time!Open!ig!o?!+lose![olume6! // ?rite data

    )or(int i9%! ibars! iII

    ileYrite(andle, TimeGiH, OpenGiH, igGiH, o?GiH, +loseGiH, [olumeGiH!

    ile+lose(andle!

    W

    doubleLo6"#

    eturns the lowest price of the bar referenced.

    int andle, bars9Cars!

    andle9ileOpen(6)ile>cs36, 8E_+7[8E_Y28TE, 6!6!

    i)(andleL%

    V

    // ?rite table columns eaders

    ileYrite(andle, 6Time!Open!ig!o?!+lose![olume6!

    // ?rite data

    )or(int i9%! ibars! iII

    ileYrite(andle, TimeGiH, OpenGiH, igGiH, o?GiH, +loseGiH, [olumeGiH!

    ile+lose(andle! W

    doublepen"#

    eturns the opening price of the bar referenced.

    int andle, bars9Cars!

    andle9ileOpen(6)ile>cs36, 8E_+7[8E_Y28TE, !!

    i)(andleL% V

    // ?rite table columns eaders

    ileYrite(andle, 6Time!Open!ig!o?!+lose![olume6!

    // ?rite data

    )or(int i9%! ibars! iII

    ileYrite(andle, TimeGiH, OpenGiH, igGiH, o?GiH, +loseGiH, [olumeGiH!

    ile+lose(andle!

    W

    doublePoint

    *oint "alue for the current chart.

  • 8/11/2019 mql4 manual.pdf

    63/162

  • 8/11/2019 mql4 manual.pdf

    64/162

  • 8/11/2019 mql4 manual.pdf

    65/162

    Constant "alue Descri,tion

    E6G6E 2 Go error returned.

    E6G6E&,LT 1 Go error returned# but the result is unnown.

    E6$MMG6E > $ommon error.

    E6%GP!L%6T!E6*!!METE& 0 %n"alid trade parameters.

    E6&EPE67,& 4 Trade ser"er is busy.

    E6L6PE&%G < ld "ersion of the client terminal.E6G6$GGE$T%G A Go connection with trade ser"er.

    E6GT6EG,HS6%HST& ? Got enough rights.

    E6T68EQ,EGT6EQ,E&T& @ Too fre'uent re'uests.

    E6M!L8,G$T%G!L6T!E 3 Malfunctional trade operation.

    E6!$$,GT6%&!7LE A4 !ccount disabled.

    E6%GP!L%6!$$,GT A< %n"alid account.

    E6T!E6T%ME,T 1>@ Trade timeout.

    E6%GP!L%6*%$E 1>3 %n"alid price.

    E6%GP!L%6&T*& 102 %n"alid stops.

    E6%GP!L%6T!E6PL,ME 101 %n"alid trade "olume.

    E6M!YET6$L&E 10> Maret is closed.

    E6T!E6%&!7LE 100 Trade is disabled.

    E6GT6EG,HS6MGE 104 Got enough money.

    E6*%$E6$S!GHE 10< *rice changed.

    E6886Q,TE& 10A ff 'uotes.

    E67YE67,& 10? 7roer is busy.

    E6EQ,TE 10@ e'uote.

    E6E6L$YE 103 rder is loced.

    E6LGH6*&%T%G&6GL6!LL9E 142 Long positions only allowed.

    E6T6M!G6EQ,E&T& 141 Too many re'uests.

    E6T!E6M%86EG%E 14< Modification denied because order too close to maret.

    E6T!E6$GTE=T67,& 14A Trade contet is busy.

    MQL4 run time error codes

  • 8/11/2019 mql4 manual.pdf

    66/162

    Constant "alue Descri,tion

    E6G6MQLE 4222 Go error.

    E69GH68,G$T%G6*%GTE 4221 9rong function pointer.

    E6!!6%GE=6,T686!GHE 422> !rray inde is out of range.

    E6G6MEM6868,G$T%G6$!LL6&T!$Y 4220 Go memory for function call stac.

    E6E$,&%PE6&T!$Y6PE8L9 4224 ecursi"e stac o"erflow.

    E6GT6EG,HS6&T!$Y686*!!METE 422< Got enough stac for parameter.E6G6MEM686*!!METE6&T%GH 422A Go memory for parameter string.

    E6G6MEM686TEM*6&T%GH 422? Go memory for temp string.

    E6GT6%G%T%!L%5E6&T%GH 422@ Got initialied string.

    E6GT6%G%T%!L%5E6!!&T%GH 4223 Got initialied string in array.

    E6G6MEM686!!&T%GH 4212 Go memory for array string.

    E6T6LGH6&T%GH 4211 Too long string.

    E6EM!%GE68M65E6%P%E 421> emainder from ero di"ide.

    E65E6%P%E 4210 5ero di"ide.

    E6,GYG9G6$MM!G 4214 ,nnown command.

    E69GH6I,M* 421< 9rong Fump (ne"er generated error).

    E6GT6%G%T%!L%5E6!! 421A Got initialied array.

    E6LL6$!LL&6GT6!LL9E 421? LL calls are not allowed.

    E6$!GGT6L!6L%7! 421@ $annot load library.

    E6$!GGT6$!LL68,G$T%G 4213 $annot call function.

    E6E=TEG!L6E=*ET6$!LL&6GT6!LL9E 42>2 Epert function calls are not allowed.

    E6GT6EG,HS6MEM686ET,GE6&T%GH 42>1 Got enough memory for temp string returned from function.

    E6&&TEM67,& 42>> &ystem is busy (ne"er generated error).

    E6%GP!L%68,G$T%G6*!!METE&6$,GT 42

  • 8/11/2019 mql4 manual.pdf

    67/162

    Ic#imoku @inko 1yo modes enumeration

    %chimou Yino Syo source of data. ,sed in i%chimou() indicators.%t can be one of the following "alues+

    Constant "alue Descri,tion

    ME6TEGY!G&EG 1 Tenan-sen.

    ME6Y%I,G&EG > YiFun-sen.

    ME6&EGY,&*!G! 0 &enou &pan !.

    ME6&EGY,&*!G7 4 &enou &pan 7.

    ME6$S%GY,&*!G < $hinou &pan.

    Indicators line identifiers

    %ndicator line identifiers used in iM!$()# iP%() and i&tochastic() indicators.%t can be one of the following "alues+

    Constant "alue Descri,tion

    ME6M!%G 2 7ase indicator line.

    ME6&%HG!L 1 &ignal line. %ndicator line identifiers used in i!=()indicator.

    Constant "alue Descri,tion

    ME6M!%G 2 7ase indicator line.

    ME6*L,&% 1 [% indicator line.

    ME6M%G,&% > -% indicator line. %ndicator line identifiers used in i7ands()# iEn"elopes()#iEn"elopesn!rray()# i8ractals()and iHator()indicators.

    Constant "alue Descri,tion

    ME6,**E 1 ,pper line.

    ME6L9E > Lower line.

    Market information identifiers

    Maret information identifiers# used with Maret%nfo() function.%t can be any of the following "alues+

    http://help//iIchimokuhttp://help//iMACDhttp://help//iRVIhttp://help//iStochastichttp://help//iADXhttp://help//iBandshttp://help//iEnvelopeshttp://help//iEnvelopesOnArrayhttp://help//iFractalshttp://help//iGatorhttp://help//MarketInfohttp://help//iIchimokuhttp://help//iMACDhttp://help//iRVIhttp://help//iStochastichttp://help//iADXhttp://help//iBandshttp://help//iEnvelopeshttp://help//iEnvelopesOnArrayhttp://help//iFractalshttp://help//iGatorhttp://help//MarketInfo
  • 8/11/2019 mql4 manual.pdf

    68/162

  • 8/11/2019 mql4 manual.pdf

    69/162

    Constant "alue Descri,tion

    M76Y 222222222 The message bo contains one push button+ Y. This is the default.

    M76Y$!G$EL 222222221 The message bo contains two push buttons+ Y and $ancel.

    M76!7TET%HGE 22222222> The message bo contains three push buttons+ !bort# etry# and %gnore.

    M76E&G$!G$EL 222222220 The message bo contains three push buttons+ es# Go# and $ancel.

    M76E&G 222222224 The message bo contains two push buttons+ es and Go.M76ET$!G$EL 22222222< The message bo contains two push buttons+ etry and $ancel.

    M76$!G$ELT$GT%G,E 22222222A9indows >222+ The message bo contains three push buttons+ $ancel# Try !gain#$ontinue. ,se this message bo type instead of M76!7TET%HGE.

    To display an icon in the message bo# specify one of the following "alues.

    Constant "alue Descri,tion

    M76%$G&T*# M76%$GE# M76%$GS!G 222222212 ! stop-sign icon appears in the message bo.

    M76%$GQ,E&T%G 2222222>2 ! 'uestion-mar icon appears in the message bo.

    M76%$GE=$L!M!T%G# M76%$G9!G%GH 222222202 !n eclamation-point icon appears in the message bo.

    M76%$G%G8M!T%G# M76%$G!&TE%&Y 222222242 !n icon consisting of a lowercase letter i in a circle appears inthe message bo.

    To indicate the default button# specify one of the following "alues.

    Constant "alue Descri,tion

    M76E87,TTG1 222222222The first button is the default button. M76E87,TTG1 is the default unlessM76E87,TTG># M76E87,TTG0# or M76E87,TTG4 is specified.

    M76E87,TTG> 222222122 The second button is the default button.

    M76E87,TTG0 222222>22 The third button is the default button.

    M76E87,TTG4 222222022 The fourth button is the default button.

    Moving Average met#od enumeration

    Mo"ing !"erage calculation method. used with i!lligator()# iEn"elopes()# iEn"elopesn!rray# i8orce()# iHator()# iM!()#iM!n!rray()# i&tde"()# i&tde"n!rray()# i&tochastic() indicators.%t can be any of the following "alues+

    Constant "alue Descri,tion

    ME6&M! 2 &imple mo"ing a"erage#

    ME6EM! 1 Eponential mo"ing a"erage#

    ME6&MM! > &moothed mo"ing a"erage#

    ME6L9M! 0 Linear weighted mo"ing a"erage.

    $!%ect ,ro,erties enumeration

    bFect "alue inde used with bFectHet()and bFect&et()functions. %t can be any of the following "alues+

    http://help//iAlligatorhttp://help//iEnvelopeshttp://help//iEnvelopesOnArrayhttp://help//iForcehttp://help//iGatorhttp://help//iMAhttp://help//iMAOnArrayhttp://help//iStdDevhttp://help//iStdDevOnArrayhttp://help//iStochastichttp://help//ObjectGethttp://help//ObjectSethttp://help//iAlligatorhttp://help//iEnvelopeshttp://help//iEnvelopesOnArrayhttp://help//iForcehttp://help//iGatorhttp://help//iMAhttp://help//iMAOnArrayhttp://help//iStdDevhttp://help//iStdDevOnArrayhttp://help//iStochastichttp://help//ObjectGethttp://help//ObjectSet
  • 8/11/2019 mql4 manual.pdf

    70/162

    Constant "alue Descri,tion

    7I**6T%ME1 2 atetime "alue to setget first coordinate time part.

    7I**6*%$E1 1 ouble "alue to setget first coordinate price part.

    7I**6T%ME> > atetime "alue to setget second coordinate time part.

    7I**6*%$E> 0 ouble "alue to setget second coordinate price part.

    7I**6T%ME0 4 atetime "alue to setget third coordinate time part.

    7I**6*%$E0 < ouble "alue to setget third coordinate price part.7I**6$L A $olor "alue to setget obFect color.

    7I**6&TLE ?Palue is one of &TLE6&L%# &TLE6!&S# &TLE6T# &TLE6!&ST#&TLE6!&STT constants to setget obFect line style.

    7I**69%TS @ %nteger "alue to setget obFect line width. $an be from 1 to %nteger "alue to setget anchor = distance obFect property in piels.

    7I**6%&T!G$E 120 %nteger "alue is to setget anchor distance obFect property in piels.

    7I**68%7LEPEL& >22 %nteger "alue to setget 8ibonacci obFect le"el count. $an be from 2 to 0>.

    7I**68%&TLEPEL[n >12 8ibonacci obFect le"el inde# where nis le"el inde to setget. $an be from 2 to 01.

    $!%ect ty,e enumeration

    bFect type identifier constants used with bFect$reate()# bFectselete!ll()and bFectType()functions. %t can beany of the following "alues+bFects can ha"e 1-0 coordinates related to type.

    http://help//const_arrowshttp://help//const_obj_visiblehttp://help//ObjectCreatehttp://help//ObjectsDeleteAllhttp://help//ObjectTypehttp://help//const_arrowshttp://help//const_obj_visiblehttp://help//ObjectCreatehttp://help//ObjectsDeleteAllhttp://help//ObjectType
  • 8/11/2019 mql4 manual.pdf

    71/162

    Constant "alue Descri,tion

    7I6PL%GE 2 Pertical line. ,ses time part of first coordinate.

    7I6SL%GE 1 Soriontal line. ,ses price part of first coordinate.

    7I6TEG > Trend line. ,ses > coordinates.

    7I6TEG7!GHLE 0 Trend by angle. ,ses 1 coordinate. To set angle of line use bFect&et()function.

    7I6EHE&&%G 4 egression. ,ses time parts of first two coordinates.

    7I6$S!GGEL < $hannel. ,ses 0 coordinates.7I6&TEP$S!GGEL A &tandard de"iation channel. ,ses time parts of first two coordinates.

    7I6H!GGL%GE ? Hann line. ,ses > coordinate# but price part of second coordinate ignored.

    7I6H!GG8!G @ Hann fan. ,ses > coordinate# but price part of second coordinate ignored.

    7I6H!GGH% 3 Hann grid. ,ses > coordinate# but price part of second coordinate ignored.

    7I68%7 12 8ibonacci retracement. ,ses > coordinates.

    7I68%7T%ME& 11 8ibonacci time ones. ,ses > coordinates.

    7I68%78!G 1> 8ibonacci fan. ,ses > coordinates.

    7I68%7!$ 10 8ibonacci arcs. ,ses > coordinates.

    7I6E=*!G&%G 14 8ibonacci epansions. ,ses 0 coordinates.

    7I68%7$S!GGEL 1< 8ibonacci channel. ,ses 0 coordinates.

    7I6E$T!GHLE 1A ectangle. ,ses > coordinates.

    7I6T%!GHLE 1? Triangle. ,ses 0 coordinates.

    7I6ELL%*&E 1@ Ellipse. ,ses > coordinates.

    7I6*%T$S8Y 13 !ndrews pitchfor. ,ses 0 coordinates.

    7I6$$LE& >2 $ycles. ,ses > coordinates.

    7I6TE=T >1 Tet. ,ses 1 coordinate.

    7I6!9 >> !rrows. ,ses 1 coordinate.

    7I6L!7EL >0 Tet label. ,ses 1 coordinate in piels.

    $!%ect visi!ility enumeration

    Time frames where obFect may be shown. ,sed in bFect&et()function to set 7I**6T%ME8!ME& property.

    Constant "alue Descri,tion

    7I6*E%6M1 22221 bFect shown is only on 1-minute charts.

    7I6*E%6M< 2222> bFect shown is only on

  • 8/11/2019 mql4 manual.pdf

    72/162

    Constant "alue Descri,tion

    &M7L6TS,M7&,* A? Thumb up symbol ().

    &M7L6TS,M7&9G A@ Thumb down symbol ().

    &M7L6!9,* >41 !rrow up symbol ().

    &M7L6!99G >4> !rrow down symbol ().

    &M7L6&T*&%HG > $hec sign symbol ().&pecial !rrow codes that eactly points to price and time.

    %t can be one of the following "alues+

    Constant "alue Descri,tion

    1 ,pwards arrow with tip rightwards ().

    > ownwards arrow with tip rightwards ().

    0 Left pointing triangle ().

    4 En ash symbol (X).

    &M7L6LE8T*%$E < Left sided price label.

    &M7L6%HST*%$E A ight sided price label.

    (eries array identifier

    &eries array identifier used with !rray$opy&eries()# Sighest() and Lowest() functions.%t can be any of the following "alues+

    Constant "alue Descri,tion

    ME6*EG 2 pen price.

    ME6L9 1 Low price.

    ME6S%HS > Sigh price.ME6$L&E 0 $lose price.

    ME6PL,ME 4 Polume# used in Lowest() and Sighest() functions.

    ME6T%ME < 7ar open time# used in !rray$opy&eries() function.

    (,ecial constants

    &pecial constants used to indicate parameters and "ariables states. %t can be one of the following "alues+

    Constant value Descri,tion

    G,LL 2 %ndicates empty state of the string.

    EM*T -1 %ndicates empty state of the parameter.

    EM*T6P!L,E 2?8888888 efault custom indicator empty "alue.

    $L6GGE 288888888 %ndicates empty state of colors.

    9SLE6!! 2 ,sed with array functions. %ndicates that all array elements will be processed.

    Time frame enumeration

    Time frame on the chart. %t can be any of the following "alues+

    http://help//ArrayCopySerieshttp://help//Highesthttp://help//Lowesthttp://help//ArrayCopySerieshttp://help//Highesthttp://help//Lowest
  • 8/11/2019 mql4 manual.pdf

    73/162

    Constant "alue Descri,tion

    *E%6M1 1 1 minute.

    *E%6M< < < minutes.

    *E%6M1< 1< 1< minutes.

    *E%6M02 02 02 minutes.

    *E%6S1 A2 1 hour.

    *E%6S4 >42 4 hour.*E%61 1442 aily.

    *E%691 122@2 9eely.

    *E%6MG1 40>22 Monthly.

    2 (ero) 2 Time frame used on the chart.

    Trade o,eration enumeration

    peration type for the rder&end()function. %t can be any of the following "alues+

    Constant "alue Descri,tion

    *67, 2 7uying position.

    *6&ELL 1 &elling position.

    *67,L%M%T > 7uy limit pending position.

    *6&ELLL%M%T 0 &ell limit pending position.

    *67,&T* 4 7uy stop pending position.

    *6&ELL&T* < &ell stop pending position.

    ;ninitiali7e reason codes

    ,ninitialie reason codes returned by ,ninitialieeason() function. %t can be any one of the following "alues+

    Constant "alue Descri,tion

    E!&G6EMPE 1 Epert remo"ed from chart.

    E!&G6E$M*%LE > Epert recompiled.

    E!&G6$S!T$S!GHE 0 symbol or timeframe changed on the chart.

    E!&G6$S!T$L&E 4 $hart closed.

    E!&G6*!!METE& < %nputs parameters was changed by user.

    E!&G6!$$,GT A ther account acti"ated.

    )ingdings sym!ols

    9ingdings font symbols used with !rrow obFects.

    http://help//OrderSendhttp://help//UninitializeReasonhttp://help//OrderSendhttp://help//UninitializeReason
  • 8/11/2019 mql4 manual.pdf

    74/162

    0> 00 04 0< 0A 0? 0@ 03 42 41 4> 40 44 4< 4A 4?

    4@ 43

  • 8/11/2019 mql4 manual.pdf

    75/162

    arameters

    222 - !ny "alues# separated by commas.

    (am,le

    string te't!

    te't97tring+oncatenate(6Account )ree margin is 6, AccountreeMargin(, 6+urrenttime is 6, TimeTo7tr(+urTime(!

    // slo? te't96Account )ree margin is 6 I AccountreeMargin( I 6+urrent time is 6 ITimeTo7tr(+urTime(

    Print(te't!

    int.tringFind(stringte2t$ stringmatc!edte2t$ intstart%,)

    &cans this string for the first match of a substring.

    arameters

    te+t - &tring to search for.

    matc#ed:te+t - &tring to search for.

    start - &tarting inde in the string.

    (am,le

    string te't96Te 4uicD bro?n dog Jumps o3er te la0< )o'6! int inde'97tringind(te't, 6dog Jumps6, %!

    i)(inde'R91$

    Print(6oopsR6!

    int.tring3etC!ar(stringte2t$ intpos)

    eturns character (code) from specified position in the string.

    arameters

    te+t - &tring where character will be retrie"ed.

    ,os - $har ero based position in the string.(am,le

    int car_code97tringUet+ar(6abcde)g6, !

    // car code c is ##

    int.tringLen(stringte2t)

    eturns character count of a string.

    arameters

    te+t - &tring to calculate length.

    (am,le string str96some te't6!

    i)(7tringen(str5 return(%!

    string.tring.etC!ar(stringte2t$ intpos$ intvalue)

    eturns string copy with changed character at the indicated position with new "alue.

    arameters

    te+t - &tring where character will be changed.

    ,os - 5ero based character position in the string. $an be from 2 to &tringLen()-1.

    value - Gew char !&$%% code.

    (am,le

    string str96abcde)g6!

    string str197tring7et+ar(str, , !

    // str1 is 6abce)g6

  • 8/11/2019 mql4 manual.pdf

    76/162

    string.tring.ubstr(stringte2t$ intstart$ intcount%EMP8+)

    Etracts a substring from tet string# starting at position (ero-based).The function returns a copy of the etracted substring if possible# otherwise returns empty string.

    arameters

    te+t - &tring from substring will be etracted.

    start - &ubstring starting inde

    count - $haracter count.

    (am,le

    string te't96Te 4uicD bro?n dog Jumps o3er te la0< )o'6!

    string substr97tring7ubstr(te't, @, 5!

    // subtracted string is 64uicD6 ?ord

    string.tring8rimLet(stringte2t)

    $all the function to trim leading white space characters from the string. &tringTrimLeft remo"es new line# space# and tabcharacters. The function returns a copy of the trimmed string if possible# otherwise returns empty string. eturns new string withchanges.

    arameters

    te+t - &tring to trim left.

    (am,le

    string str196 ello ?orld 6!

    string str"97tringTrime)t(str!

    // a)ter trimming te str" 3ariable ?ill be 6ello Yorld 6

    string.tring8rim*ig!t(stringte2t)

    $all the function to trim leading white space characters from the string. &tringTrimight remo"es new line# space# and tab

    characters. The function returns a copy of the trimmed string if possible# otherwise return empty string.

    arameters

    te+t - &tring to trim right.

    (am,le

    string str196 ello ?orld 6!

    string str"97tringTrim2igt(str!

    // a)ter trimming te str" 3ariable ?ill be 6 ello Yorld6

    Tec#nical Indicator calls

    Accelerator $scillator ' iAC5AccumulationDistri!ution ' iAD5Alligator ' iAlligator5Average Directional Movement Inde+ ' iADB5Average True .ange ' iAT.5A*esome $scillator ' iA$5/ears o*er ' i/earso*er5/ollinger /ands ' i/ands5/ollinger /ands on !uffer ' i/ands$nArray5/ulls o*er ' i/ullso*er5Commodity C#annel Inde+ ' iCCI5Commodity C#annel Inde+ on !uffer ' iCCI$nArray5

    Custom Indicator ' iCustom5DeMarker ' iDeMarker5-nvelo,es ' i-nvelo,es5-nvelo,es on !uffer ' i-nvelo,es$nArray5Force Inde+ ' iForce5

    http://help//iAChttp://help//iADhttp://help//iAlligatorhttp://help//iADXhttp://help//iATRhttp://help//iAOhttp://help//iBearsPowerhttp://help//iBandshttp://help//iBandsOnArrayhttp://help//iBullsPowerhttp://help//iCCIhttp://help//iCCIOnArrayhttp://help//iCustomhttp://help//iDeMarkerhttp://help//iEnvelopeshttp://help//iEnvelopes