Quote:
|
Originally Posted by newdigital
I saw in the code of some EA this line:
#include <stdlib.mqh>
What is stdlib.mqh file?
Why we need to use it?
What is inside this file and how to check it?
Which functions?
Is it possible ti write our own library file with most usable pieces of the code?
Where to get custom library file?
May be somebody wrote it already ...
|
Hi newdigital,
At the beginning I’d like to explain to you the main idea behind my previous nine lessons. I wanted to present the programming in MQL4 in a simple way and without entering in a lot of minutiae which will distribute the reader’s concentration.
Now, let me answer your questions.
The file
"stdlib.mqh" is a one of
mqh files. And those kinds of files contain frequently used functions and variables or it contains the declarations of the functions of a
library file.
Our file
stdlib.mqh contains the declarations of the library file
stdlib.mq4.
Those kinds of files used in your code when you use the include directive which tells the compiler to open the file and paste its content in your code. It’s very like manual opening of the file, copying its content then pasting it in your code.
If you have any code which you use it frequently you can put it in those files and you will have not to write it every time you want to use.
It’s very like the very popular .h
header files used in c++ programming language.
Now, I’ll give you a full description of the content of the file
stdlib.mqh.
You can find this file in you
MetaTrader 4\experts\include path and if you double-clicked it you will see its content in MetaEditor.
You will find five functions declarations included in the stdlib.mqh and I’ll give you more details about each of them.
string ErrorDescription(int error_code);
This function takes an integer value and returns string value.
Its job is taking the error number and returns the string description of the error. For example:
ErrorDescription(65) will return the description
Invalid account.
ErrorDescription(134) will return the description
Not enough money.
You could ask me, and how can I get the error number?
You get the error number by using the function
GetLastError, which will return an integer value, with the last error has occurred while the execution of you program.
int RGB(int red_value,int green_value,int blue_value);
This function takes three integer values and returns an integer value.
The three inputs are the values of red, green and blue of the color and its job to return the integer-valued representation of the color. For example:
RGB(255,255,255) will return
16777215 which is the integer-value of the
White color.
bool CompareDoubles(double number1,double number2);
This function takes two doubles values and returns a Boolean value.
Its job is comparing the two double entries (from right to left), and return the result of the comparison. For example:
CompareDoubles(2.0,2.01) will return
false
CompareDoubles(2.0,2.0) will return
true.
string DoubleToStrMorePrecision(double number,int precision);
This function takes a double value and an integer value and returns a string value. Its job is returning a string contains the representation of the double number you entered as a first parameter with the number of the precisions you entered in the second parameter (up to 16 digits after decimal point).
For example:
DoubleToStrMorePrecision(2,10) will return
“2.0000000000”
DoubleToStrMorePrecision(2.1234567890,5) will return
“2.12346”
string IntegerToHexString(int integer_number);
This function takes one value of integer type and returns as string value.
Its job is converting the entered integer to a string contains the hexadecimal notation representation of the entered integer. For example:
IntegerToHexString(16777215) will return
“00FFFFFF”
I hope I gave you a good description in this topic.
If you have any further questions in this topic I’ll be happy.