MQL4 data type conversion function


This group of functions provides data conversion function from one format to another.

Pay special attention to the normalizedouble() function, which ensures the accuracy required to represent the price. In the transaction process, MT4 can not use non-standard price, even if the price has more than one decimal place, it is unacceptable to exceed the accuracy required by the transaction server.

  • CharToStr()- Convert ASCII to string
  • DoubleToStr()- Convert floating point data to string
  • NormalizeDouble()- standardized double precision numerical value
  • StrToDouble()- convert string data to floating point
  • StrToInteger()- convert string data to integer values
  • StrToTime()- conversion of string data to date time
  • TimeToStr()- date time data is converted to a string
Chartostr() – convert ASCII to string
string CharToStr(int char_ code)

This function converts ASCII code to a string.

Parameters:

char_ Code - acsii code of the character.

Example:

string str="WORL" + CharToStr(44);


//44 is the ASCII code for'd '. //The result of STR is world

Doubletostr() - Convert floating point data to string
string DoubleToStr(double value, int digits)

This function converts a double precision floating-point number to a string of specified precision (specified decimal places).

Parameters:

Value - the value to convert. Digits - accuracy requirement, number of digits after decimal point (0-8)

Example:

string value=DoubleToStr(1.28473418, 5);


//The value is "1.28473"

Normalizedouble() – normalize double precision values
double NormalizeDouble(double value, int digits)

Rounds a floating-point value to the specified precision and returns a normalized double value.

Calculation of stop loss value and profit value, order transaction, real-time transaction price requires price Standardization (that is, the decimal number of the specified price should not exceed the accuracy required by the server). This precision requirement can be obtained from the predefined digits variable.

be careful:Normalizedouble() function, which ensures the accuracy required to represent the price. In the transaction process, MT4 can not use non-standard price, even if the price has more than one decimal place, it is unacceptable to exceed the accuracy required by the transaction server

Parameters:

Value - the value to convert. Digits - accuracy requirement, number of digits after decimal point (0-8)

Example:

double var1=0.123456789;  Print(DoubleToStr(NormalizeDouble(var1,5),8));


//The output information is: 0.12346000

Strtodouble() - convert string data to floating point values
double StrToDouble(string value)

This function converts a numeric string into a double value.

Parameters:

Value - a string in numeric form.

Example:

double var=StrToDouble("103.2812");


Strtointeger() – convert string data to integer values
int StrToInteger(string value)

This function converts a numeric string to an integer value.

Parameters:

Value - a string in numeric form.

Example:

int var1=StrToInteger("1024");


Strtotime() - convert string data to date time
datetime StrToTime(string value)

This function converts a numeric string into date time data, and the input format is“ yyyy.mm.dd hh:mm"。

Parameters:

value - " yyyy.mm.dd  HH: mm ".

Example:

datetime var1;  var1=StrToTime("2003.8.12 17:35");


var1=StrToTime("17:35");


//Returns the current date and gives the specified time VAR1 = strtotime ("2003.8.12");


//The return date and time is "2003.8.12 00:00"

Timetostr() - date time data converted to string
string TimeToStr(datetime value, void mode)

This function converts datetime data (seconds since January 1, 1970) to“ yyyy.mm.dd HH: mm ".

Parameters:

Value - the number of seconds that have passed since January 1} 1 00:00, 1970. Mode - data output can be one or more of the following combinations: time_ The result format of date is "yyyy. Mm. DD", time_ Minutes result format is "HH: mm", time_ The format of seconds result is "HH: mm: SS"

Example:

string var1=TimeToStr(TimeCurrent(),TIME_ DATE|TIME_ SECONDS);


    Was this article helpful?

    1 out of 1 found this helpful