myeatrade

MQL4 Reference

MQL4 Conversion functions

A group of functions that provide conversion of data from one format into another.

The NormalizeDouble() function must be specially noted as it provides the necessary accuracy of the price presentation. In trading operations, no unnormalized prices may be used if their accuracy even a digit exceeds that required by the trade server.

 

CharToStr()

string CharToStr(int char_code)

Conversion of the symbol code into a one-character string.

Parameters:

char_code - ASCII char code.

Sample:

  string str="WORL" + CharToStr(44); // 44 is code for 'D'
  // the resulting string will be WORLD

DoubleToStr()

string DoubleToStr(double value, int digits)

Returns text string with the specified numerical value converted into a specified precision format.

Parameters:

value  - Floating point value. 
digits - Precision format, number of digits after decimal point (0-8). 

Sample:

  string value=DoubleToStr(1.28473418, 5);
  // the value is "1.28473"

NormalizeDouble()

double NormalizeDouble(double value, int digits)

Rounds the floating point value to the given precision. Returns normalized value of the double type.

The calculated StopLoss and TakeProfit values, as well as open price of pending orders must be normalized with a precision the value of which is stored in the pre-defined variable of Digits.

Parameters:

value  - Floating point value. 
digits - Precision format, number of digits after decimal point (0-8). 

Sample:

  double var1=0.123456789;
  Print(DoubleToStr(NormalizeDouble(var1,5),8));
  // output: 0.12346000

StrToDouble()

double StrToDouble(string value)

Converts string representation of number to double type (double-precision format with floating point).

Parameters:

value  - String containing the number character representation format.  

Sample:

  double var=StrToDouble("103.2812");

StrToInteger()

int StrToInteger(string value)

Converts string containing the value character representation into a value of the int (integer) type.

Parameters:

value  - String containing the number character representation format.  

Sample:

  int var1=StrToInteger("1024");

StrToTime()

datetime StrToTime(string value)

Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).

Parameters:

value  - String value of date/time format as "yyyy.mm.dd hh:mi".  

Sample:

  datetime var1;
  var1=StrToTime("2003.8.12 17:35");
  var1=StrToTime("17:35");      // returns the current date with the given time
  var1=StrToTime("2003.8.12");  // returns the date with the midnight time of "00:00"

TimeToStr()

string TimeToStr(datetime value, int mode=TIME_DATE|TIME_MINUTES)

Converts value containing time in seconds that has passed since January 1, 1970, into a string of "yyyy.mm.dd hh:mi" format.

Parameters:

value - Positive amount of seconds that have passed since 00:00, January 1, 1970. 
mode  - Optional data output mode can be one or combination of:
        TIME_DATE gets result as "yyyy.mm.dd",
        TIME_MINUTES gets result as "hh:mi",
        TIME_SECONDS gets result as "hh:mi:ss". 

Sample:

  string var1=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
This article url: http://www.myeatrade.com/438/

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