资源预览内容
第1页 / 共67页
第2页 / 共67页
第3页 / 共67页
第4页 / 共67页
第5页 / 共67页
第6页 / 共67页
第7页 / 共67页
第8页 / 共67页
第9页 / 共67页
第10页 / 共67页
亲,该文档总共67页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
MQL4 Language for Newbies. Technical Indicators and Built-In Functions ru IntroductionThis is the third article from the series MQL4 Language for Newbies. In the first two articles we learned the fundamentals of MQL4, the basis of further development. Now we will learn to use built-in functions and functions for working with technical indicators. The latter ones will be essential in the future development of your Expert Advisors and indicators. Besides we will see on a simple example, how we can trace trading signals for entering the market, for you to understand, how to use indicators correctly. And at the end of the article you will learn something new and interesting about the language itself. Mathematical FunctionsLet us start with the most simple, but still used and helpful mathematic functions. MathAbsFunction Prototype:double MathAbs(double value)It is a very simple function, which returns the absolute value (number module). It means, if you, for example, use it for a negative number, as a result you will get a positive number.Example of its usage:int a=-10;double b=-20.0;double c=7.0; a=MathAbs(a); / now a is equal to 10b=MathAbs(b); / now b is equal to 20.0c=MathAbs(c); / the value of c will not change, for it was positiveMathCeil, MathFloor and MathRoundFunctions prototypes:double MathCeil(double x)double MathFloor(double x)double MathRound(double value)These three functions are very much alike: all they round off a number to the whole number. But each of them has its own peculiarity:MathCeil rounds up in such a way, that even if we have one thousandth of a whole number (for example, 1.001), it is considered a whole number. I.e. a number is rounded up to a higher value. For example:double a;a=MathCeil(1.001); / a=2.0, even one thousandth is rounded off to a whole numbera=MathCeil(1.999); / a=2.0a=MathCeil(-1.001); / a=-1.0, it is correct, because -1.0 is more than -1.001a=MathCeil(-1.999); / a=-1.0, it is correct, -1.0 is more than -1.999MathFloor makes the same, as MathCeil, but quite opposite. I.e. if we need to round down a positive number, it will simply lose a fractional part:double a;a=MathFloor(1.999); / a=1.0, no matter how large the fractional part is, it will be taken awaya=MathFloor(1.001); / a=1.0a=MathFloor(-1.001); / a=-2.0, correct, because -2.0 is less than -1.001a=MathFloor(-1.999); / a=-2.0, correct, -2.0 is less than -1.999MathRound rounds off numbers in a familiar to us way. I.e. if a fractional part is large (0.5 and more), it will be rounded off to 1. If the fractional part is small (less than 0.5), it will be rounded off to 0, i.e. it will be simply omitted. Examples:double a;a=MathRound(1.1); / a=1.0, the fractional part is too small (0.1)a=MathRound(1.57); / a=2.0, the fractional part is enough to be rounded off to 1a=MathRound(-3.1); / a=-3.0 not enougha=MathRound(-6.99); / a=-7.0 enoughMathMaxMathMinFunctions prototypes:double MathMax(double value1, double value2)double MathMin(double value1, double value2)These two functions are very much alike. They accept 2 arguments and return accordingly the largest and the smallest one. Examples:double a;a=MathMax(50.0,1.0); / a=50.0a=MathMin(10.0,12.0); / a=10.0MathPowFunction prototype:double MathPow(double base, double exponent)This function allows raising a number base to the power exponent. Examples:double a;a=MathPow(5.0,2.0); / a=25.0, 5 to the power 2a=MathPow(2.0,8.0); / a=256.0, 2 to the power 8a=MathPow(25.0,0.5); / a=5.0, you know, a number to the power 0.5 is its square rootMathSqrtFunction prototype:double MathSqrt(double x)Take the square root using this function. But do not try to take the square root of a negative number. In this case a zero will be returned. Examples:double a;a=MathSqrt(9.0); / a=3.0a=MathSqrt(25.0); / a=5.0a=MathSqrt(-256.0); / a=0.0, I explainedMathLogFunction prototype:double MathLog(double x)Does anyone remember, what a logarithm is? Logarithm of a to the base b is equal to the power, to which you need to raise b, to get a. Widely used are logarithms to the bases e (Euler number) - natural logarithms (lna) and to the base 10 - common (Briggs) logarithm (lg a). The more information about logarithms can be found at: http:/en.wikipedia.org/wiki/LogarithmSo, the function MathLog is intended for taking natural logarithm of the number x. Do not try to take natural logarithm of negative numbers or zero. In this case you will get -1. Examples of using the function:double a;a=MathLog(10.0); / a=2.30258509a=MathLog(0.0); / a=-1.0, incorrecta=MathLog(-10.0); / a=-1.0, incorrectMathExpFunction prototype:double MathExp(double d)This function returns number e, raised to the power d. Many of you must have forgotten this number. e is a mathematical constant, base of natural logarit
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号