MQL4 mathematics and trigonometric function (2)

- MathAbs()- absolute value
- MathArccos()- find inverse cosine
- MathArcsin()- find the inverse sine
- MathArctan()- find arctangent
- MathCeil()- take the smallest integer
- MathCos()- find cosine
- MathExp()- find the power of e
- MathFloor()- take the largest integer
- MathLog()- find natural logarithm
- MathMax()- Maximum
- MathMin()- Minimum
- MathMod()- modulus
- MathPow()- exponentiation
- MathRand()- get random integer
- MathRound()- rounding value
- MathSin()- find sine
- MathSqrt()- square root
- MathSrand()- random number setting
- MathTan()- tangent
double MathMax(double value1, double value2)
Returns the maximum of two values.
Parameters:
Value1 - the first value. Value2 - the second value.
Example:
double result=MathMax(1.08,Bid);
double MathMin(double value1, double value2)
Returns the smallest of two values.
Parameters:
Value1 - the first value. Value2 - the second value.
Example:
double result=MathMin(1.08,Ask);
double MathMod(double value, double value2)
This function returns the floating-point remainder of dividing two numbers.
The mathmod function calculates the floating-point remainder F of X / y, so x = I * y + F, where I is an integer, f has the same sign as X, and the absolute value of F is less than the absolute value of Y.
Parameters:
Value1 - dividend. Value2 - divisor.
Example:
double x=-10.0,y=3.0,z; z=MathMod(x,y);
Print ("remainder", x, "/", y, "is", z);
//Output data - the remainder of - 10 / 3 is - 1
double MathPow(double base, double exponent)
Returns the value of the radix to the specified power.
Parameters:
Base - cardinality. Exponent - exponential value.
Example:
double x=2.0,y=3.0,z; z=MathPow(x,y);
Printf (x, "of", y, "the power is", z);
//Output data: the third power of 2 is 8
int MathRand()
The mathrand function returns a pseudo-random integer in the range of 0 to 32767. You need to use the mathsrand() function before calling mathrand.
Example:
MathSrand(TimeLocal());
//Display 10 numbers. For (int i = 0; I < 10; I + +) print ("random number", mathrand());
double MathRound(double value)
Returns an integer rounded to the nearest specified value.
Parameters:
Value - the value to be rounded.
Example:
double y=MathRound(2.8);
Print("The round of 2.8 is ",y);
y=MathRound(2.4);
Print("The round of -2.4 is ",y);
//Output: the round of 2.8 is 3 / / the round of - 2.4 is - 2
double MathSin(double value)
Returns the sine of the specified angle.
Parameters:
Value - the angle value in radians.
Example:
double pi=3.1415926535; double x, y; x=pi/2; y=MathSin(x);
Print("MathSin(",x,") = ",y);
y=MathCos(x);
Print("MathCos(",x,") = ",y);
//Output: mathsin (1.5708) = 1 / / mathcos (1.5708) = 0
double MathSqrt(double x)
The mathsgrt function returns the square root of X. If x is negative, infinity (Nan) is returned.
Parameters:
X - the value of the square root.
Example:
double question=45.35, answer; answer=MathSqrt(question);
if(question<0) Print("Error: MathSqrt returns ",answer," answer");
else Print("The square root of ",question," is ", answer);
//Output: the square root of 45.35 is 6.73
void MathSrand(int seed)
The mathsrand() function sets a starting point for generating a set of pseudo-random integers. To reinitialize the random number generator, use 1 as the seed. With other values as seeds, the generator can be set to a random starting point. Use mathrand to retrieve the generated pseudo-random number. Before calling mathrand(), calling the mathrand function and calling the mathrand function with 1 as the seed generate the same random number.
Parameters:
Seed - seeds that generate random numbers.
Example:
MathSrand(TimeLocal());
//Display 10 random numbers. For (int i = 0; I < 10; I + +) print ("random value", mathrand());
double MathTan(double x)
Mathtan returns the tangent of X. If x is greater than or equal to 263, or X is less than or equal to - 263, the function returns infinity (Nan)
Parameters:
X - the angle value in radians.
Example:
double pi=3.1415926535; double x,y; x=MathTan(pi/4);
Print("MathTan(",pi/4," = ",x);
//Output: mathtan (0.7856) = 1