Common Functions
Function Summary Info
Displays a message box containing user-defined data. Parameters may be of any type. Number of
Alert
parameters cannot exceed 64.
Displays a comment defined by a user in the upper loft corner of a chart window. Parameters may be
Comment
of any type. Number of parameters cannot exceed 64.
GetTickCount() returns number of milliseconds passed since a system was started. The counter is
GetTickCount limited by the resolution of the system timer. Since time is stored as an unsigned integer, it is
overfilled every 49.7 days.
Returns various information about securities listed in "Market watch" window. Part of the information
MarketInfo
about the current security is stored in predefined variables (see MarketInfo() Identifiers).
MessageBox function creates and displays a message box, it is also used to manage the dialog
window. A message box contains a message and header defined ina program, as well as any
MessageBox combination of predefined icons and push buttons. If a function is executed successfully, the returned
value is one of the return code values of MessageBox(). The function cannot be called from a custom
indicator, because indicators are executed in the interface thread and may not decelerate it.
PlaySound Plays a sound file. The file must be located in the terminal_dir\sounds directory or in its subdirectory.
Prints a message to the experts log. Parameters can be of any type. Amount of passed parameters
Print
cannot exceed 64.
Sends a file to the address specified in setting window of "Publisher" tab. If the attempt fails, it retuns
FALSE. The function does not operate in the testing mode. This function cannot be called from
SendFTP custom indicators, either. The file to be sent must be stored in the terminal_directory\experts\files
folder or in its sub-folders. It will not be sent if there is no FTP address and/or access password
specified in settings.
Sends an email to the address specified in settings window of "Email" tab. The sending can be
SendMail
disabled in settings, or it can be omitted to specify the e-mail address.
The Sleep() function suspends execution of the current expert within the specified interval. Sleep()
cannot be called from custom indicators, because indicators are executed in the interface thread and
Sleep
may not decelerate it.
The checking of the expert stop flag status every 0.1 second is built into the function.
Functions for Working with Graphical Objects
Function Summary Info
Creating an object with predefined name, type and initial coordinates in the indicated chart
ObjectCreate subwindow. number of object coordinates can be from 1 to 3 depending on the object
type. In case of success the function returns TRUE, otherwise FALSE.
Deleting an object with the indicated name. In case of success the function returns TRUE,
ObjectDelete
otherwise FALSE.
The function returns the object description. It returns for objects of the OBJ_TEXT and
ObjectDescription
OBJ_LABEL types the text displayed in these objects.
The function searches for the object of the given name. The function returns the index of
ObjectFind the window, to which the searched object belongs. In case of failure, the function returns -
1.
ObjectGet The function returns the value of the given property of the object.
The function returns the description of the Fibo object level. The amount of levels
ObjectGetFiboDescription depends on the type of the object that belongs to the group of Fibo objects. The maximum
amount of levels is 32.
The functions calculates and returns the bar number (the shift relative to the current bar)
ObjectGetShiftByValue for the given price. The bar number is calculated using a linear equation for the first and
second coordinates. It is used for trend lines and similar objects.
The functions calculates and returns the price value for the given bar (the shift relative to
ObjectGetValueByShift the current bar). The price value is calculated using a linear equation for the first and
second coordinates. It is used for trend lines and similar objects.
Changing one of object coordinates on a chart. Objects can have from one to three
ObjectMove anchoring points according to the object type. In case of success, the function returns
TRUE, otherwise FALSE.
ObjectName The function returns the object name according to its order number in the list of objects.
Deleting all object of the indicated type in the indicated chart subwindow. The function
ObjectsDeleteAll
returns the number of deleted objects.
Changing properties of an indicated object. In case of success the function returns TRUE,
ObjectSet
otherwise FALSE.
The function assigns a new value to Fibonacci level. Number of levels depends on
ObjectSetFiboDescription
Fibonacci object type. Maximal number of levels is 32.
ObjectSetText Changing object description. For objects OBJ_TEXT and OBJ_LABEL this description is
displayed on a chart as a text line. In case of success the function returns TRUE,
otherwise FALSE.
ObjectsTotal Returns the total number of objects of the indicated type on a chart.
ObjectType The function returns the type of an indicated object.
String Functions
Function Short Description
It forms a string from the given parameters and returns it. The parameters can be of
StringConcatenate
any type. The number of parameters cannot exceed 64.
Substring searching. It returns the number of the position in the line the desired
StringFind
substring starts with, or -1, in case the substring is not found.
StringGetChar It returns the value of the symbol that is located at the specified position of the line.
StringLen It returns the number of symbols in the line.
It returns the copy of the line with the modified value of the symbol at the specified
StringSetChar
position.
It extracts the substring that starts at the specified position in the text line. The function
StringSubstr returns the copy of the extracted substring, if possible. Otherwise, an empty string is
returned.
The function cuts the carriage return characters, spaces and tabulation symbols from
StringTrimLeft the left part of the string. The function returns the copy of the modified string, if
possible. Otherwise, an empty string is returned.
The function cuts the carriage return characters, spaces and tabulation symbols from
StringTrimRight the right part of the string. The function returns the copy of the modified string, if
possible. Otherwise, an empty string is returned.
Data Transformation Functions
Function Summary Info
CharToStr Transformation of the symbol code into a single-symbol string.
Transformation of the numeric value into a text string that contains the symbolic
DoubleToStr
representation of the number with the specified accuracy format.
Rounding off the number with the floating point to the specified accuracy. The
NormalizeDouble calculated StopLoss, TakeProfit and also the open prcie of pending orders values must
be normalized according to the accuracy that is stored in the defined Digits variable.
Transformation of the string that contains the symbolic representation of the number
StrToDouble
into the number of "double" type (double-accuracy format with the floating point).
Transformation of the string that contains the symbolic representation into the number
StrToInteger
of the "int" type (integer).
Transformation of the string that contains time and/or date in the "yyyy.mm.dd [hh:mi]"
StrToTime format into the number of the "datetime" type (number of seconds passed since
01.01.1970).
Transformation of the value that contains the time expressed in seconds passed since
TimeToStr
01.01.1970 into the string of the "yyyy.mm.dd hh:mi" format.
Mathematical Functions
Function Summary Info
MathAbs The function returns the absolute value (in absolute magnitude) of a given number.
The function returns the arccosine value of x in the 0 to π radians range. If x is lesser than -1 or greater
MathArccos
than 1, the function returns NaN (undefined value).
The function returns arcsine value of x in the -π/2 to π/2 radians range. If x i less than -1 or greater than
MathArcsin
1, the function returns NaN (undefined value).
The function returns arctangent of x. If x is equal to 0, then the function returns 0. MathArctan returns
MathArctan
the value in the -π/2 to π/2 radians range.
MathCeil The function returns the numeric value that is the smallest integer bigger or equal to x.
MathCos The function returns the cosine of the angle.
The function returns the value of e to the power of d. At overflow, the function returns INF (infinity), and
MathExp
it returns 0 at underflow.
MathFloor The function returns the numeric value representing the largest integer that is less than or equal to x.
The function returns the natural logarithm of x if successful. If x is negative, this function returns NaN
MathLog
(undefined value). If x is 0, it returns INF (infinity).
MathMax The function returns the maximum value of two numeric values.
MathMin The function returns the minimum value of two numeric values.
The function returns the floating-point remainder of division of two numbers. The MathMod function
MathMod calculates the floating-point remainder f of x / y such that x = i * y + f , where i is an integer, f has the
same sign as x, and the absolute value of f is less than the absolute value of y.
MathPow Returns the value of the base expression raised to the specified power (exponent value).
The function returns a pseudorandom integer within the range of 0 to 32767. The MathSrand function
MathRand
must be used to seed the pseudorandom-number generator before calling MathRand.
MathRound The function returns value rounded to the nearest integer of the specified numeric value.
MathSin The function returns the sine of the specified angle.
The function returns the square root of x. If x is negative, MathSqrt returns an indefinite (same as a
MathSqrt
quiet NaN).
MathSrand The function sets the starting point for generating a series of pseudorandom integers.
MathTan returns the tangent of x. If x is greater than or equal to 263, or less than or equal to -263, a
MathTan
loss of significance in the result occurs. In this case, the function returns an indefinite value.
Functions Returning Client Terminal Information
Function Summary Info
TerminalCompany It returns the name of the company that owns the client terminal.
TerminalName It returns the name of the client terminal.
TerminalPath It returns the directory the client terminal is launched from.
Functions Detecting the Current Status of the Client Terminal Including the Environment Status of the Executed
MQL4 Program
Function Short description
The function returns the last error code, following which the value of the special last_error
GetLastError variable that contains the last error code is set to zero. So the next calling of the GetLastError
function will return 0 value.
It returns the status of the connection used for data transferring between the client terminal and
IsConnected the server. TRUE - the connection to the server is established, FALSE - there is no connection
to the server or the connection is lost.
IsDemo It returns TRUE if a program works with a demo-account. Otherwise, it returns FALSE.
IsDllsAllowed It returns TRUE if DLL calling functions are permitted for an EA. Otherwise, it returns FALSE.
It returns TRUE if the EA launching is permitted in the client terminal. Otherwise, it returns
IsExpertEnabled
FALSE.
IsLibrariesAllowed It returns TRUE if an EA is able to declare a library function. Otherwise, it returns FALSE.
IsOptimization It returns TRUE if an EA is working in the test optimizing mode. Otherwise, it returns FALSE.
It returns TRUE if a program (EA or script) received a command to exit working. Otherwise, it
IsStopped
returns FALSE.
IsTesting It returns TRUE if an EA is working in the testing mode. Otherwise, it returns FALSE.
It returns TRUE if an EA is allowed to trade and the traffic is free for trading. Otherwise, it
IsTradeAllowed
returns FALSE.
IsTradeContextBusy It returns TRUE if the traffic for trading is busy. Otherwise, it returns FALSE.
IsVisualMode It returns TRUE if an EA is tested in the visualization mode. Otherwise, it returns FALSE.
It returns the code of the reason for operation termination of an EA, a custom indicator or a
UninitializeReason script. Returned values can be one of the deinitialization codes. This function can be called in
the init() function to analyze the reasons for deinitialization of the previous launch, as well.
Functions Accessing to the Information about the Active Account
Function Short description
It returns a value of the balance of the active account (the total amount of money on the
AccountBalance
account).
AccountCredit It returns a credit value of the active account.
AccountCompany It returns the name of a brokerage company the current account is registered at.
AccountCurrency It returns the currency name of the current account.
It returns the equity value of the current account. The equity calculation depends on
AccountEquity
server settings.
AccountFreeMargin It returns the value of free margin permitted for opened orders of a current account.
It returns the value of free margin that will remain after the specified position has been
AccountFreeMarginCheck
opened on the current account.
AccountFreeMarginMode The calculation of free margin amount mode for opened orders of the current account.
AccountLeverage It returns the leverage value of the current account.
It returns the amount of margin used to maintain the open positions on the current
AccountMargin
account.
AccountName It returns the user name of the current account.
AccountNumber It returns the number of the current account.
AccountProfit It returns the profit value of the current account calculated in the base currency.
AccountServer It returns the name of the active server.
AccountStopoutLevel It returns the value of the level that is used to identify the StopOut status.
AccountStopoutMode It returns the mode of StopOut level calculation.
Trade Functions
Function Summary Info
Any trade operation (OrderSend, OrderClose, OrderCloseBy, OrderDelete or OrderModify
Execution Errors functions) can unsuccessfully end for a score of reasons and return either the negative ticket
number or FALSE. You can find out the reason of failure by using the GetLastError function.
Every error should be processed in its own way. The table below contains the general
recommendations.
It closes position. It returns TRUE, if the function has ended successfully. It returns FALSE, if
OrderClose
the function fails to end.
It closes one open position with the other that is opened in the opposite direction for the same
OrderCloseBy symbol. It returns TRUE. if the function has ended successfully. It returns FALSE, if the function
fails to end.
OrderClosePrice It returns the close price of the selected order.
OrderCloseTime It returns the time of closing for the selected order.
OrderComment It returns the comment of the selected order.
OrderCommission It returns the calculated commission value of the selected order.
It deletes the previously placed pending order. It returns TRUE, if the function has ended
OrderDelete
successfully. It returns FALSE, if the function fails to end.
OrderExpiration It returns the date of expiration of the selected pending order.
OrderLots It returns the amount of lots of the selected order.
OrderMagicNumber It returns the identifying ("magic") number of the selected order.
It modifies the parameters of the previously opened orders and pending orders. It returns TRUE
OrderModify
if the function has ended successfully. It returns FALSE, if the function fails to end.
OrderOpenPrice It returns the open price of the selected order.
OrderOpenTime It returns the opening time of the selected order.
OrderPrint It enters the order information to the journal.
It returns the net profit (without regard to swaps and commissions) of the selected order. It is the
OrderProfit
unrealized profit for the opened orders and fixed profit for the closed orders.
The function chooses the order to work with subsequently. It returns TRUE if the function has
OrderSelect
ended successfully. It returns FALSE, if the function fails to end.
The main function for opening orders and placing pending orders. It returns the number of the
OrderSend ticket that was assigned to the order by the trade server, or -1, in case of failing to end the
operation.
It returns the number of closed positions and deleted orders in the history of the current
OrdersHistoryTotal
account, loaded to the client terminal.
It returns close price of the position when it reaches the loss level (stop loss) of the currently
OrderStopLoss
selected order.
OrdersTotal It returns the total number of open and pending orders.
OrderSwap It returns the swap value of the currently selected order.
OrderSymbol It returns the symbol name for the currently selected order.
It returns the close price when it reaches the profit level (take profit) of the currently selected
OrderTakeProfit
order.
OrderTicket It returns the ticket number of the currently selected order.
OrderType It returns the operation type of the currently selected order.