MQL4 Reference 2

Share Embed Donate


Short Description

Download MQL4 Reference 2...

Description

MQL4 Reference MetaQuotes Language 4 (MQL4) is a new built-in language for programming of trading strategies. This language allows to create your own Expert Advisors that make trading management automated and are perfectly suitable for implementing of one's own trade strategies. Besides, one can use MQL4 for creation of one's own Custom Indicators, Scripts, and Libraries. You can start learning the language using Sergey Kovalyov's book named Programming in Algorithmic Language MQL4 published and supported by MetaQuotes Software Corp. You can download the Book in .chm format at: http://www.mql4.com/files/mql4bookenglish.chm (size 2.0 Mb). A large amount of functions necessary for analysis of the current and previously income quotes, as well as basic arithmetic and logic operations are included in MQL4 structure. There are also basic indicators built in and commands of order placement and control. The MetaEditor 4 (text editor) that highlights different constructions of MQL4 language is used for writing the program code. It helps users to orientate themselves in the expert system text quite easily. We use MetaQuotes Language Dictionary as a Help System for MQL4 language. An abridged guide contains functions divided into categories, operations, reserved words, and other language constructions and allows finding the description of every element we use. Programs written in MetaQuotes Language 4 have different features and purposes:



Expert Advisor is a mechanical trading system (MTS) linked up to a certain chart. An Advisor starts to run with every incoming tick for a given symbol. The Advisor will not be launched for a new, tick if it is processing the previous one at this moment (i.e., the Advisor has not completed its operation yet). The Advisor can both inform you about a possibility to trade and trade at an account automatically sending orders directly to the trade server. Like most trading systems, the terminal supports testing strategies on history data with displaying trading in-and-out points in the chart. Experts are stored in terminal_directory\experts.



Custom Indicator is a technical indicator written independently in addition to those already integrated into the client terminal. Like built-in indicators, they cannot trade automatically and are intended for implementing of analytical functions only. Custom Indicators are stored in terminal_directory\experts\indicators.



Script is a program intended for a single execution of some actions. Unlike Expert Advisors, Scripts are not run tickwise, but on request. Scripts are stored in terminal_dictionary\experts\scripts.



Library is a set of custom functions containing programs most frequently used. Libraries cannot start execution by itself. Libraries are recommended to be stored in terminal_directory\experts\libraries.



Included file is a source text of the most frequently used blocks of custom programs. Such files can be included into the source texts of experts, scripts, custom indicators, and libraries at the compiling stage. The use of included files is more preferable than the use of libraries because of additional burden occurring at calling library functions. Included files are recommended to be stored in terminal_directory\experts\include

Basics MetaQuotes Language 4 (MQL4) is a new integrated language for programming of trading strategies. This language allows users writing of their own programs (Expert Advisors) that automate trading management and ideally suit for implementing of their own trading strategies. Besides, one can create one's own technical indicators (Custom Indicators), scripts, and libraries in MQL 4. Syntax Syntax of MQL4 is much a C-like syntax, apart from some features:



no address arithmetic;



no operator do ... while;



no operator goto ...;



no operation of [condition]?[expression 1]:[expression 2];



no compound data types (structures);



complex assignments are impossible; for example, val1=val2=0; arr[i++]=val; cond=(cnt=OrdersTotal)>0; etc.;



calculation of a logical expression is always completed, never early terminated.

Comments Multiline comments start with /* symbols and end with */ symbols. Such comments cannot be nested. Single comments start with // symbols, end with the symbol of a new line and can be nested into multiline comments. Comments are allowed where blank spaces are possible and tolerate any number of spaces. Examples:

// single comment /* multiline // nested single comment comment */ Identifiers Identifiers are used as names of variables, functions, and data types. The length of an identifier cannot exceed 31 character. Symbols you can use: numbers from 0 to 9, Latin capital and small letters a to z, A to Z (recognized as different symbols), the symbol of underlining (_). The first symbol cannot be a number. The identifier must not coincide with any reserved word. Examples:

NAME1 namel Total_5 Paper Reserved words The identifiers listed below are fixed reserved words. A certain action is assigned to each of them, and they cannot be used for other purposes: Data types

Memory classes

Operators

Other

bool

extern

break

false

color

static

case

true

datetime

continue

double

default

int

else

string

for

void

if return switch while

Data types Any program operates with data. Data can be of different types depending on their purposes. For example, integer data are used to access to array components. Price data belong to those of double precision with floating point. This is related to the fact that no special data type is foreseen for price data in MQL 4. Data of different types are processed with different rates. Integer data are processed at the fastest. To process the double precision data, a special coprocessor is used. However, because of complicity of internal presentation of data with floating point, they are processed slower than the integer ones. String data are processed at the longest because of dynamic computer memory allocation/reallocation. The main data types are:

      

Integer (int) Boolean (bool) Literals (char) Strings (string) Floating-point number (double) Color (color) Date and time (datetime)

The color and datetime types make sense only to facilitate visualization and enter those parameters that had been set from expert advisor property tab or custom indicator "Inputs" tab. The data of color and datetime types are represented as integer values. int and double are called arithmetic (numeric) types. Only implicit type casting is used in expressions. Type casting Only implicit type casting is used in MQL 4 expressions. The type priority grows at casting:

int (bool,color,datetime); double; string; Before operations (except for the assignment ones) are performed, the data have been conversed into the maximum priority type. Before assignment operations are performed, the data have been cast into the target type. Examples:

int int

i = 1 / 2; i = 1 / 2.0;

double d = double d = double d = string s =

string s = string s =

// no types casting, the result is 0 // the expression is cast to the double type, then is to the target type of int, the result is 0 1.0 / 2.0; // no types casting, the result is 0.5 1 / 2.0; // the expression is cast to the double type that is the same as the target type, the result is 0.5 1 / 2; // the expression of the int type is cast to the target type of double, the result is 0.0 1.0 / 8; // the expression is cast to the double type, then is to the target type of string, the result is "0.12500000" (the string containing 10 characters) NULL; // the constant of type int is cast to the target type of string, the result is "0" (the string containing 1 character) "Ticket #"+12345; // the expression is cast to the string type that is the same as the target type, the result is "Ticket #12345"

Type casting is applied to not only constants, but also variables of corresponding types.

Integer constants Decimals: numbers from 0 to 9; zero must not be the first number. Examples:

12, 111, -956 1007 Hexadecimals: numbers from 0 to 9, letters from a to f or A to F to represent the values 10 to 15; they start with 0x or 0X. Examples:

0x0A, 0x12, 0X12, 0x2f, 0xA3, 0Xa3, 0X7C7 Its internal representation is a long 4-byte integer number. Integer constants can assume values from -2147483648 to 2147483647. If the constant exceeds this range, the result is undefined. Literal constants Any single character enclosed in single quotes or a hexadecimal ASCII-code of a character looking like '\x10' is a character constant of integer type. Some characters like a single quote ('), double quote (") a question mark (?), a reverse slash (\), and control characters can be represented as a combination of characters starting with a reverse slash (\) according to the table below:

line feed horizontal tab carriage return reverse slash single quote double quote hexadecimal ASCII-code

NL (LF) \n HT \t CR \r \ \\ ' \' " \" hh \xhh

If a character different from those listed above follows the reverse slash, the result will not be defined:

int int int int

a b c d

= = = =

'A'; '$'; '©'; // code 0xA9 '\xAE'; // symbol code ®

Its internal representation is a long 4-byte integer number. Literal constants can assume values from 0 to 255. If the constant exceeds this given range, the result is undefined. Boolean constants Boolean constants may have the value of true or false, numeric representation of them is 1 or 0, respectively. True or TRUE, False or FALSE can be used, as well. Examples:

bool a = true; bool b = false; bool c = 1; Its internal representation is a long 4-byte integer number. Boolean constants can assume the values of 0 or 1. Floating-point number constants (double) Floating-point constants consist of an integer part, a point (.), and a fractional part. The integer and the fractional parts represent sequences of decimal numbers. Examples:

double double double double

a b c d

= = = =

12.111; -956.1007; 0.0001; 16;

Its internal representation is a double-precision number of 8 bytes. Floating-point constants can assume values from -1.7 * e-308 to 1.7 * e308. If a constant exceeds this range, the result is undefined.

String constants String constant is a sequence of ASCII-code characters enclosed in double quotes: "Character constant". A string constant is an array of characters enclosed in quotes. It is of the string type. If there is a need to insert a double quote (") into the string, a reverse slash (\) must be put before it. Any special character constants can be inserted into the string if they have a reverse slash (\) before them. The length of a string constant lies between 0 and 255 characters. If the string constant is longer, the superfluous characters on the right will be rejected, and compiler will alert correspondingly. Examples:

"This is a character string" "Copyright symbol \t\xA9" "this line contains a line feed symbol \n" "C:\\Program Files\\MetaTrader 4" "A" "1234567890" "0" "$" Its internal representation is a structure of 8 bytes. The first element of the structure is a long integer that contains the size of the buffer distributed for the line. The second element of the structure is 32-order address of the buffer that contains the line.

Color constants Color constants can be represented in three ways: literally, by integers, or by name (for named Web colors only). Literal representation consists of three parts representing numerical rate values of three main color components: red, green, blue. The constant starts with C and is enclosed in single quotes. Numerical rate values of a color component lie in the range from 0 to 255. Integer-valued representation is written in a form of hexadecimal or a decimal number. A hexadecimal number looks like 0x00BBGGRR where RR is the rate of the red color component, GG - of the green one, and BB - of the blue one. Decimal constants are not directly reflected in RGB. They represent a decimal value of the hexadecimal integer representation. Specific colors reflect the so-called Web colors set. Examples:

// symbol constants C'128,128,128' // gray C'0x00,0x00,0xFF' // blue // named color Red Yellow Black // integer-valued representation 0xFFFFFF // white 16777215 // white 0x008000 // green 32768 // green Its internal representation is a long integer number of 4 bytes. The first byte will not be considered. The other three bytes contain RGB components. Datetime constants Datetime constants can be represented as a literal line consisting of 6 parts for values of year, month, date, hours, minutes, and seconds. The constant is enclosed in single quotes and starts with D. Either date (year, month, date) or time (hours, minutes, seconds), or both can be skipped. Datetime constant can vary from Jan 1, 1970 to Dec 31, 2037. Examples:

D'2004.01.01 00:00' D'1980.07.19 12:30:27' D'19.07.1980 12:30:27' D'19.07.1980 12' D'01.01.2004' D'12:30:27' D''

// New Year

//equal //equal //equal //equal

to to to to

D'1980.07.19 12:00:00' D'01.01.2004 00:00:00' D'[compilation date] 12:30:27' D'[compilation date] 00:00:00'

Its internal representation is a long integer number of 4 bytes. The value represents the amount of seconds elapse from 00:00 Jan 1, 1970.

Operations & Expressions Some characters and character sequences are of a special importance. These are so-called operation symbols, for example:

+ - * / % && || = += *=

symbols of arithmetic operations symbols of logic operations symbols of assignment operations

Operation symbols are used in expressions and have sense when appopriate operands are given them Punctuation marks are emphasized, as well. These are parentheses, braces, comma, colon, and semicolon. Operation symbols, punctuation marks, spaces are used to separate language elements from each other. Expressions An expression consists of one or more operands and operation characters. An expression can be written in several lines. Examples:

a++; b = 10; x = (y * z) / (w + 2) + 127; An expression that ends with a semicolon (;) is an operator. Arithmetical operations Arithmetical operations include additive and multiplicative operations:

Sum of values Difference of values Changing the operation sign Product of values Division quotient Division remainder Adding 1 to the variable value Subtracting 1 from the variable value

i = j + 2; i = j - 3; x = - x; z = 3 * x; i = j / 5; minutes = time % 60; i++; k--;

The operations of adding/subtracting 1 (increment/decrement) cannot be used in expressions. Examples:

int a=3; a++; int b=(a++)*3;

Assignment operation

// valid expression // invalid expression

The value of the expression that includes the given operation is the value of the left operand after assignment.

Assigning the y value to the x variable

y = x;

The following operations unite arithmetic or bitwise operations with operation of assignment:

Adding x to the y variable Subtracting x from the y variable Multiplying the y variable by x Dividing the y variable by x Module x value of y Logical shift of y representation to the right by x bit Logical shift of y representation to the left by x bit Bitwise operation AND Bitwise operation OR Bitwise operation exclusive OR of x and y binary notations

y y y y y y y y y

+= x; -= x; *= x; /= x; %= x; >>= x; y) Print("TRUE");

Bitwise operations

Complement of the variable value up to one. The value of the expression contains 1 in all digits where n contains 0, and it contains 0 in all digits where n contains 1.

b = ~n; Binary-coded representation of x is shifted to the right by y digits. The right shift is a logical one, i.e., the freed left-side bits will be filled with zeros.

x = x >> y; The binary-coded representation of x is shifted to the right by y digits, the freed digits on the right will be filled with zeroes.

x = x = == != || && = += -= *= /= %= >>= iADX(NULL,0,14,PRICE_HIGH,MODE_PLUSDI,0)) return(0); iATR

double iATR(string symbol, int timeframe, int period, int shift) Calculates the Indicator of the average true range and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period for calculation.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iATR(NULL,0,12,0)>iATR(NULL,0,20,0)) return(0); iAO

double iAO(string symbol, int timeframe, int shift) Calculates the Bill Williams' Awesome oscillator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iAO(NULL, 0, 2); iBearsPower

double iBearsPower(string symbol, int timeframe, int period, int applied_price, int shift) Calculates the Bears Power indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period for calculation.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iBearsPower(NULL, 0, 13,PRICE_CLOSE,0); iBands

double iBands(

string symbol, int timeframe, int period, int deviation, int bands_shift, int applied_price, int mode, int shift)

Calculates the Bollinger bands indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate the indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period to calculate the main line.

deviation

-

Deviation from the main line.

bands_shift

-

The indicator shift relative to the chart.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

mode

-

Indicator line index. It can be any of the Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0]) return(0); iBandsOnArray

double iBandsOnArray(

double array[], int total, int period, int deviation, int bands_shift, int mode, int shift)

Calculation of the Bollinger Bands indicator on data stored in a numeric array. Unlike iBands(...), the iBandsOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function. Parameters: array[]

-

Array with data.

total

-

The number of items to be counted. 0 means the whole array.

period

-

Averaging period for calculation of main line.

deviation

-

Deviation from main line.

bands_shift

-

The indicator shift relative to the chart.

mode

-

Indicator line index. It can be any of the Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iBands(ExtBuffer,total,2,0,MODE_LOWER,0)>Low[0]) return(0); iBullsPower

double iBullsPower(string symbol, int timeframe, int period, int applied_price, int shift) Calculates the Bulls Power indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period for calculation.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iBullsPower(NULL, 0, 13,PRICE_CLOSE,0);

iCCI

double iCCI(string symbol, int timeframe, int period, int applied_price, int shift) Calculates the Commodity channel index and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period for calculation.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iCCI(NULL,0,12,PRICE_TYPICAL,0)>iCCI(NULL,0,20,PRICE_TYPICAL,0)) return(0); iCCIOnArray

double iCCIOnArray(double array[], int total, int period, int shift) Calculation of the Commodity Channel Index on data stored in a numeric array. Unlike iCCI(...), the iCCIOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function. Parameters: array[]

-

Array with data.

total

-

The number of items to be counted.

period

-

Averaging period for calculation.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iCCIOnArray(ExtBuffer,total,12,0)>iCCI(NULL,0,20,PRICE_TYPICAL, 0)) return(0); iCustom

double iCustom(string symbol, int timeframe, string name, ..., int mode, int shift) Calculates the specified custom indicator and returns its value. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\experts\indicators directory. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

name

-

Custom indicator compiled program name.

...

-

Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.

mode

-

Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iCustom(NULL, 0, "SampleInd",13,1,0); iDeMarker

double iDeMarker(string symbol, int timeframe, int period, int shift) Calculates the DeMarker indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period for calculation.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iDeMarker(NULL, 0, 13, 1); iEnvelopes

double iEnvelopes(

string symbol, int timeframe, int ma_period, int ma_method, int ma_shift, int applied_price, double deviation, int mode, int shift)

Calculates the Envelopes indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

ma_period

-

Averaging period for calculation of the main line.

ma_method

-

MA method. It can be any of Moving Average method enumeration value.

ma_shift

-

MA shift. Indicator line offset relate to the chart by timeframe.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

deviation

-

Percent deviation from the main line.

mode

-

Indicator line index. It can be any of Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iEnvelopes(NULL, 0, 13,MODE_SMA,10,PRICE_CLOSE,0.2,MODE_UPPER,0); iEnvelopesOnArray

double iEnvelopesOnArray(

double array[], int total, int ma_period, int ma_method, int ma_shift, double deviation, int mode, int shift)

Calculation of the Envelopes indicator on data stored in a numeric array. Unlike iEnvelopes(...), the iEnvelopesOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function. Parameters: array[]

-

Array with data.

total

-

The number of items to be counted.

ma_period

-

Averaging period for calculation of the main line.

ma_method

-

MA method. It can be any of Moving Average method enumeration value.

ma_shift

-

MA shift. Indicator line offset relate to the chart by timeframe.

deviation

-

Percent deviation from the main line.

mode

-

Indicator line index. It can be any of Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iEnvelopesOnArray(ExtBuffer, 0, 13, MODE_SMA, 0.2, MODE_UPPER,0 ); iForce

double iForce(

string symbol, int timeframe, int period, int ma_method, int applied_price, int shift)

Calculates the Force index and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period for calculation.

ma_method

-

MA method. It can be any of Moving Average method enumeration value.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iForce(NULL, 0, 13,MODE_SMA,PRICE_CLOSE,0);

iFractals

double iFractals(string symbol, int timeframe, int mode, int shift) Calculates the Fractals and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

mode

-

Indicator line index. It can be any of the Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iFractals(NULL, 0, MODE_UPPER, 3); iGator

double iGator(

string symbol, int timeframe, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int ma_method, int applied_price, int mode, int shift)

Gator oscillator calculation. The oscillator displays the difference between the Alligator red and blue lines (the upper histogram) and that between red and green lines (the lower histogram). Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

jaw_period

-

Blue line averaging period (Alligator's Jaw).

jaw_shift

-

Blue line shift relative to the chart.

teeth_period

-

Red line averaging period (Alligator's Teeth).

teeth_shift

-

Red line shift relative to the chart.

lips_period

-

Green line averaging period (Alligator's Lips).

lips_shift

-

Green line shift relative to the chart.

ma_method

-

MA method. It can be any of Moving Average method enumeration value.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

mode

-

Indicator line index. It can be any of Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double jaw_val=iGator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_UPPER, 1); iIchimoku

double iIchimoku(

string symbol, int timeframe, int tenkan_sen, int kijun_sen, int senkou_span_b, int mode, int shift)

Calculates the Ichimoku Kinko Hyo and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

tenkan_sen

-

Tenkan Sen averaging period.

kijun_sen

-

Kijun Sen averaging period.

senkou_span_b

-

Senkou SpanB averaging period.

mode

-

Source of data. It can be one of the Ichimoku Kinko Hyo mode enumeration.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double tenkan_sen=iIchimoku(NULL, 0, 9, 26, 52, MODE_TENKANSEN, 1);

iBWMFI

double iBWMFI(string symbol, int timeframe, int shift) Calculates the Bill Williams Market Facilitation index and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iBWMFI(NULL, 0, 0); iMomentum

double iMomentum(string symbol, int timeframe, int period, int applied_price, int shift) Calculates the Momentum indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator.NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Period (amount of bars) for calculation of price changes.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iMomentum(NULL,0,12,PRICE_CLOSE,0)>iMomentum(NULL,0,20,PRICE_CLOSE,0)) return(0); iMomentumOnArray

double iMomentumOnArray(double array[], int total, int period, int shift) Calculation of the Momentum indicator on data stored in a numeric array. Unlike iMomentum(...), the iMomentumOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function. Parameters: array[]

-

Array with data.

total

-

The number of items to be counted.

period

-

Period (amount of bars) for calculation of price changes.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iMomentumOnArray(mybuffer,100,12,0)>iMomentumOnArray(mubuffer,100,20,0)) return(0); iMFI

double iMFI(string symbol, int timeframe, int period, int shift) Calculates the Money flow index and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Period (amount of bars) for calculation of the indicator.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iMFI(NULL,0,14,0)>iMFI(NULL,0,14,1)) return(0);

iMA

double iMA(

string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

Calculates the Moving average indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Averaging period for calculation.

ma_shift

-

MA shift. Indicators line offset relate to the chart by timeframe.

ma_method

-

MA method. It can be any of the Moving Average method enumeration value.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i); iMAOnArray

double iMAOnArray(double array[], int total, int period, int ma_shift, int ma_method, int shift) Calculation of the Moving Average on data stored in a numeric array. Unlike iMA(...), the iMAOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function. Parameters: array[]

-

Array with data.

total

-

The number of items to be counted. 0 means whole array.

period

-

Averaging period for calculation.

ma_shift

-

MA shift

ma_method

-

MA method. It can be any of the Moving Average method enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double macurrent=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,0); double macurrentslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,0); double maprev=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,1); double maprevslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,1); //---if(maprev=macurrentslow) Alert("crossing up"); iOsMA

double iOsMA(

string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int shift)

Calculates the Moving Average of Oscillator and returns its value. Sometimes called MACD Histogram in some systems. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

fast_ema_period

-

Number of periods for fast moving average calculation.

slow_ema_period

-

Number of periods for slow moving average calculation.

signal_period

-

Number of periods for signal moving average calculation.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iOsMA(NULL,0,12,26,9,PRICE_OPEN,1)>iOsMA(NULL,0,12,26,9,PRICE_OPEN,0)) return(0); iMACD

double iMACD(

string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int mode, int shift)

Calculates the Moving averages convergence/divergence and returns its value. In the systems where OsMA is called MACD Histogram, this indicator is displayed as two lines. In the Client Terminal, the Moving Average Convergence/Divergence is drawn as a histogram. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

fast_ema_period

-

Number of periods for fast moving average calculation.

slow_ema_period

-

Number of periods for slow moving average calculation.

signal_period

-

Number of periods for signal moving average calculation.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

mode

-

Indicator line index. It can be any of the Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL ,0)) return(0); iOBV

double iOBV(string symbol, int timeframe, int applied_price, int shift) Calculates the On Balance Volume indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iOBV(NULL, 0, PRICE_CLOSE, 1); iSAR

double iSAR(string symbol, int timeframe, double step, double maximum, int shift) Calculates the Parabolic Stop and Reverse system and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

step

-

Increment, usually 0.02.

maximum

-

Maximum value, usually 0.2.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iSAR(NULL,0,0.02,0.2,0)>Close[0]) return(0);

iRSI

double iRSI(string symbol, int timeframe, int period, int applied_price, int shift) Calculates the Relative strength index and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Number of periods for calculation.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0); iRSIOnArray

double iRSIOnArray(double array[], int total, int period, int shift) Calculation of the Relative Strength Index on data stored in a numeric array. Unlike iRSI(...), the iRSIOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function. Parameters: array[]

-

Array with data.

total

-

The number of items to be counted.

period

-

Number of periods for calculation.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iRSIOnArray(ExtBuffer,1000,14,0)>iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0); iRVI

double iRVI(string symbol, int timeframe, int period, int mode, int shift) Calculates the Relative Vigor index and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Number of periods for calculation.

mode

-

Indicator line index. It can be any of Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iRVI(NULL, 0, 10,MODE_MAIN,0); iStdDev

double iStdDev(

string symbol, int timeframe, int ma_period, int ma_shift, int ma_method, int applied_price, int shift)

Calculates the Standard Deviation indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

ma_period

-

MA period.

ma_shift

-

MA shift.

ma_method

-

MA method. It can be any of Moving Average method enumeration value.

applied_price

-

Applied price. It can be any of Applied price enumeration values.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iStdDev(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);

iStdDevOnArray

double iStdDevOnArray(

double array[], int total, int ma_period, int ma_shift, int ma_method, int shift)

Calculation of the Standard Deviation indicator on data stored in a numeric array. Unlike iStdDev(...), the iStdDevOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function. Parameters: array[]

-

Array with data.

total

-

The number of items to be counted.

ma_period

-

MA period.

ma_shift

-

MA shift.

ma_method

-

MA method. It can be any of Moving Average method enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

double val=iStdDevOnArray(ExtBuffer,100,10,0,MODE_EMA,0); iStochastic

double iStochastic(

string symbol, int timeframe, int %Kperiod, int %Dperiod, int slowing, int method, int price_field, int mode, int shift)

Calculates the Stochastic oscillator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

%Kperiod

-

%K line period.

%Dperiod

-

%D line period.

slowing

-

Slowing value.

method

-

MA method. It can be any ofMoving Average method enumeration value.

price_field

-

Price field parameter. Can be one of this values: 0 - Low/High or 1 - Close/Close.

mode

-

Indicator line index. It can be any of the Indicators line identifiers enumeration value.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_ SIGNAL,0)) return(0); iWPR

double iWPR(string symbol, int timeframe, int period, int shift) Calculates the Larry William's percent range indicator and returns its value. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

period

-

Number of periods for calculation.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

if(iWPR(NULL,0,14,0)>iWPR(NULL,0,14,1)) return(0);

Timeseries access

A group of functions intended for access to price data of any available symbol/period. If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 - the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()). At the testing, price data of the same symbol but of another timeframe are modelled exactly, with the exception of volumes. Volumes of another timeframe are not modelled. Price data of other symbols are not modelled, either. In all cases, the amount of bars in time series is modelled exactly. iBars

int iBars(string symbol, int timeframe) Returns the number of bars on the specified chart. For the current chart, the information about the amount of bars is in the predefined variable named Bars. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

Sample:

Print("Bar count on the 'EUROUSD' symbol with PERIOD_H1 is",iBars("EUROUSD",PERIOD_H1));

iBarShift

int iBarShift(string symbol, int timeframe, datetime time, bool exact=false) Search for bar by open time. The function returns bar shift with the open time specified. If the bar having the specified open time is missing, the function will return -1 or the nearest bar shift depending on the exact. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

time

-

value to find (bar's open time).

exact

-

Return mode when bar not found. false - iBarShift returns nearest. true - iBarShift returns -1.

Sample:

datetime some_time=D'2004.03.21 12:00'; int shift=iBarShift("EUROUSD",PERIOD_M1,some_time); Print("shift of bar with open time ",TimeToStr(some_time)," is ",shift); iClose

double iClose(string symbol, int timeframe, int shift) Returns Close value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. For the current chart, the information about close prices is in the predefined array named Close[]. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ", iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ", iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iHigh

double iHigh(string symbol, int timeframe, int shift) Returns High value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. For the current chart, the information about high prices is in the predefined array named High[]. Parameters: symbol

-

Symbol on that data need to calculate indicator. NULL means current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ", iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ", iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i)); iHighest

int iHighest(string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0) Returns the shift of the maximum value over a specific number of periods depending on type. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

type

-

Series array identifier. It can be any of the Series array identifier enumeration values.

count

-

Number of periods (in direction from the start bar to the back one) on which the calculation is carried out.

start

-

Shift showing the bar, relative to the current bar, that the data should be taken from.

Sample:

double val; // calculating the highest value on the 20 consequtive bars in the range // from the 4th to the 23rd index inclusive on the current chart val=High[iHighest(NULL,0,MODE_HIGH,20,4)]; iLow

double iLow(string symbol, int timeframe, int shift) Returns Low value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. For the current chart, the information about low prices is in the predefined array named Low[]. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ", iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ", iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iLowest

int iLowest(string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0) Returns the shift of the least value over a specific number of periods depending on type. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

type

-

Series array identifier. It can be any of Series array identifier enumeration values.

count

-

Number of periods (in direction from the start bar to the back one) on which the calculation is carried out.

start

-

Shift showing the bar, relative to the current bar, that the data should be taken from.

Sample:

// calculating the lowest value on the 10 consequtive bars in the range // from the 10th to the 19th index inclusive on the current chart double val=Low[iLowest(NULL,0,MODE_LOW,10,10)]; iOpen

double iOpen(string symbol, int timeframe, int shift) Returns Open value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. For the current chart, the information about open prices is in the predefined array named Open[]. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ", iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ", iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i)); iTime

datetime iTime(string symbol, int timeframe, int shift) Returns Time value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. For the current chart, the information about bars open times is in the predefined array named Time[]. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ", iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ", iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iVolume

double iVolume(string symbol, int timeframe, int shift) Returns Tick Volume value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. For the current chart, the information about bars tick volumes is in the predefined array named Volume[]. Parameters: symbol

-

Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe

-

Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

shift

-

Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ", iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ", iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

Trading functions

A group of functions intended for trading management. Trading functions of OrderSend(), OrderClose, OrderCloseBy, OrderDelete, and OrderModify cannot be called from custom indicators. Trading functions can be used in experts and scripts. Trading functions can be called only if the "Allow live trading" property of this particular expert is checked. To trade from experts and scripts, only one thread was provided that was launched in the program trade context (context of automated trading from experts and scripts). This is why, if this context is occupied with an expert trading operation, another expert or script cannot call trading functions at that moment due to error 146 (ERR_TRADE_CONTEXT_BUSY). To check whether it is possible to trade or not, one has to use the IsTradeAllowed() function. To make a clear sharing of access to the trading context, one can use a semaphore on the basis of a global variable the value of which must be changed using the GlobalVariableSetOnCondition() function. Execution errors Any trading operation (functions of OrderSend(), OrderClose, OrderCloseBy, OrderDelete or OrderModify) can fail, for a number of reasons, and return either negative ticket number or FALSE. One can find out about the reason for fail by calling of the GetLastError() function. Every error must be processed in a special way. The most common recommendations are given below. Error codes returned from trade server. Constant

Value

Description

ERR_NO_ERROR

0

Trade operation succeeded.

ERR_NO_RESULT

1

OrderModify attempts to replace the values already set with the same values. One or more values must be changed, then modification attempt can be repeated.

ERR_COMMON_ERROR

2

Common error. All attempts to trade must be stopped until reasons are clarified. Restart of operation system and client terminal will possibly be needed.

ERR_INVALID_TRADE_PARAMETERS

3

Invalid parameters were passed to the trading function, for example, wrong symbol, unknown trade operation, negative slippage, non-existing ticket number, etc. The program logic must be changed.

ERR_SERVER_BUSY

4

Trade server is busy. The attempt can be repeated after a rather long period of time (over several minutes).

ERR_OLD_VERSION

5

Old version of the client terminal. The latest version of the client terminal must be installed.

ERR_NO_CONNECTION

6

No connection to the trade server. It is necessary to make sure that connection has not been broken (for example, using the IsConnected function) and repeat the attempt after a certain period of time (over 5 seconds).

ERR_TOO_FREQUENT_REQUESTS

8

Requests are too frequent. The frequency of requesting must be reduced, the program logic must be changed.

ERR_ACCOUNT_DISABLED

64

The account was disabled. All attempts to trade must be stopped.

ERR_INVALID_ACCOUNT

65

The account number is invalid. All attempts to trade must be stopped.

ERR_TRADE_TIMEOUT

128

Timeout for the trade has been reached. Before retry (at least, in 1-minute time), it is necessary to make sure that trading operation has not really succeeded (a new position has not been opened, or the existing order has not been modified or deleted, or the existing position has not been closed)

ERR_INVALID_PRICE

129

Invalid bid or ask price, perhaps, unnormalized price. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

ERR_INVALID_STOPS

130

Stops are too close, or prices are ill-calculated or unnormalized (or in the open price of a pending order). The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

ERR_INVALID_TRADE_VOLUME

131

Invalid trade volume, error in the volume granularity. All attempts to trade must be stopped, and the program logic must be changed.

ERR_MARKET_CLOSED

132

Market is closed. The attempt can be repeated after a rather long period of time (over several minutes).

ERR_TRADE_DISABLED

133

Trade is disabled. All attempts to trade must be stopped.

ERR_NOT_ENOUGH_MONEY

134

Not enough money to make an operation. The trade with the same parameters must not be repeated. After 5-second (or more) delay, the attempt can be repeated with a smaller volume, but it is necessary to make sure that there is enough money to complete the operation.

ERR_PRICE_CHANGED

135

The price has changed. The data can be refreshed without any delay using the RefreshRates function and make a retry.

ERR_OFF_QUOTES

136

No quotes. The broker has not supplied with prices or refused, for any reason (for example, no prices at the session start, unconfirmed prices, fast market). After 5second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry.

ERR_REQUOTE

138

The requested price has become out of date or bid and ask prices have been mixed up. The data can be refreshed without any delay using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

ERR_ORDER_LOCKED

139

The order has been locked and under processing. All attempts to make trading operations must be stopped, and the program logic must be changed.

ERR_LONG_POSITIONS_ONLY_ALLOWED 140

Only buying operation is allowed. The SELL operation must not be repeated.

ERR_TOO_MANY_REQUESTS

141

Too many requests. The frequency of requesting must be reduced, the program logic must be changed.

142

The order has been enqueued. It is not an error but an interaction code between the client terminal and the trade server. This code can be got rarely, when the disconnection and the reconnection happen during the execution of a trade operation. This code should be processed in the same way as error 128.

143

The order was accepted by the dealer for execution. It is an interaction code between the client terminal and the trade server. It can appear for the same reason as code 142. This code should be processed in the same way as error 128.

144

The order was discarded by the client during manual confirmation. It is an interaction code between the client terminal and the trade server.

ERR_TRADE_MODIFY_DENIED

145

Modifying has been denied since the order is too close to market and locked for possible soon execution. The data can be refreshed after more than 15 seconds using the RefreshRates function, and a retry can be made.

ERR_TRADE_CONTEXT_BUSY

146

The trade thread is busy. Retry only after the IsTradeContextBusy function has returned FALSE.

ERR_TRADE_EXPIRATION_DENIED

147

The use of pending order expiration date has been denied by the broker. The operation can only be repeated if the expiration parameter has been zeroized.

ERR_TRADE_TOO_MANY_ORDERS

148

The amount of open and pending orders has reached the limit set by the broker. New open positions and pending orders can be placed only after the existing positions or orders have been closed or deleted.

OrderClose

bool OrderClose(int ticket, double lots, double price, int slippage, color Color=CLR_NONE)

Closes opened order. If the function succeeds, the return value is true. If the function fails, the return value is false. To get the detailed error information, call GetLastError(). Parameters: ticket

-

Unique number of the order ticket.

lots

-

Number of lots.

price

-

Preferred closing price.

slippage

-

Value of the maximum price slippage in points.

Color

-

Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart.

Sample:

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75) { OrderClose(order_id,1,Ask,3,Red); return(0); } OrderCloseBy

bool OrderCloseBy(int ticket, int opposite, color Color=CLR_NONE) Closes an opened order by another opposite opened order. If the function succeeds, the return value is true. If the function fails, the return value is false. To get the detailed error information, call GetLastError(). Parameters: ticket

-

Unique number of the order ticket.

opposite

-

Unique number of the opposite order ticket.

Color

-

Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart.

Sample:

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75) { OrderCloseBy(order_id,opposite_id); return(0); } OrderClosePrice

double OrderClosePrice() Returns close price for the currently selected order. Note: The order must be previously selected by the OrderSelect() function. Sample:

if(OrderSelect(ticket,SELECT_BY_POS)==true) Print("Close price for the order ",ticket," = ",OrderClosePrice()); else Print("OrderSelect failed error code is",GetLastError());

OrderCloseTime

datetime OrderCloseTime()

Returns close time for the currently selected order. If order close time is not 0 then the order selected and has been closed and retrieved from the account history. Open and pending orders close time is equal to 0. Note: The order must be previously selected by the OrderSelect() function. Sample:

if(OrderSelect(10,SELECT_BY_POS,MODE_HISTORY)==true) { datetime ctm=OrderOpenTime(); if(ctm>0) Print("Open time for the order 10 ", ctm); ctm=OrderCloseTime(); if(ctm>0) Print("Close time for the order 10 ", ctm); } else Print("OrderSelect failed error code is",GetLastError()); OrderComment

string OrderComment() Returns comment for the selected order. Note: The order must be previously selected by the OrderSelect() function. Sample:

string comment; if(OrderSelect(10,SELECT_BY_TICKET)==false) { Print("OrderSelect failed error code is",GetLastError()); return(0); } comment = OrderComment(); // ... OrderCommission

double OrderCommission() Returns calculated commission for the currently selected order. Note: The order must be previously selected by the OrderSelect() function. Sample:

if(OrderSelect(10,SELECT_BY_POS)==true) Print("Commission for the order 10 ",OrderCommission()); else Print("OrderSelect failed error code is",GetLastError());

OrderDelete

bool OrderDelete(int ticket, color Color=CLR_NONE)

Deletes previously opened pending order. If the function succeeds, the return value is true. If the function fails, the return value is false. To get the detailed error information, call GetLastError(). Parameters: ticket

-

Unique number of the order ticket.

Color

-

Color of the arrow on the chart. If the parameter is missing or has CLR_NONE value arrow will not be drawn on the chart.

Sample:

if(Ask>var1) { OrderDelete(order_ticket); return(0); } OrderExpiration

datetime OrderExpiration() Returns expiration date for the selected pending order. Note: The order must be previously selected by the OrderSelect() function. Sample:

if(OrderSelect(10, SELECT_BY_TICKET)==true) Print("Order expiration for the order #10 is ",OrderExpiration()); else Print("OrderSelect returned error of ",GetLastError()); OrderLots

double OrderLots() Returns amount of lots for the selected order. Note: The order must be previously selected by the OrderSelect() function. Sample:

if(OrderSelect(10,SELECT_BY_POS)==true) Print("lots for the order 10 ",OrderLots()); else Print("OrderSelect returned error of ",GetLastError()); OrderMagicNumber

int OrderMagicNumber() Returns an identifying (magic) number for the currently selected order. Note: The order must be previously selected by the OrderSelect() function. Sample:

if(OrderSelect(10,SELECT_BY_POS)==true) Print("Magic number for the order 10 ", OrderMagicNumber()); else Print("OrderSelect returned error of ",GetLastError());

OrderModify

bool

int ticket, double price, double stoploss, double takeprofit, datetime

OrderModify(

expiration, color arrow_color=CLR_NONE)

Modification of characteristics for the previously opened position or pending orders. If the function succeeds, the returned value will be TRUE. If the function fails, the returned value will be FALSE. To get the detailed error information, call GetLastError() function. Notes: Open price and expiration time can be changed only for pending orders. If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated. Pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated. Parameters: ticket

-

Unique number of the order ticket.

price

-

New open price of the pending order.

stoploss

-

New StopLoss level.

takeprofit

-

New TakeProfit level.

expiration

-

Pending order expiration time.

arrow_color

-

Arrow color for StopLoss/TakeProfit modifications in the chart. If the parameter is missing or has CLR_NONE value, the arrows will not be shown in the chart.

Sample:

if(TrailingStop>0) { OrderSelect(12345,SELECT_BY_TICKET); if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF