• No results found

COMMON FUNCTIONS

In document MQL4_Documentation (Page 80-84)

General-purpose functions not included into any specialized groups.

ALERT

void Alert( ...)

Displays a dialog box containing the user-defined data. Parameters can be of any type. Amount of passed parameters cannot exceed 64.

Arrays cannot be passed to the Alert function. Arrays should be output elementwise. Data of double type output with 4 decimal digits after point. To output with more precision use DoubleToStr() function.

Data of bool, datetime and color types will be output as its numeric presentation. To output values of datetime type as string convert it by TimeToStr() function.

See also Comment() and Print() functions.

Parameters:

... - Any values, separated by commas. It can be up to 64 parameters.

Sample:

if(Close[0]>SignalLevel)

Alert("Close price coming ", Close[0],"!!!");

COMMENT

void Comment( ...)

The function outputs the comment defined by the user in the left top corner of the chart. Parameters can be of any type. Amount of passed parameters cannot exceed 64.

Arrays cannot be passed to the Comment() function. Arrays should be output elementwise.

Data of double type output with 4 digits after the decimal point. To output with more precision, use the DoubleToStr() function.

Data of bool, datetime and color types will be output as their numeric presentation. To output values of datetime type as strings, convert them with the TimeToStr()

function.

See also Alert() and Print() functions.

Parameters:

... - =Any values separated by commas. It can be up to 64 parameters.

Sample:

double free=AccountFreeMargin();

Comment("Account free margin is ",DoubleToStr(free,2),"\n","Current time is ",TimeToStr(TimeCurrent()));

81

GETTICKCOUNT

int GetTickCount( )

The GetTickCount() function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. Sample:

int start=GetTickCount(); // some hard calculations...

Print("Calculation time is ", GetTickCount()-start, " milliseconds.");

MARKETINFO

double MarketInfo( string symbol, int type)

Returns various data about securities listed in the Market Watch window. A part of information about the current security is stored in predefined variables.

Parameters:

symbol - Security symbol.

type - Request identifier that defines the type of information to be returned. Can

be any of values of request identifiers. Sample:

double bid =MarketInfo("EURUSD",MODE_BID); double ask =MarketInfo("EURUSD",MODE_ASK); double point =MarketInfo("EURUSD",MODE_POINT); int digits=MarketInfo("EURUSD",MODE_DIGITS); int spread=MarketInfo("EURUSD",MODE_SPREAD);

MESSAGEBOX

int MessageBox( string text=NULL, string caption=NULL, int flags=EMPTY) The MessageBox function creates, displays, and operates message box. The message box contains an application-defined message and header, as well as a random

combination of predefined icons and push buttons. If the function succeeds, the returned value is one of the MessageBox return code values.

The function cannot be called from custom indicators since they are executed within interface thread and may not decelerate it.

Parameters:

text - Optional text that contains the message to be displayed.

caption - Optional text to be displayed in the header of the dialog box. If this

parameter is NULL, the expert name will be displayed in the header.

flags - Optional flags that determine the type and behavior of the dialog box.

They can represent a conbination of flags from the following groups. Sample: #include <WinUser32.mqh> if(ObjectCreate("text_object", OBJ_TEXT, 0, D'2004.02.20 12:30', 1.0045)==false) {

int ret=MessageBox(" ObjectCreate() function returned the "+GetLastError()+" error\nContinue?", "Question",

82 if(ret==IDNO) return(false); }

// continue

PLAYSOUND

void PlaySound( string filename)

Function plays a sound file. The file must be located in the terminal_dir\sounds directory or in its subdirectory.

Parameters:

filename - Path to the sound file.

Sample:

if(IsDemo()) PlaySound("alert.wav");

PRINT

void Print( ...)

Prints a message to the experts log. Parameters can be of any type. Amount of passed parameters cannot exceed 64.

Arrays cannot be passed to the Print() function. Arrays should be printed elementwise. Data of double type are printed with 4 decimal digits after point. To output more precisely, use the DoubleToStr() function.

Data of bool, datetime and color types will be printed as their numeric presentation. To print values of datetime type as string, convert them with the TimeToStr() function.

See also Alert() and Comment() functions.

Parameters:

... - Any values separated by commas. It can be up to 64 parameters.

Sample:

Print("Account free margin is ", AccountFreeMargin()); Print("Current time is ", TimeToStr(TimeCurrent())); double pi=3.141592653589793;

Print("PI number is ", DoubleToStr(pi,8)); // Output: PI number is 3.14159265

// Array printing for(int i=0;i<10;i++) Print(Close[i]);

SENDFTP

bool SendFTP( string filename, string ftp_path=NULL)

Sends the file to the FTP server set in the Tools->Options->Publisher tab. If the attempt fails, it retuns FALSE.

The function does not operate in the testing mode. This function cannot be called from 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.

83

Parameters:

filename - File to be sent.

ftp_path - FTP path. If the path has not been specified, the path described in settings

will be used. Sample: int lasterror=0; if(!SendFTP("report.txt")) lasterror=GetLastError(); SENDMAIL

void SendMail( string subject, string some_text)

Sends a message to the e-mail set in the Tools->Options->EMail tab.

The sending can be disabled in settings, or it can be omitted to specify the e-mail address. To get the detailed error information, one has to call the GetLastError()

function. Parameters:

subject - Subject text.

some_text - Mail body.

Sample:

double lastclose=Close[0]; if(lastclose<my_signal)

SendMail("from your expert", "Price dropped down to "+DoubleToStr(lastclose,Digits));

SLEEP

void Sleep( int milliseconds)

The Sleep() function suspends execution of the current expert within the specified interval.

The Sleep() function cannot be called from custom indicators since they calculate in the interface thread and may not decelerate it.

The checking of the expert stop flag status every 0.1 second has been built into the function.

Parameters:

milliseconds - Sleeping interval in milliseconds.

Sample:

//---- wait for 10 seconds Sleep(10000);

84

In document MQL4_Documentation (Page 80-84)