myeatrade

MQL4 Reference

MQL4 Math & Trig (2)

A set of mathematical and trigonometric functions.

 

MathMax()

double MathMax(double value1, double value2)

Returns the maximum value of two numeric values.

Parameters:

value1 - The first numeric value. 
value2 - The second numeric value. 

Sample:

  double result=MathMax(1.08,Bid);

MathMin()

double MathMin(double value1, double value2)

Returns the minimum value of two numeric values.

Parameters:

value1 - The first numeric value. 
value2 - The second numeric value. 

Sample:

  double result=MathMin(1.08,Ask);

MathMod()

double MathMod(double value, double value2)

The function returns the floating-point remainder of division of two numbers.

The MathMod function calculates the floating-point remainder f of x / y such that 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:

value  - Dividend value. 
value2 - Divisor value. 

Sample:

  double x=-10.0,y=3.0,z;
  z=MathMod(x,y);
  Print("The remainder of ",x," / ",y," is ",z);
  //Output: The remainder of -10 / 3 is -1

MathPow()

double MathPow(double base, double exponent)

Returns the value of the base expression raised to the specified power (exponent value).

Parameters:

base  - Base value. 
exponent - Exponent value. 

Sample:

  double x=2.0,y=3.0,z;
  z=MathPow(x,y);
  Printf(x," to the power of ",y," is ", z);
  //Output: 2 to the power of 3 is 8

MathRand()

int MathRand()

The MathRand function returns a pseudorandom integer within the range of 0 to 32767. The MathSrand function must be used to seed the pseudorandom-number generator before calling MathRand.

Sample:

  MathSrand(TimeLocal());
  // Display 10 numbers.
  for(int i=0;i<10;i++ )
    Print("random value ", MathRand());

MathRound()

double MathRound(double value)

Returns value rounded to the nearest integer of the specified numeric value.

Parameters:

value - Numeric value to be rounded. 

Sample:

  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

MathSin()

double MathSin(double value)

Returns the sine of the specified angle.

Parameters:

value - An angle measured in radians. 

Sample:

  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

MathSqrt()

double MathSqrt(double x)

The MathSqrt function returns the square root of x. If x is negative, MathSqrt returns an indefinite (same as a quiet NaN).

Parameters:

x - Positive numeric value. 

Sample:

  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

MathSrand()

void MathSrand(int seed)

The MathSrand() function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. MathRand retrieves the pseudorandom numbers that are generated. Calling MathRand before any call to MathSrand generates the same sequence as calling MathSrand with seed passed as 1.

Parameters:

seed - Seed for random-number generation. 

Sample:

  MathSrand(TimeLocal());
  // Display 10 numbers.
  for(int i=0;i<10;i++ )
    Print("random value ", MathRand());

MathTan()

double MathTan(double x)

MathTan returns the tangent of x. If x is greater than or equal to 263, or less than or equal to -263, a loss of significance in the result occurs, in which case the function returns an indefinite (same as a quiet NaN).

Parameters:

x - Angle in radians. 

Sample:

  double pi=3.1415926535;
  double x,y;
  x=MathTan(pi/4);
  Print("MathTan(",pi/4," = ",x);
  //Output: MathTan(0.7856)=1
This article url: http://www.myeatrade.com/448/

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