myeatrade

Blog

MQL4 Array functions (2)

A group of functions to work with arrays.

Arrays are allowed to be maximum four-dimensional. Each dimension is indexed from 0 to dimension size-1. In a particular case of a one-dimensional array of 50 elements, calling of the first element will appear as array[0], of the last one – as array[49].

Using these functions (except for those which change quantitative and qualitative characteristics of the array) one can process predefined time series Time[], Open[], High[], Low[], Close[], Volume[]

 

ArrayDimension()

int ArrayDimension(object array[])

Returns the multidimensional array rank.

Parameters:

array[]   - Array for which the rank will be returned. 

Sample:

int num_array[10][5];
int dim_size;
dim_size=ArrayDimension(num_array);
// dim_size=2

ArrayGetAsSeries()

bool ArrayGetAsSeries(object array[])

Returns TRUE if array is organized as a series array (array elements are indexed from the last to the first one), otherwise returns FALSE.

Parameters:

array[]   - Array to be checked. 

Sample:

  if(ArrayGetAsSeries(array1)==true)
    Print("array1 is indexed as a series array");
  else
    Print("array1 is indexed normally (from left to right)");

ArrayInitialize()

int ArrayInitialize(double &array[], double value)

Sets all elements of a numeric array to the same value. Returns the count of initialized elements.

Note: It is not recommended to initialize index buffers in the custom indicator init() function as such functions are initialized automatically with an "empty value" at allocation and re-allocation of buffers.

Parameters:

array[] - Numeric array to be initialized. 
value   - New value to be set. 

Sample:

  //---- initializing of all array elements with 2.1
  double myarray[10];
  ArrayInitialize(myarray,2.1);

ArrayIsSeries()

bool ArrayIsSeries(object array[])

Returns TRUE if the array under check is a series array (Time[],Open[],Close[],High[],Low[], or Volume[]), otherwise returns FALSE.

Parameters:

array[] - Array under check.  

Sample:

   if(ArrayIsSeries(array1)==false)
     ArrayInitialize(array1,0);
   else
     {
      Print("Series array cannot be initialized!");
      return(-1);
     }

ArrayMaximum()

int ArrayMaximum(double array[], int count=WHOLE_ARRAY, int start=0)

Searches for the element with maximum value. The function returns position of this maximum element in the array.

Parameters:

array[] - The numeric array to search in. 
count   - The amount of elements to search in. 
start   - Initial search index. 

Sample:

double num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
int    maxValueIdx=ArrayMaximum(num_array);
Print("Max value = ", num_array[maxValueIdx]);

ArrayMinimum()

int ArrayMinimum(double array[], int count=WHOLE_ARRAY, int start=0)

Searches for the element with minimum value. The function returns position of this minimum element in the array.

Parameters:

array[] - The numeric array to search in. 
count   - The amount of elements to search in. 
start   - Initial search index. 

Sample:

double num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
int    minValueidx=ArrayMinimum(num_array);
Print("Min value = ", num_array[minValueIdx]);

MQL4 Array functions (1)

A group of functions to work with arrays.

Arrays are allowed to be maximum four-dimensional. Each dimension is indexed from 0 to dimension size-1. In a particular case of a one-dimensional array of 50 elements, calling of the first element will appear as array[0], of the last one – as array[49].

Using these functions (except for those which change quantitative and qualitative characteristics of the array) one can process predefined time series Time[], Open[], High[], Low[], Close[], Volume[]

 

ArrayBsearch()

int ArrayBsearch(double array[], double value, 
                 int count=WHOLE_ARRAY, int start=0, 
                 int direction=MODE_ASCEND)

If the element with the specified value doesn’t exist in the array, the function returns the index of the nearest smallest value of the elements between which the searched value is located.

The function cannot be used with string arrays and series arrays (with the exception of the series array of the bar open time).

Note: Binary search processes only sorted arrays. To sort numeric arrays use the ArraySort() function.

Parameters:

array[]   - The numeric array to search for. 
value     - The value to search for. 
count     - Count of elements to search for. By default, it searches in the whole array. 
start     - Starting index to search for. By default, the search starts at the first element. 
direction - Search direction. It can be any of the following values:
            MODE_ASCEND searching in forward direction,
            MODE_DESCEND searching in backward direction. 

Sample:

   datetime daytimes[];
   int      shift=10,dayshift;
   // All the Time[] series are sorted in descendant mode
   ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
   if(Time[shift]>=daytimes[0]) dayshift=0;
   else
     {
      dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
      if(Period()<PERIOD_D1) dayshift++;
     }
   Print(TimeToStr(Time[shift])," corresponds to ",dayshift," day bar opened at ",
         TimeToStr(daytimes[dayshift]));

ArrayCopy()

int ArrayCopy(object&dest[], object source[], 
              int start_dest=0, int start_source=0, 
              int count=WHOLE_ARRAY)

Copies an array to another one. Arrays must be of the same type, but arrays with type double[], int[], datetime[], color[], and bool[] can be copied as arrays of the same type.

Returns the amount of copied elements.

Parameters:

dest[]       - Destination array. 
source[]     - Source array. 
start_dest   - Starting index for the destination array. By default, start index is 0. 
start_source - Starting index for the source array. By default, start index is 0. 
count        - The count of elements that should be copied. By default, it is WHOLE_ARRAY constant. 

Sample:

  double array1[][6];
  double array2[10][6];
  // array2 is filled with some data
  ArrayCopyRates(array1);
  ArrayCopy(array2,array1,0,0,60);
  // array2 is having the first 10 bars from the history now (first bar considered as bar with index [Bars-1])
  ArrayCopy(array2,array1,0,Bars*6-60,60);
  // array2 is having the last 10 bars from the history now (last bar considered as current bar, bar wit index [0])

ArrayCopyRates()

int ArrayCopyRates(double &dest_array[], 
                   string symbol=NULL, int timeframe=0)

Copies rates to the two-dimensional array from chart RateInfo array and returns copied bars amount, or -1 if failed. First dimension of RateInfo array contains bars amount, second dimension has 6 elements:

  • 0 – time,
  • 1 – open,
  • 2 – low,
  • 3 – high,
  • 4 – close,
  • 5 – volume.

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()).

Notes: This rates array is normally used to pass data to a DLL function.

Memory is not really allocated for data array, and no real copying is performed. When such an array is accessed, the access will be redirected.

Parameters:

dest_array[] - Reference to the two-dimensional destination array of double type. 
symbol       - Symbol name (currency pair name) 
timeframe    - Timeframe. It can be any of the listed timeframes values. 

Sample:

  double array1[][6];
  ArrayCopyRates(array1,"EURUSD", PERIOD_H1);
  Print("Current bar ",TimeToStr(array1[0][0]),"Open", array1[0][1]);

ArrayCopySeries()

int ArrayCopySeries(double &array[], int series_index, 
                    string symbol=NULL, int timeframe=0)

Copies a series array to another one and returns the count of the copied elements.

There is no real memory allocation for data array and nothing is copied. When such an array is accessed, the access is redirected. Excluded are arrays that are assigned as indexed ones in custom indicators. In this case, data are really copied.

If data are copied from another chart with different symbol and/or timeframe, it is possible that the necessary data will lack. In this case, error ERR_HISTORY_WILL_UPDATED (4066 – requested history data under updating) will be placed into the last_error variable, and there will be necessary to retry copying after a certain period of time.

Note: If series_index is MODE_TIME, the array to be passed to the function must be of the datetime type.

Parameters:

array[]      - Reference to the destination one-dimensional numeric array. 
series_index - Series array identifier. It must be one of series array listed identifiers values. 
symbol       - Symbol name (the name of the currency pair) 
timeframe    - Timeframe of the chart. It can be any of Timeframe list values. 

Sample:

datetime daytimes[];
int      shift=10,dayshift,error;
//---- the Time[] array was sroted in the descending order
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
error=GetLastError();
if(error==4066)
  {
   //---- make two more attempts to read
   for(int i=0;i<2; i++)
     {
      Sleep(5000);
      ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
      //---- check the current daily bar time
      datetime last_day=daytimes[0];
      if(Year()==TimeYear(last_day) && Month()==TimeMonth(last_day) && Day()==TimeDay(last_day)) break;
     }
  }
if(Time[shift]>=daytimes[0]) dayshift=0;
else
  {
   dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
   if(Period()<PERIOD_D1) dayshift++;
  }
Print(TimeToStr(Time[shift])," corresponds to ",dayshift," day bar opened at ", TimeToStr(daytimes[dayshift]));

MQL4 Account information

A group of functions to access to the active account information.

 

AccountBalance()

double AccountBalance()

Returns balance value of the current account (the amount of money on the account).

Sample:

Print("Account balance = ",AccountBalance());

AccountCredit()

double AccountCredit()

Returns credit value of the current account.

Sample:

Print("Account number ", AccountCredit());

AccountCompany()

string AccountCompany()

Returns the brokerage company name where the current account was registered.

Sample:

Print("Account company name ", AccountCompany());

AccountCurrency()

string AccountCurrency()

Returns currency name of the current account.

Sample:

Print("account currency is ", AccountCurrency());

AccountEquity()

double AccountEquity()

Returns equity value of the current account. Equity calculation depends on trading server settings.

Sample:

Print("Account equity = ",AccountEquity());

AccountFreeMargin()

double AccountFreeMargin()

Returns free margin value of the current account.

Sample:

Print("Account free margin = ",AccountFreeMargin());

AccountFreeMarginCheck()

double AccountFreeMarginCheck(string symbol, int cmd, double volume)

Returns free margin that remains after the specified position has been opened at the current price on the current account. If the free margin is insufficient, an error 134 (ERR_NOT_ENOUGH_MONEY) will be generated.

Parameters:

symbol - Symbol for trading operation. 
cmd    - Operation type. It can be either OP_BUY or OP_SELL. 
volume - Number of lots. 

Sample:

if(AccountFreeMarginCheck(Symbol(),OP_BUY,Lots)<=0 || GetLastError()==134) return;

AccountFreeMarginMode()

double AccountFreeMarginMode()

Calculation mode of free margin allowed to open positions on the current account. The calculation mode can take the following values:

  • 0 – floating profit/loss is not used for calculation;
  • 1 – both floating profit and loss on open positions on the current account are used for free margin calculation;
  • 2 – only profit value is used for calculation, the current loss on open positions is not considered;
  • 3 – only loss value is used for calculation, the current loss on open positions is not considered.

Sample:

if(AccountFreeMarginMode()==0)
   Print("Floating Profit/Loss do not use.");

AccountLeverage()

int AccountLeverage()

Returns leverage of the current account.

Sample:

Print("Account #",AccountNumber(), " leverage is ", AccountLeverage());

AccountMargin()

double AccountMargin()

Returns margin value of the current account.

Sample:

Print("Account margin ", AccountMargin());

AccountName()

string AccountName()

Returns the current account name.

Sample:

Print("Account name ", AccountName());

AccountNumber()

int AccountNumber()

Returns the number of the current account.

Sample:

Print("account number ", AccountNumber());

AccountProfit()

double AccountProfit()

Returns profit value of the current account.

Sample:

Print("Account profit ", AccountProfit());

AccountServer()

string AccountServer()

Returns the connected server name.

Sample:

Print("Server name is ", AccountServer());

AccountStopoutLevel()

int AccountStopoutLevel()

Returns the value of the Stop Out level.

Sample:

Print("StopOut level = ", AccountStopoutLevel());

AccountStopoutMode()

int AccountStopoutMode()

Returns the calculation mode for the Stop Out level. Calculation mode can take the following values:

  • 0 – calculation of percentage ratio between margin and equity;
  • 1 – comparison of the free margin level to the absolute value.

Sample:

int level=AccountStopoutLevel();
if(AccountStopoutMode()==0)
   Print("StopOut level = ", level, "%");
else
   Print("StopOut level = ", level, " ", AccountCurrency());

MQL4 Runtime errors

In the executing sub-system of the client terminal, the error code can be stored, in the case of its occurring at an mql4 program execution. There is a specific last_error variable provided for every executable mql4 program. Before the init function is run, the last_error variable has been zeroized. If an error occurs during the process of calculation or that of calling the built-in function, the last_error variable takes the corresponding error code. Value stored in this variable can be got using the GetLastError function. At that, the last_error variable will be zeroized.

There is a number of critical errors that cause immediate stopping of program execution:

Constant Value Description
ERR_WRONG_FUNCTION_POINTER 4001 At calling of an internal function, a wrong function pointer has been detected
ERR_NO_MEMORY_FOR_CALL_STACK 4003 At calling of an internal function, it is impossible to reallocate memory for the function calls stack
ERR_RECURSIVE_STACK_OVERFLOW 4004 The data stack is overflowed at the recursive function call
ERR_NO_MEMORY_FOR_PARAM_STRING 4006 At calling of an internal function, it is impossible to allocate memory for passing the string as a function parameter
ERR_NO_MEMORY_FOR_TEMP_STRING 4007 It is impossible to allocate the temporary buffer for string operations
ERR_NO_MEMORY_FOR_ARRAYSTRING 4010 At assignment, it is impossible to reallocate memory for a string in an array
ERR_TOO_LONG_STRING 4011 At assignment, too long resulting string to be placed into the service buffer (no possibility to reallocate for the service buffer)
ERR_REMAINDER_FROM_ZERO_DIVIDE 4012 Dividing by 0 when taking the remainder of the division
ERR_ZERO_DIVIDE 4013 Dividing by 0
ERR_UNKNOWN_COMMAND 4014 Unknown instruction

If the program stopped working due to a critical error, the code of this error can be read at the next launching of the start or deinit function using the GetLastError() function. Thelast_error variable is not zeroized before the start or deinit function starts.

There is a number of critical errors referred to imported functions call that cause immediate stopping of expert advisor or custom indicator execution the start function will not be launched until expert or indicator is re-initialized.

Constant Value Description
ERR_CANNOT_LOAD_LIBRARY 4018 At calling of an imported function, loading error of dll or ex4 library occurred
ERR_CANNOT_CALL_FUNCTION 4019 At calling of an imported function, it was found out that dll or ex4 library did not contain the called function
ERR_DLL_CALLS_NOT_ALLOWED 4017 At calling of an imported dll function, it was found out that dll imports were not allowed
ERR_EXTERNAL_CALLS_NOT_ALLOWED 4020 At calling of an ex4 function, it was found out that external ex4 imports were not allowed

Other errors do not interrupt program execution.

Constant Value Description
ERR_ARRAY_INDEX_OUT_OF_RANGE 4002 Attempt to access an array item number of which is out of the array range
ERR_NOT_INITIALIZED_STRING 4008 Not initialized string; no value was assigned to the string being an operand in an expression
ERR_NOT_INITIALIZED_ARRAYSTRING 4009 Not initialized string in the array string; no value was assigned to the string item being an operand in an expression
ERR_NO_MEMORY_FOR_RETURNED_STR 4021 It is impossible to reallocate memory for a string returned from function

The ERR_NO_MQLERROR (4000) code is never generated.

There is a number of errors which are possible only as a result of software or hardware failure.If any errors described below occur repeatedly, one should contact the developers.

Constant Value Description
ERR_WRONG_FUNCTION_POINTER 4001 At calling of an internal function, a wrong function pointer has been detected
ERR_UNKNOWN_COMMAND 4014 Unknown instruction
ERR_NOT_INITIALIZED_ARRAY 4016 Not initialized array
ERR_INVALID_FUNCTION_PARAMSCNT 4050 Invalid parameters count passed into built-in function
ERR_STRING_FUNCTION_INTERNAL 4052 String function internal error
ERR_TRADE_ERROR 4067 Trade function internal error
ERR_SOME_OBJECT_ERROR 4207 Object function internal error

There are some functions that always change the last_error variable value

Function Error codes
AccountFreeMarginCheck ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_UNKNOWN_SYMBOL (4106), ERR_NOT_ENOUGH_MONEY (134)
OrderSend ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_PRICE_PARAM (4107), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), ERR_LONGS_NOT_ALLOWED (4110), ERR_SHORTS_NOT_ALLOWED (4111), code returned by trade server
OrderClose ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_PRICE_PARAM (4107), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
OrderCloseBy ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
OrderDelete ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
OrderModify ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_PRICE_PARAM (4107), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
GetLastError ERR_NO_ERROR (0)

Some functions change value of the last_error variable only if an error occurs.

Function Error codes
ArrayBsearch ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayCopy ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCOMPATIBLE_ARRAYS (4056), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayCopyRates ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCOMPATIBLE_ARRAYS (4056), ERR_STRING_PARAMETER_EXPECTED (4062),
ArrayCopySeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCORRECT_SERIESARRAY_USING (4054), ERR_INCOMPATIBLE_ARRAYS (4056), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_HISTORY_WILL_UPDATED (4066), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayDimension ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArrayGetAsSeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArrayInitialize ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayIsSeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArrayMaximum ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayMinimum ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayRange ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayResize ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArraySetAsSeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArraySize ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArraySort ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCORRECT_SERIESARRAY_USING (4054), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileClose ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileDelete ERR_WRONG_FILE_NAME (4101), ERR_SOME_FILE_ERROR (4100)
FileFlush ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileIsEnding ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileIsLineEnding ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileOpen ERR_TOO_MANY_OPENED_FILES (4102), ERR_WRONG_FILE_NAME (4101), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_SOME_FILE_ERROR (4100), ERR_CANNOT_OPEN_FILE (4103)
FileOpenHistory ERR_TOO_MANY_OPENED_FILES (4102), ERR_WRONG_FILE_NAME (4101), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_SOME_FILE_ERROR (4100), ERR_CANNOT_OPEN_FILE (4103)
FileReadArray ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_ARRAY_ERROR (4053), ERR_SOME_FILE_ERROR (4100), ERR_END_OF_FILE (4099)
FileReadDouble ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_END_OF_FILE (4099)
FileReadInteger ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_END_OF_FILE (4099)
FileReadNumber ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100), ERR_END_OF_FILE (4099)
FileReadString ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100), ERR_TOO_LONG_STRING (4011), ERR_END_OF_FILE (4099)
FileSeek ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileSize ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileTell ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileWrite ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_SOME_FILE_ERROR (4100)
FileWriteDouble ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100)
FileWriteInteger ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100)
FileWriteString ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100), ERR_STRING_PARAMETER_EXPECTED (4062)
FileWriteArray ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100),
GlobalVariableCheck ERR_STRING_PARAMETER_EXPECTED (4062)
GlobalVariableDel ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLES_PROCESSING (4057)
GlobalVariableGet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLE_NOT_FOUND (4058)
GlobalVariablesDeleteAll ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLES_PROCESSING (4057)
GlobalVariableSet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLES_PROCESSING (4057), ERR_GLOBAL_VARIABLE_NOT_FOUND (4058)
GlobalVariableSetOnCondition ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLE_NOT_FOUND (4058)
iCustom ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
technical indicators, series access functions ERR_HISTORY_WILL_UPDATED (4066)
technical indicators OnArray ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
IndicatorBuffers ERR_INVALID_FUNCTION_PARAMVALUE (4051)
IndicatorDigits ERR_INVALID_FUNCTION_PARAMVALUE (4051)
IndicatorShortName ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MarketInfo ERR_STRING_PARAMETER_EXPECTED (4062), ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_UNKNOWN_SYMBOL (4106), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MathArccos ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MathArcsin ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MathMod ERR_ZERO_DIVIDE (4013)
MathSqrt ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MessageBox ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_STRING_PARAMETER_EXPECTED (4062)
ObjectCreate ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_UNKNOWN_OBJECT_TYPE (4203), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_OBJECT_ALREADY_EXISTS (4200), ERR_NO_SPECIFIED_SUBWINDOW (4206)
ObjectDelete ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectDescription ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectFind ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204)
ObjectGet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectGetFiboDescription ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_TYPE (4203), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectGetShiftByValue ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_OBJECT_COORDINATES_ERROR (4205)
ObjectGetValueByShift ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_OBJECT_COORDINATES_ERROR (4205)
ObjectMove ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectName ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_ARRAY_INDEX_OUT_OF_RANGE (4002)
ObjectSet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectSetText ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectSetFiboDescription ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_TYPE (4203), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectType ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
OrderClosePrice ERR_NO_ORDER_SELECTED (4105)
OrderCloseTime ERR_NO_ORDER_SELECTED (4105)
OrderComment ERR_NO_ORDER_SELECTED (4105)
OrderCommission ERR_NO_ORDER_SELECTED (4105)
OrderExpiration ERR_NO_ORDER_SELECTED (4105)
OrderLots ERR_NO_ORDER_SELECTED (4105)
OrderMagicNumber ERR_NO_ORDER_SELECTED (4105)
OrderOpenPrice ERR_NO_ORDER_SELECTED (4105)
OrderOpenTime ERR_NO_ORDER_SELECTED (4105)
OrderPrint ERR_NO_ORDER_SELECTED (4105)
OrderProfit ERR_NO_ORDER_SELECTED (4105)
OrderStopLoss ERR_NO_ORDER_SELECTED (4105)
OrderSwap ERR_NO_ORDER_SELECTED (4105)
OrderSymbol ERR_NO_ORDER_SELECTED (4105)
OrderTakeProfit ERR_NO_ORDER_SELECTED (4105)
OrderTicket ERR_NO_ORDER_SELECTED (4105)
OrderType ERR_NO_ORDER_SELECTED (4105)
PlaySound ERR_WRONG_FILE_NAME (4101)
SendFTP ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_STRING_PARAMETER_EXPECTED (4062)
SendMail ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_FUNCTION_NOT_CONFIRMED (4060), ERR_SEND_MAIL_ERROR (4061)
SetIndexArrow ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexBuffer ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCORRECT_SERIESARRAY_USING (4054), ERR_INCOMPATIBLE_ARRAYS (4056)
SetIndexDrawBegin ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexEmptyValue ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexLabel ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_STRING_PARAMETER_EXPECTED (4062)
SetIndexShift ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexStyle ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetLevelValue ERR_INVALID_FUNCTION_PARAMVALUE (4051)
Sleep ERR_CUSTOM_INDICATOR_ERROR (4055)
StringFind ERR_STRING_PARAMETER_EXPECTED (4062)
StringGetChar ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NOT_INITIALIZED_STRING (4008), ERR_ARRAY_INDEX_OUT_OF_RANGE (4002)
StringLen ERR_STRING_PARAMETER_EXPECTED (4062)
StringSetChar ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_NOT_INITIALIZED_STRING (4008), ERR_TOO_LONG_STRING (4011), ERR_ARRAY_INDEX_OUT_OF_RANGE (4002)
StringSubstr ERR_STRING_PARAMETER_EXPECTED (4062), ERR_TOO_LONG_STRING (4011)
StringTrimLeft ERR_STRING_PARAMETER_EXPECTED (4062)
StringTrimRight ERR_STRING_PARAMETER_EXPECTED (4062)
WindowIsVisible ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059)
WindowFind ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NOT_INITIALIZED_STRING (4008)
WindowHandle ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NOT_INITIALIZED_STRING (4008)
WindowScreenShot ERR_WRONG_FILE_NAME (4101), ERR_INVALID_FUNCTION_PARAMVALUE (4051)

Other functions never change the last_error variable value.

MQL4 Program Run

For an MQL4 program to work, it must be compiled (the "Compile" button or F5). It must be compiled without any errors (warnings are allowed, but they must be analyzed). At this, in the corresponding directory, terminal_dir\experts, terminal_dir\experts\indicators, or terminal_dir\experts\scripts, an executable file must be created that has the same name and extension EX4. It is this file that can be launched for execution.

Experts, custom indicators, and scripts are attached to one of the opened charts by dragging with the mouse from the "Navigator" window of the client terminal to the corresponding chart (the Drag’n’Drop technique). MQL4 programs can work only when the client terminal is on.

For an expert to stop working,it must be deleted from the chart using "Expert Advisors – Delete" in the chart context menu. The status of the "Enable Expert Advisors" field influences the running of the expert.

For a custom indicator to stop working, it must be deleted from the chart.

Custom indicators and expert advisors operate until they are explicitly deleted from the chart. Information about the attached experts and custom indicators is saved between client terminal startups. Scripts are executed once and deleted automatically after they have completed their operation, or when the current chart has been closed or changed its status, or when the client terminal has been terminated. Scripts are not launched at the terminal restart since information about them is not saved.

In the same chart, one expert, one script, and an unlimited amount of indicators can work simultaneously.

Program Run

Immediately after the program has been attached to the chart, it starts working with the init() function. The init() function of an expert advisor or a custom indicator attached to the chart will run just after client terminal has started and history data (this concerns only experts, but not indicators) have been loaded additionally, after the symbol and/or chart period have been changed, after the program has been recompiled in MetaEditor, after inputs have been changed from the window of expert or custom indicator settings. An expert will also be initialized after the account has been changed.

Every program attached to a chart completes its work with the deinit() function. The deinit() function runs at the client terminal shutdown, at chart closing, immediately before the symbol and/or chart period is changed, at successful recompiling of the program, at changing of inputs, or at changing of the account. One can see the reason of deinitialization using the UninitializeReason() function during execution of the deinit() function. The deinit() function must be executed within 2.5 seconds. If the function has not completed its execution within this time period, it will be completed forcedly. Scripts are an exception to this rule, as they normally finish their working independently, without any commands from outside. If a script works very long (due to endless loop, foe example), it can be finished by an outside command (at deletion of the script from the chart context menu, at attaching of a new script to the same chart, at closing of the chart, at changing of the symbol and/or chart period). In this case, the deinit() function is limited by 2.5 seconds, too.

At incoming of new quotes, the start() function of the attached experts and custom indicators will be executed. If the start() function launched at the preceding quote was running when a new quote came, the new quote will be skipped by the expert. All new quotes income while the program was being executed are skipped by the program until the current execution of the start() function has been completed. After that, the start() function will be run only when a successive new quote incomes. For custom indicators, the start() function will be launched for recalculation after the current chart symbol or timeframe has been changed independently on new quotes incoming. The start() function will not be run when the expert properties window is open. The latter cannot be opened during the expert execution.

Detaching of the program from the chart, change of symbol and/or chart period, change of the account, closing of the chart, as well as shutdown of the client terminal will interrupt execution of the program. If the start() function was being executed at the moment when the stop working command was given, the time remaining for its work is limited by 2.5 seconds. The program can get to know that it is tried to shut it down with the built-in function of IsStopped() and finish its work correctly.

Execution of scripts does not depend on incoming quotes. At change of symbol and/or chart period, the script will finish its work and be unloaded from the client terminal.

Scripts and experts work in their own thread. Custom indicators work in the main interface thread. If a custom indicator has been called with the iCustom() function, this indicator works in the thread of the program that has called it. Library (imported) functions work in the calling program thread, as well.

Imported functions call

To import functions during execution of an mql4 program, the so-called late binding is used. This means that, until the imported function is called, the corresponding module (ex4 or dll) will not be loaded. MQL4 and DLL libraries are executed in the calling module thread.

It is not recommended to use a fully qualified name of the module to be loaded like Drive:\Directory\FileName.Ext. MQL4 libraries are loaded from the terminal_dir\experts\libraries folder. If the library has not been found, there will be made an attempt to load the library from the terminal_dir\experts folder.

System libraries (DLLs) are loaded by the rules of the operation system. If the library has already been loaded (by another expert, for example, or from another client terminal launched at the same time), the library already loaded will be referenced to. Otherwise, the searching will be preformed in the following order:

  • 1. The terminal_dir\experts\libraries directory.
  • 2. The directory from which the terminal_dir client terminal was launched.
  • 3. The current directory.
  • 4. The system directory of windows_dir\SYSTEM32 (or windows_dir\SYSTEM for Win98).
  • 5. The directory where windows_dir operation system was installed.
  • 6. Directories listed in the PATH environment system variable.

If a DLL uses another DLL in its work, the former one will not be loaded if the latter one is unavailable.

Unlike system libraires, custom libraries (MQL4) are loaded for every calling module separately, independently on whether the called library has been loaded by any other module. For example, the caller.ex4 module calls functions from lib1.ex4 and lib2.ex4 libraries. The lib1.ex4 library, in its turn, calls functions from the lib2.ex4 library. In this case, one more copy of the lib1.ex4 library and two copies of the lib2.ex4 library will be loaded, regardless that all calls come from the same caller.ex4 module.

Functions imported from DLL into an mql4 program must provide linkage convention accepted for Windows API functions. To provide such a convention, the key word __stdcall specific for compilers of Microsoft(r) company is used in the source codes of programs written in C or C++ language. The above linkage convention is characterized by the following:

  • – calling function (in our case, it is an mql4 program) must "see" the called (imported from DLL) function prototype in order to put parameters onto the stack in a proper way;
  • – calling function (in our case, it is an mql4 program) puts parameters onto the stack in the reversed order, i.e., from right to left; it is this order in which the imported function reads parameters passed to it;
  • – parameters are passed by their values, except for those explicitely passed by a link (in our case, these are lines);
  • – on reading the parameters passed to it, the imported function will flush the stack by itself.

At describing of the imported function prototype, it is useless to use parameters with default values as all parameters must be passed explicitely to the imported function.

If the call for an imported function failed (expert settings do not allow DLL imports, or the corresponding library could not be loaded for any reason), the expert stops working putting the corresponding message into the "expert stopped" journal. At that, the expert will not be launched until it is re-initialized. An expert can be re-initialized as a result of recompiling or opening of the expert properties table and pressing of OK button.

MQL4 Predefined variables

For each executable MQL4 program, a number of predefined variables is supported that reflect the state of the current price chart at the launching of a program: an expert, a script, or a custom indicator.

Libraries use variables of the module that has called a library.

To have a safe and quick access to these data, client terminal provides local copies of predefined variables for each launched program separately. These data are updated at every launch of an attached expert or a custom indicator automatically or using the RefreshRates() function call.

Ask

double Ask

The latest known seller’s price (ask price) for the current symbol. The RefreshRates() function must be used to update.

See also MarketInfo().

Sample:

  if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
    {
     OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,
               "My order #2",3,D'2005.10.10 12:30',Red);
     return;
    }

Bid

double Bid

The latest known buyer’s price (offer price, bid price) of the current symbol. The RefreshRates() function must be used to update.

See also MarketInfo().

Sample:

  if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
    {
     OrderSend("EURUSD",OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,
               "My Order #2",3,D'2005.10.10 12:30',Red);
     return(0);
    }

Bars

int Bars

Number of bars in the current chart.

See also iBars().

Sample:

  int counter=1;
  for(int i=1; i<=Bars; i++)
    {
     Print(Close[i-1]);
    }

Digits

int Digits

Number of digits after decimal point for the current symbol prices.

See also MarketInfo().

Sample:

Print(DoubleToStr(Close[0], Digits));

Point

double Point

The current symbol point value in the quote currency.

See also MarketInfo().

Sample:

OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

Close[ ]

double Close[]

Series array that contains close prices for each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iClose().

Sample:

  int handle = FileOpen("file.csv", FILE_CSV|FILE_WRITE, ";");
  if(handle>0)
    {
     // table column headers recording
     FileWrite(handle, "Time;Open;High;Low;Close;Volume");
     // data recording
     for(int i=0; i<Bars; i++)
       FileWrite(handle, Time[i], Open[i], High[i], Low[i], Close[i], Volume[i]);
     FileClose(handle);
    }

Open[ ]

double Open[]

Series array that contains open prices of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iOpen().

Sample:

   i = Bars - counted_bars - 1;
   while(i>=0)
     {
      double high  = High[i];
      double low   = Low[i];
      double open  = Open[i];
      double close = Close[i];
      AccumulationBuffer[i] = (close-low) - (high-close);
      if(AccumulationBuffer[i] != 0)
        {
         double diff = high - low;
         if(0==diff)
            AccumulationBuffer[i] = 0;
         else
           {
            AccumulationBuffer[i] /= diff;
            AccumulationBuffer[i] *= Volume[i];
           }
        }
      if(i<Bars-1) AccumulationBuffer[i] += AccumulationBuffer[i+1];
      i--;
     }

High[ ]

double High[]

Series array that contains the highest prices of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iHigh().

Sample:

//---- maximums counting
   i=Bars-KPeriod;
   if(counted_bars>KPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double max=-1000000;
      k = i + KPeriod-1;
      while(k>=i)
        {
         price=High[k];
         if(max<price) max=price;
         k--;
        }
      HighesBuffer[i]=max;
      i--;
     }
//----

Low[ ]

double Low[]

Series array that contains the lowest prices of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iLow().

Sample:

//---- minima counting
   i=Bars-KPeriod;
   if(counted_bars>KPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double min=1000000;
      k = i + KPeriod-1;
      while(k>=i)
        {
         price=Low[k];
         if(min>price) min=price;
         k--;
        }
      LowesBuffer[i]=min;
      i--;
     }
//----

Time[ ]

datetime Time[]

Series array that contains open time of each bar of the current chart. Data like datetime represent time, in seconds, that has passed since 00:00 a.m. of 1 January, 1970.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iTime().

Sample:

   for(i=Bars-2; i>=0; i--)
     {
      if(High[i+1] > LastHigh) LastHigh = High[i+1];
      if(Low[i+1] < LastLow)   LastLow  = Low[i+1];
      //----
      if(TimeDay(Time[i]) != TimeDay(Time[i+1]))
        {
         P = (LastHigh + LastLow + Close[i+1])/3;
         R1 = P*2 - LastLow;
         S1 = P*2 - LastHigh;
         R2 = P + LastHigh - LastLow;
         S2 = P - (LastHigh - LastLow);
         R3 = P*2 + LastHigh - LastLow*2;
         S3 = P*2 - (LastHigh*2 - LastLow);
         LastLow  = Open[i];
         LastHigh = Open[i];
        }
      //----
      PBuffer[i]  = P;
      S1Buffer[i] = S1;
      R1Buffer[i] = R1;
      S2Buffer[i] = S2;
      R2Buffer[i] = R2;
      S3Buffer[i] = S3;
      R3Buffer[i] = R3;
     }

Volume[ ]

double Volume[]

Series array that contains tick volumes of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iVolume().

Sample:

      if(i==0 && time0<i_time+periodseconds)
        {
         d_volume += Volume[0];
         if(Low[0]<d_low)   d_low = Low[0];
         if(High[0]>d_high) d_high = High[0];
         d_close = Close[0];
        }
      last_fpos = FileTell(ExtHandle);
      last_volume = Volume[i];
      FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
      FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);

MQL4 Standard constants(4)


Uninitialize reason codes

Uninitialize reason codes returned by UninitializeReason() function. It can be any one of the following values:

Constant Value Description
  0 Script finished its execution independently.
REASON_REMOVE 1 Expert removed from chart.
REASON_RECOMPILE 2 Expert recompiled.
REASON_CHARTCHANGE 3 symbol or timeframe changed on the chart.
REASON_CHARTCLOSE 4 Chart closed.
REASON_PARAMETERS 5 Inputs parameters was changed by user.
REASON_ACCOUNT 6 Other account activated.

Special constants

Special constants used to indicate parameters and variables states. It can be one of the following values:

Constant Value Description
NULL 0 Indicates empty state of the string.
EMPTY -1 Indicates empty state of the parameter.
EMPTY_VALUE 0x7FFFFFFF Default custom indicator empty value.
CLR_NONE 0xFFFFFFFF Indicates empty state of colors.
WHOLE_ARRAY 0 Used with array functions. Indicates that all array elements will be processed.

Error codes

The GetLastError() function return codes. Error code constants defined at stderror.mqh file. To print text messages use ErrorDescription() function defined at stdlib.mqh file.

#include <stderror.mqh>
#include <stdlib.mqh>
void SendMyMessage(string text)
  {
   int check;
   SendMail("some subject", text);
   check=GetLastError();
   if(check!=ERR_NO_ERROR) Print("Cannot send message, error: ",ErrorDescription(check));
  }

Error codes returned from trade server.

Constant Value Description
ERR_NO_ERROR 0 No error returned.
ERR_NO_RESULT 1 No error returned, but the result is unknown.
ERR_COMMON_ERROR 2 Common error.
ERR_INVALID_TRADE_PARAMETERS 3 Invalid trade parameters.
ERR_SERVER_BUSY 4 Trade server is busy.
ERR_OLD_VERSION 5 Old version of the client terminal.
ERR_NO_CONNECTION 6 No connection with trade server.
ERR_NOT_ENOUGH_RIGHTS 7 Not enough rights.
ERR_TOO_FREQUENT_REQUESTS 8 Too frequent requests.
ERR_MALFUNCTIONAL_TRADE 9 Malfunctional trade operation.
ERR_ACCOUNT_DISABLED 64 Account disabled.
ERR_INVALID_ACCOUNT 65 Invalid account.
ERR_TRADE_TIMEOUT 128 Trade timeout.
ERR_INVALID_PRICE 129 Invalid price.
ERR_INVALID_STOPS 130 Invalid stops.
ERR_INVALID_TRADE_VOLUME 131 Invalid trade volume.
ERR_MARKET_CLOSED 132 Market is closed.
ERR_TRADE_DISABLED 133 Trade is disabled.
ERR_NOT_ENOUGH_MONEY 134 Not enough money.
ERR_PRICE_CHANGED 135 Price changed.
ERR_OFF_QUOTES 136 Off quotes.
ERR_BROKER_BUSY 137 Broker is busy.
ERR_REQUOTE 138 Requote.
ERR_ORDER_LOCKED 139 Order is locked.
ERR_LONG_POSITIONS_ONLY_ALLOWED 140 Long positions only allowed.
ERR_TOO_MANY_REQUESTS 141 Too many requests.
ERR_TRADE_MODIFY_DENIED 145 Modification denied because order too close to market.
ERR_TRADE_CONTEXT_BUSY 146 Trade context is busy.
ERR_TRADE_EXPIRATION_DENIED 147 Expirations are denied by broker.
ERR_TRADE_TOO_MANY_ORDERS 148 The amount of open and pending orders has reached the limit set by the broker.
ERR_TRADE_HEDGE_PROHIBITED 149 An attempt to open a position opposite to the existing one when hedging is disabled.
ERR_TRADE_PROHIBITED_BY_FIFO 150 An attempt to close a position contravening the FIFO rule.

MQL4 run time error codes

Constant Value Description
ERR_NO_MQLERROR 4000 No error.
ERR_WRONG_FUNCTION_POINTER 4001 Wrong function pointer.
ERR_ARRAY_INDEX_OUT_OF_RANGE 4002 Array index is out of range.
ERR_NO_MEMORY_FOR_CALL_STACK 4003 No memory for function call stack.
ERR_RECURSIVE_STACK_OVERFLOW 4004 Recursive stack overflow.
ERR_NOT_ENOUGH_STACK_FOR_PARAM 4005 Not enough stack for parameter.
ERR_NO_MEMORY_FOR_PARAM_STRING 4006 No memory for parameter string.
ERR_NO_MEMORY_FOR_TEMP_STRING 4007 No memory for temp string.
ERR_NOT_INITIALIZED_STRING 4008 Not initialized string.
ERR_NOT_INITIALIZED_ARRAYSTRING 4009 Not initialized string in array.
ERR_NO_MEMORY_FOR_ARRAYSTRING 4010 No memory for array string.
ERR_TOO_LONG_STRING 4011 Too long string.
ERR_REMAINDER_FROM_ZERO_DIVIDE 4012 Remainder from zero divide.
ERR_ZERO_DIVIDE 4013 Zero divide.
ERR_UNKNOWN_COMMAND 4014 Unknown command.
ERR_WRONG_JUMP 4015 Wrong jump (never generated error).
ERR_NOT_INITIALIZED_ARRAY 4016 Not initialized array.
ERR_DLL_CALLS_NOT_ALLOWED 4017 DLL calls are not allowed.
ERR_CANNOT_LOAD_LIBRARY 4018 Cannot load library.
ERR_CANNOT_CALL_FUNCTION 4019 Cannot call function.
ERR_EXTERNAL_CALLS_NOT_ALLOWED 4020 Expert function calls are not allowed.
ERR_NO_MEMORY_FOR_RETURNED_STR 4021 Not enough memory for temp string returned from function.
ERR_SYSTEM_BUSY 4022 System is busy (never generated error).
ERR_INVALID_FUNCTION_PARAMSCNT 4050 Invalid function parameters count.
ERR_INVALID_FUNCTION_PARAMVALUE 4051 Invalid function parameter value.
ERR_STRING_FUNCTION_INTERNAL 4052 String function internal error.
ERR_SOME_ARRAY_ERROR 4053 Some array error.
ERR_INCORRECT_SERIESARRAY_USING 4054 Incorrect series array using.
ERR_CUSTOM_INDICATOR_ERROR 4055 Custom indicator error.
ERR_INCOMPATIBLE_ARRAYS 4056 Arrays are incompatible.
ERR_GLOBAL_VARIABLES_PROCESSING 4057 Global variables processing error.
ERR_GLOBAL_VARIABLE_NOT_FOUND 4058 Global variable not found.
ERR_FUNC_NOT_ALLOWED_IN_TESTING 4059 Function is not allowed in testing mode.
ERR_FUNCTION_NOT_CONFIRMED 4060 Function is not confirmed.
ERR_SEND_MAIL_ERROR 4061 Send mail error.
ERR_STRING_PARAMETER_EXPECTED 4062 String parameter expected.
ERR_INTEGER_PARAMETER_EXPECTED 4063 Integer parameter expected.
ERR_DOUBLE_PARAMETER_EXPECTED 4064 Double parameter expected.
ERR_ARRAY_AS_PARAMETER_EXPECTED 4065 Array as parameter expected.
ERR_HISTORY_WILL_UPDATED 4066 Requested history data in updating state.
ERR_TRADE_ERROR 4067 Some error in trading function.
ERR_END_OF_FILE 4099 End of file.
ERR_SOME_FILE_ERROR 4100 Some file error.
ERR_WRONG_FILE_NAME 4101 Wrong file name.
ERR_TOO_MANY_OPENED_FILES 4102 Too many opened files.
ERR_CANNOT_OPEN_FILE 4103 Cannot open file.
ERR_INCOMPATIBLE_FILEACCESS 4104 Incompatible access to a file.
ERR_NO_ORDER_SELECTED 4105 No order selected.
ERR_UNKNOWN_SYMBOL 4106 Unknown symbol.
ERR_INVALID_PRICE_PARAM 4107 Invalid price.
ERR_INVALID_TICKET 4108 Invalid ticket.
ERR_TRADE_NOT_ALLOWED 4109 Trade is not allowed. Enable checkbox "Allow live trading" in the expert properties.
ERR_LONGS_NOT_ALLOWED 4110 Longs are not allowed. Check the expert properties.
ERR_SHORTS_NOT_ALLOWED 4111 Shorts are not allowed. Check the expert properties.
ERR_OBJECT_ALREADY_EXISTS 4200 Object exists already.
ERR_UNKNOWN_OBJECT_PROPERTY 4201 Unknown object property.
ERR_OBJECT_DOES_NOT_EXIST 4202 Object does not exist.
ERR_UNKNOWN_OBJECT_TYPE 4203 Unknown object type.
ERR_NO_OBJECT_NAME 4204 No object name.
ERR_OBJECT_COORDINATES_ERROR 4205 Object coordinates error.
ERR_NO_SPECIFIED_SUBWINDOW 4206 No specified subwindow.
ERR_SOME_OBJECT_ERROR 4207 Some error in object function.

MQL4 Standard constants(3)


Object types

Object type identifier constants used with ObjectCreate(), ObjectsDeleteAll() and ObjectType() functions. It can be any of the following values:

Objects can have 1-3 coordinates related to type.

Constant Value Description
OBJ_VLINE 0 Vertical line. Uses time part of first coordinate.
OBJ_HLINE 1 Horizontal line. Uses price part of first coordinate.
OBJ_TREND 2 Trend line. Uses 2 coordinates.
OBJ_TRENDBYANGLE 3 Trend by angle. Uses 1 coordinate. To set angle of line use ObjectSet() function.
OBJ_REGRESSION 4 Regression. Uses time parts of first two coordinates.
OBJ_CHANNEL 5 Channel. Uses 3 coordinates.
OBJ_STDDEVCHANNEL 6 Standard deviation channel. Uses time parts of first two coordinates.
OBJ_GANNLINE 7 Gann line. Uses 2 coordinate, but price part of second coordinate ignored.
OBJ_GANNFAN 8 Gann fan. Uses 2 coordinate, but price part of second coordinate ignored.
OBJ_GANNGRID 9 Gann grid. Uses 2 coordinate, but price part of second coordinate ignored.
OBJ_FIBO 10 Fibonacci retracement. Uses 2 coordinates.
OBJ_FIBOTIMES 11 Fibonacci time zones. Uses 2 coordinates.
OBJ_FIBOFAN 12 Fibonacci fan. Uses 2 coordinates.
OBJ_FIBOARC 13 Fibonacci arcs. Uses 2 coordinates.
OBJ_EXPANSION 14 Fibonacci expansions. Uses 3 coordinates.
OBJ_FIBOCHANNEL 15 Fibonacci channel. Uses 3 coordinates.
OBJ_RECTANGLE 16 Rectangle. Uses 2 coordinates.
OBJ_TRIANGLE 17 Triangle. Uses 3 coordinates.
OBJ_ELLIPSE 18 Ellipse. Uses 2 coordinates.
OBJ_PITCHFORK 19 Andrews pitchfork. Uses 3 coordinates.
OBJ_CYCLES 20 Cycles. Uses 2 coordinates.
OBJ_TEXT 21 Text. Uses 1 coordinate.
OBJ_ARROW 22 Arrows. Uses 1 coordinate.
OBJ_LABEL 23 Text label. Uses 1 coordinate in pixels.

Object properties

Object value index used with ObjectGet() and ObjectSet() functions. It can be any of the following values:

Constant Value Type Description
OBJPROP_TIME1 0 datetime Datetime value to set/get first coordinate time part.
OBJPROP_PRICE1 1 double Double value to set/get first coordinate price part.
OBJPROP_TIME2 2 datetime Datetime value to set/get second coordinate time part.
OBJPROP_PRICE2 3 double Double value to set/get second coordinate price part.
OBJPROP_TIME3 4 datetime Datetime value to set/get third coordinate time part.
OBJPROP_PRICE3 5 double Double value to set/get third coordinate price part.
OBJPROP_COLOR 6 color Color value to set/get object color.
OBJPROP_STYLE 7 int Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
OBJPROP_WIDTH 8 int Integer value to set/get object line width. Can be from 1 to 5.
OBJPROP_BACK 9 bool Boolean value to set/get background drawing flag for object.
OBJPROP_RAY 10 bool Boolean value to set/get ray flag of object.
OBJPROP_ELLIPSE 11 bool Boolean value to set/get ellipse flag for fibo arcs.
OBJPROP_SCALE 12 double Double value to set/get scale object property.
OBJPROP_ANGLE 13 double Double value to set/get angle object property in degrees.
OBJPROP_ARROWCODE 14 int Integer value or arrow enumeration to set/get arrow code object property.
OBJPROP_TIMEFRAMES 15 int Value can be one or combination (bitwise addition) of object visibility constants to set/get timeframe object property.
OBJPROP_DEVIATION 16 double Double value to set/get deviation property for Standard deviation objects.
OBJPROP_FONTSIZE 100 int Integer value to set/get font size for text objects.
OBJPROP_CORNER 101 int Integer value to set/get anchor corner property for label objects. Must be from 0-3.
OBJPROP_XDISTANCE 102 int Integer value to set/get anchor X distance object property in pixels.
OBJPROP_YDISTANCE 103 int Integer value is to set/get anchor Y distance object property in pixels.
OBJPROP_FIBOLEVELS 200 int Integer value to set/get Fibonacci object level count. Can be from 0 to 32.
OBJPROP_LEVELCOLOR 201 color Color value to set/get object level line color.
OBJPROP_LEVELSTYLE 202 int Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object level line style.
OBJPROP_LEVELWIDTH 203 int Integer value to set/get object level line width. Can be from 1 to 5.
OBJPROP_FIRSTLEVEL+n 210+n int Integer value to set/get the value of Fibonacci object level with index n. Index n can be from 0 (number of levels -1), but not larger than 31.

Object visibility

Timeframes where object may be shown. Used in ObjectSet() function to set OBJPROP_TIMEFRAMES property.

Constant Value Description
OBJ_PERIOD_M1 0x0001 Object shown is only on 1-minute charts.
OBJ_PERIOD_M5 0x0002 Object shown is only on 5-minute charts.
OBJ_PERIOD_M15 0x0004 Object shown is only on 15-minute charts.
OBJ_PERIOD_M30 0x0008 Object shown is only on 30-minute charts.
OBJ_PERIOD_H1 0x0010 Object shown is only on 1-hour charts.
OBJ_PERIOD_H4 0x0020 Object shown is only on 4-hour charts.
OBJ_PERIOD_D1 0x0040 Object shown is only on daily charts.
OBJ_PERIOD_W1 0x0080 Object shown is only on weekly charts.
OBJ_PERIOD_MN1 0x0100 Object shown is only on monthly charts.
OBJ_ALL_PERIODS 0x01FF Object shown is on all timeframes.
NULL 0 Object shown is on all timeframes.
EMPTY -1 Hidden object on all timeframes.

MQL4 Standard constants(2)


Indicator lines

Indicator line identifiers used in iMACD(), iRVI() and iStochastic() indicators.

It can be one of the following values:

Constant Value Description
MODE_MAIN 0 Base indicator line.
MODE_SIGNAL 1 Signal line.

Indicator line identifiers used in iADX() indicator.

Constant Value Description
MODE_MAIN 0 Base indicator line.
MODE_PLUSDI 1 +DI indicator line.
MODE_MINUSDI 2 -DI indicator line.

Indicator line identifiers used in iBands(), iEnvelopes(), iEnvelopesOnArray(), iFractals() and iGator() indicators.

Constant Value Description
MODE_UPPER 1 Upper line.
MODE_LOWER 2 Lower line.

Ichimoku Kinko Hyo

Ichimoku Kinko Hyo identifiers used in iIchimoku() indicator call as source of requested data.

It can be one of the following values:

Constant Value Description
MODE_TENKANSEN 1 Tenkan-sen.
MODE_KIJUNSEN 2 Kijun-sen.
MODE_SENKOUSPANA 3 Senkou Span A.
MODE_SENKOUSPANB 4 Senkou Span B.
MODE_CHINKOUSPAN 5 Chinkou Span.

Moving Average methods

Moving Average calculation method used with iAlligator(), iEnvelopes(), iEnvelopesOnArray, iForce(), iGator(), iMA(), iMAOnArray(), iStdDev(), iStdDevOnArray(), iStochastic() indicators.

It can be any of the following values:

Constant Value Description
MODE_SMA 0 Simple moving average,
MODE_EMA 1 Exponential moving average,
MODE_SMMA 2 Smoothed moving average,
MODE_LWMA 3 Linear weighted moving average.

MessageBox

The MessageBox() function return codes.

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.

Note: MessageBox return codes defined in the WinUser32.mqh file

Constant Value Description
IDOK 1 OK button was selected.
IDCANCEL 2 Cancel button was selected.
IDABORT 3 Abort button was selected.
IDRETRY 4 Retry button was selected.
IDIGNORE 5 Ignore button was selected.
IDYES 6 Yes button was selected.
IDNO 7 No button was selected.
IDTRYAGAIN 10 Try Again button was selected.
IDCONTINUE 11 Continue button was selected.

The MessageBox function flags specify the contents and behavior of the dialog box. This value can be a combination of flags from the following groups of flags.

To indicate the buttons displayed in the message box, specify one of the following values.

Constant Value Description
MB_OK 0x00000000 The message box contains one push button: OK. This is the default.
MB_OKCANCEL 0x00000001 The message box contains two push buttons: OK and Cancel.
MB_ABORTRETRYIGNORE 0x00000002 The message box contains three push buttons: Abort, Retry, and Ignore.
MB_YESNOCANCEL 0x00000003 The message box contains three push buttons: Yes, No, and Cancel.
MB_YESNO 0x00000004 The message box contains two push buttons: Yes and No.
MB_RETRYCANCEL 0x00000005 The message box contains two push buttons: Retry and Cancel.
MB_CANCELTRYCONTINUE 0x00000006 Windows 2000: The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE.

To display an icon in the message box, specify one of the following values.

Constant Value Description
MB_ICONSTOP, MB_ICONERROR, MB_ICONHAND 0x00000010 A stop-sign icon appears in the message box.
MB_ICONQUESTION 0x00000020 A question-mark icon appears in the message box.
MB_ICONEXCLAMATION, MB_ICONWARNING 0x00000030 An exclamation-point icon appears in the message box.
MB_ICONINFORMATION, MB_ICONASTERISK 0x00000040 An icon consisting of a lowercase letter i in a circle appears in the message box.

To indicate the default button, specify one of the following values.

Constant Value Description
MB_DEFBUTTON1 0x00000000 The first button is the default button. MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.
MB_DEFBUTTON2 0x00000100 The second button is the default button.
MB_DEFBUTTON3 0x00000200 The third button is the default button.
MB_DEFBUTTON4 0x00000300 The fourth button is the default button.

MessageBox() function behavior flags are defined in the WinUser32.mqh file, this is why this heading file must be included to programs through #include <WinUser32.mqh>. Not all possible flags are listed here. For more details, please refer to Win32 API description.

Wingdings

Wingdings font symbols used with Arrow objects.

  32 ! 33 " 34 # 35 $ 36 % 37 & 38 39 ( 40 ) 41 * 42 + 43 , 44 45 . 46 / 47
0 48 1 49 2 50 3 51 4 52 5 53 6 54 7 55 8 56 9 57 : 58 ; 59 < 60 = 61 > 62 ? 63
@ 64 A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72 I 73 J 74 K 75 L 76 M 77 N 78 O 79
P 80 Q 81 R 82 S 83 T 84 U 85 V 86 W 87 X 88 Y 89 Z 90 [ 91 \ 92 ] 93 ^ 94 _ 95
` 96 a 97 b 98 c 99 d 100 e 101 f 102 g 103 h 104 i 105 j 106 k 107 l 108 m 109 n 110 o 111
p 112 q 113 r 114 s 115 t 116 u 117 v 118 w 119 x 120 y 121 z 122 { 123 | 124 } 125 ~ 126  127
128  129 130 ƒ 131 132 133 134 135 ˆ 136 137 Š 138 139 Œ 140  141 Ž 142  143
 144 145 146 147 148 149 150 151 ˜ 152 153 š 154 155 œ 156  157 ž 158 Ÿ 159
  160 ¡ 161 ¢ 162 £ 163 ¤ 164 ¥ 165 ¦ 166 § 167 ¨ 168 © 169 ª 170 « 171 ¬ 172 ­ 173 ® 174 ¯ 175
° 176 ± 177 ² 178 ³ 179 ´ 180 µ 181 182 · 183 ¸ 184 ¹ 185 º 186 » 187 ¼ 188 ½ 189 ¾ 190 ¿ 191
À 192 Á 193 Â 194 Ã 195 Ä 196 Å 197 Æ 198 Ç 199 È 200 É 201 Ê 202 Ë 203 Ì 204 Í 205 Î 206 Ï 207
Ð 208 Ñ 209 Ò 210 Ó 211 Ô 212 Õ 213 Ö 214 × 215 Ø 216 Ù 217 Ú 218 Û 219 Ü 220 Ý 221 Þ 222 ß 223
à 224 á 225 â 226 ã 227 ä 228 å 229 æ 230 ç 231 è 232 é 233 ê 234 ë 235 ì 236 í 237 î 238 ï 239
ð 240 ñ 241 ò 242 ó 243 ô 244 õ 245 ö 246 ÷ 247 ø 248 ù 249 ú 250 û 251 ü 252 ý 253 þ 254 ÿ 255

Web colors

color type supported color constants.

Black DarkGreen DarkSlateGray Olive Green Teal Navy
Purple Maroon Indigo MidnightBlue DarkBlue DarkOliveGreen SaddleBrown
ForestGreen OliveDrab SeaGreen DarkGoldenrod DarkSlateBlue Sienna MediumBlue
Brown DarkTurquoise DimGray LightSeaGreen DarkViolet FireBrick MediumVioletRed
MediumSeaGreen Chocolate Crimson SteelBlue Goldenrod MediumSpringGreen LawnGreen
CadetBlue DarkOrchid YellowGreen LimeGreen OrangeRed DarkOrange Orange
Gold Yellow Chartreuse Lime SpringGreen Aqua DeepSkyBlue
Blue Magenta Red Gray SlateGray Peru BlueViolet
LightSlateGray DeepPink MediumTurquoise DodgerBlue Turquoise RoyalBlue SlateBlue
DarkKhaki IndianRed MediumOrchid GreenYellow MediumAquamarine DarkSeaGreen Tomato
RosyBrown Orchid MediumPurple PaleVioletRed Coral CornflowerBlue DarkGray
SandyBrown MediumSlateBlue Tan DarkSalmon BurlyWood HotPink Salmon
Violet LightCoral SkyBlue LightSalmon Plum Khaki LightGreen
Aquamarine Silver LightSkyBlue LightSteelBlue LightBlue PaleGreen Thistle
PowderBlue PaleGoldenrod PaleTurquoise LightGray Wheat NavajoWhite Moccasin
LightPink Gainsboro PeachPuff Pink Bisque LightGoldenrod BlanchedAlmond
LemonChiffon Beige AntiqueWhite PapayaWhip Cornsilk LightYellow LightCyan
Linen Lavender MistyRose OldLace WhiteSmoke Seashell Ivory
Honeydew AliceBlue LavenderBlush MintCream Snow White  

MQL4 Standard constants(1)

To simplify the program writing and to make program texts more convenient for perception, predefined standard constants are forseen in MQL4.

Standard constants are similar to macro substitutions and are of int type.

The constants are grouped by their purposes.

Series arrays

Series array identifier used with ArrayCopySeries(), iHighest() and iLowest() functions.

It can be any of the following values:

Constant Value Description
MODE_OPEN 0 Open price.
MODE_LOW 1 Low price.
MODE_HIGH 2 High price.
MODE_CLOSE 3 Close price.
MODE_VOLUME 4 Volume, used in iLowest() and iHighest() functions.
MODE_TIME 5 Bar open time, used in ArrayCopySeries() function.

Timeframes

Timeframe of the chart (chart period). It can be any of the following values:

Constant Value Description
PERIOD_M1 1 1 minute.
PERIOD_M5 5 5 minutes.
PERIOD_M15 15 15 minutes.
PERIOD_M30 30 30 minutes.
PERIOD_H1 60 1 hour.
PERIOD_H4 240 4 hour.
PERIOD_D1 1440 Daily.
PERIOD_W1 10080 Weekly.
PERIOD_MN1 43200 Monthly.
0 (zero) 0 Timeframe used on the chart.

Trade operations

Operation type for the OrderSend() function. It can be any of the following values:

Constant Value Description
OP_BUY 0 Buying position.
OP_SELL 1 Selling position.
OP_BUYLIMIT 2 Buy limit pending position.
OP_SELLLIMIT 3 Sell limit pending position.
OP_BUYSTOP 4 Buy stop pending position.
OP_SELLSTOP 5 Sell stop pending position.

Price constants

Applied price constants. It can be any of the following values:

Constant Value Description
PRICE_CLOSE 0 Close price.
PRICE_OPEN 1 Open price.
PRICE_HIGH 2 High price.
PRICE_LOW 3 Low price.
PRICE_MEDIAN 4 Median price, (high+low)/2.
PRICE_TYPICAL 5 Typical price, (high+low+close)/3.
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4.

MarketInfo

Market information identifiers, used with MarketInfo() function.

It can be any of the following values:

Constant Value Description
MODE_LOW 1 Low day price.
MODE_HIGH 2 High day price.
MODE_TIME 5 The last incoming tick time (last known server time).
MODE_BID 9 Last incoming bid price. For the current symbol, it is stored in the predefined variable Bid
MODE_ASK 10 Last incoming ask price. For the current symbol, it is stored in the predefined variable Ask
MODE_POINT 11 Point size in the quote currency. For the current symbol, it is stored in the predefined variable Point
MODE_DIGITS 12 Count of digits after decimal point in the symbol prices. For the current symbol, it is stored in the predefined variable Digits
MODE_SPREAD 13 Spread value in points.
MODE_STOPLEVEL 14 Stop level in points.
MODE_LOTSIZE 15 Lot size in the base currency.
MODE_TICKVALUE 16 Tick value in the deposit currency.
MODE_TICKSIZE 17 Tick size in points.
MODE_SWAPLONG 18 Swap of the long position.
MODE_SWAPSHORT 19 Swap of the short position.
MODE_STARTING 20 Market starting date (usually used for futures).
MODE_EXPIRATION 21 Market expiration date (usually used for futures).
MODE_TRADEALLOWED 22 Trade is allowed for the symbol.
MODE_MINLOT 23 Minimum permitted amount of a lot.
MODE_LOTSTEP 24 Step for changing lots.
MODE_MAXLOT 25 Maximum permitted amount of a lot.
MODE_SWAPTYPE 26 Swap calculation method. 0 – in points; 1 – in the symbol base currency; 2 – by interest; 3 – in the margin currency.
MODE_PROFITCALCMODE 27 Profit calculation mode. 0 – Forex; 1 – CFD; 2 – Futures.
MODE_MARGINCALCMODE 28 Margin calculation mode. 0 – Forex; 1 – CFD; 2 – Futures; 3 – CFD for indices.
MODE_MARGININIT 29 Initial margin requirements for 1 lot.
MODE_MARGINMAINTENANCE 30 Margin to maintain open positions calculated for 1 lot.
MODE_MARGINHEDGED 31 Hedged margin calculated for 1 lot.
MODE_MARGINREQUIRED 32 Free margin required to open 1 lot for buying.
MODE_FREEZELEVEL 33 Order freeze level in points. If the execution price lies within the range defined by the freeze level, the order cannot be modified, cancelled or closed.

Drawing styles

Drawing shape style enumeration for SetIndexStyle() function.

It can be any of the following values:

Constant Value Description
DRAW_LINE 0 Drawing line.
DRAW_SECTION 1 Drawing sections.
DRAW_HISTOGRAM 2 Drawing histogram.
DRAW_ARROW 3 Drawing arrows (symbols).
DRAW_ZIGZAG 4 Drawing sections between even and odd indicator buffers.
DRAW_NONE 12 No drawing.

Drawing style. Valid when width=1. It can be any of the following values:

Constant Value Description
STYLE_SOLID 0 The pen is solid.
STYLE_DASH 1 The pen is dashed.
STYLE_DOT 2 The pen is dotted.
STYLE_DASHDOT 3 The pen has alternating dashes and dots.
STYLE_DASHDOTDOT 4 The pen has alternating dashes and double dots.

Arrow codes

Predefined Arrow codes enumeration. Arrows code constants. It can be one of the following values:

Constant Value Description
SYMBOL_THUMBSUP 67 Thumb up symbol (C).
SYMBOL_THUMBSDOWN 68 Thumb down symbol (D).
SYMBOL_ARROWUP 241 Arrow up symbol (ñ).
SYMBOL_ARROWDOWN 242 Arrow down symbol (ò).
SYMBOL_STOPSIGN 251 Stop sign symbol (û).
SYMBOL_CHECKSIGN 252 Check sign symbol (ü).

Special Arrow codes that exactly points to price and time. It can be one of the following values:

Constant Value Description
  1 Upwards arrow with tip rightwards ().
  2 Downwards arrow with tip rightwards ().
  3 Left pointing triangle ().
  4 En Dash symbol (–).
SYMBOL_LEFTPRICE 5 Left sided price label.
SYMBOL_RIGHTPRICE 6 Right sided price label.
第 3 页,共 7 页12345...最旧 »
menu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loader