


#property description "We recommend to test it first on a Demo Account"ĮNTRY BUY: PSAR changes from above the previous bar to below the current barĮNTRY SELL: PSAR changes from below the previous bar to above the current barĮXIT: Take profit or trailing stop using PSARĮxtern double LotSize=0.1 //Position sizeĮxtern double StopLoss=20 //Stop loss in pipsĮxtern double TakeProfit=500 //Take profit in pipsĮxtern int Slippage=2 //Slippage in pipsĮxtern bool TradeEnabled=true //Enable tradeĮxtern double PSARMaxStep=0. #property description "DISCLAIMER: This code comes with no guarantee, you can use it at your own risk" 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. All arrays used in MQL4 can be divided into two groups: user-defined arrays (created by a programmers initiative) and arrays-timeseries (arrays with predefined names and data types). double MathMod ( double value1, double value2) The function returns the floating-point remainder of division of two numbers. #property description "This Expert Advisor opens orders when the PSAR changes from above to below the price or vice versa" It means all arrays preserve their values between calls of the function, in which the array is declared (see Types of Variables ). The latter ones will be essential in the future development of your. Now we will learn to use built-in functions and functions for working with technical indicators. From this build on, most of the functions can be applied to matrices and vectors. Math functions were originally designed to perform relevant operations on scalar values. In the first two articles we learned the fundamentals of MQL4, the basis of further development. Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5 Mathematical Functions A set of mathematical and trigonometric functions. I've checked on Excel, as expected, it normally returns the remainder zero, unlike mql4.įor an ugly workaround i use the modulus '%' operator with a function to convert price to int and back to double (% only accept int's).PSAR - (Tested with over $3,100,000 profit) This is the third article from the series 'MQL4 Language for Newbies'. If you run this test script, the result of the third price is suppose to not change (1.25500), at least in my opinion. Each 'case' variation consists of the key word 'case', a Constant, ':' (colon), and operators. The operator body contains one or several variations 'case' and one variation 'default'. The header contains the name of the operator and an Expression enclosed in parentheses. the number is an integer product of the divisor) the MathMod() doesn't return zero, it returns the divisor instead.Įxample: #property show_inputs extern double divisor = 0.0005 ĭouble price = ĭouble remainder = MathMod( price, divisor) Īlert( "price = ", DoubleToStr( price, Digits), " result = ", DoubleToStr( price - MathMod( price, divisor), Digits)) Īlert( "*****************************************************") MQL4 Reference Math Functions MathAbs MathAbs MathArccos MathArcsin MathArctan MathCeil MathCos MathExp MathFloor MathLog MathLog10 MathMax MathMin MathMod. The operator 'switch' consists of the header and the executable body. But I recently found out that if the division remainder is zero (i.e. The MathMod function calculates the real remainder f from expression val/y so that val i y + f, where i is an integer, f has the same sign as val. Return Value The largest of the two values. double MathMax( double value1, // first value double value2 // second value ) Parameters value1 in First numeric value.

I've used MathMod() function a lot on my code for rounding off prices. MathMax - Math Functions - MQL4 Reference MathMax The function returns the maximal value of two values.
