MQL4 Reference

MQL4 Common functions (2)

General-purpose functions not included into any specialized groups.



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. 


  int start=GetTickCount();
  // some hard calculations...
  Print("Calculation time is ", GetTickCount()-start, " milliseconds.");


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.


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. 


  #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", MB_YESNO|MB_ICONQUESTION);
     if(ret==IDNO) return(false);
  // continue


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.


filename - File to be sent. 
ftp_path - FTP path. If the path has not been specified, the path described in settings will be used. 


int lasterror=0;


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.


subject   - Subject text. 
some_text - Mail body. 


  double lastclose=Close[0];
    SendMail("from your expert", "Price dropped down to "+DoubleToStr(lastclose,Digits));


bool SendNotification(string message)

Sends Push notification to mobile terminals whose MetaQuotes IDs are specified on the "Notifications" tab in options window.

Sending notifications can be disabled in the settings. The ID can also be omitted.

In case of error, the function returns false. To get information about the error, call the GetLastError() function.

Note: The SendNotification() function has strict limitations on its usage: no more than 2 calls per second and no more than 10 calls per minute. Frequency of calls is controlled dynamically, and the function can be blocked in case of violation.


message - Message text up to 255 symbols. 


  double lastclose=Close[0];
    SendNotification("Price changed "+DoubleToStr(lastclose,Digits));


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.


milliseconds   -   Sleeping interval in milliseconds.


//---- wait for 10 seconds
This article url:

Please login to post comment, if you haven't account you can register free