MQL operations - The #1 Blog on trading, personal investing! Best Tips for Beginners

Header Ads

MQL operations

With MQL following operations can be processed.
  • Arithmetical Operations
Symbol
Operation
Sample
Alternative
+
Adding
x + 2

-
Substruction or sign change
x - 3, y = - y

*
Multiplication
3 * x

/
piding
x / 5

%
Mode operation
minutes = time % 60

++
Adding 1
y++
y = y + 1
--
Substruction 1
y--
y = y - 1



  • Assignment Operations
Symbol
Operation
Sample
Alternative
=
Assigining x value to y variable
у = x

+=
Adding x value to y value and assigning it to y variable
у += x
y = y + x
-=
Minusing x value from y value and assigning it to y variable
y -= x
y = y - x
*=
Multiplication y and x and assigning result to y
y *= x
y = y * x
/=
piding y to x and assigning result to y
y /= x
y = y / x
%=
Mode y to x and assigning result to y
y %= x
y = y % x

  • Relational Operations
Symbol
Operation
Sample
==
If x equal to y than returns true
x == y
!=
If x not equal to y than returns true
x != y
<
If x less than y than returns true
x < y
>
If x greater than y than returns true
x > y
<=
If x less or equal to y than returns true
x <= y
>=
If x greater or equal to y than returns true
x >= y

  • Boolean true false operations
Symbol
Operation
Sample
Definition
!
Not
! Ñ…
If x value is true than it returns false
||
Or
x < 5 || x > 7
If one of two conditions is true than it returns true
&&
And
x == 3 && y < 5
Only if two conditions are true than it returns true

  • Bit binary operations
Complementary operation; it return the opposite value of the parameter bit.
b = ~n;

Iteration operation; it iterates bits inside x to right as amount of y, fills empty bits with 0 value.
x = x >> y;

Iteration operation; it iterates bits inside x to left as amount of y, fills empty bits with 0 value.
x = x << y;

And operations returns true only if both statement are correct.
b = ((x & y) != 0);

Or operations returns true if one of the multiple conditions is true.
b = x | y;

Exclusive or returns true if both statement have different value from each other. Otherwise if they have same value than it returns false.
b = x ^ y;


  • Comma operations
for(i=0,j=99; i<100; i++,j--) Print(array[i][j]);   // Seperates parameters in loops

My_function(Alf, Bet, Gam, Del)                     // Seperates parameters during calling function

  • Function calling operations
Functions are called from their name with their parameters. If the function returns a value, it needs to be assigned same value type variable.
Function_Name (Parameter_List)             // calling non return type function

Variable = Function_Name(Parameter_List);  // calling return type function