MT4新手编程资料

上传人:cn****1 文档编号:498307005 上传时间:2023-07-31 格式:DOC 页数:67 大小:896KB
返回 下载 相关 举报
MT4新手编程资料_第1页
第1页 / 共67页
MT4新手编程资料_第2页
第2页 / 共67页
MT4新手编程资料_第3页
第3页 / 共67页
MT4新手编程资料_第4页
第4页 / 共67页
MT4新手编程资料_第5页
第5页 / 共67页
点击查看更多>>
资源描述

《MT4新手编程资料》由会员分享,可在线阅读,更多相关《MT4新手编程资料(67页珍藏版)》请在金锄头文库上搜索。

1、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

2、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 correct

3、ly. 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, whic

4、h 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); /

5、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 i

6、ts 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 wh

7、ole 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 si

8、mply 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.999MathRo

9、und 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 pa

10、rt 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)The

11、se 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 num

12、ber 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

13、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, w

14、hat 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 foun

15、d 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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号