# Operations and expressions

By | 11/09/2019

In order to understand what importance operations and expressions have in MQL4, no special analogies are needed. Practically, it is the same as operations and expressions in simple arithmetic. Everybody understands that in the record f = n + m, members f, n, and m are variables, signs = and + are operational signs, and n + m is an expression.In the preceding section of the book, you learned about the necessity to present data of different types. Here we will get into possible relationships between these data (square meters still cannot be added to apples). In MQL4, there are some natural limitations to the rules of using operations in expressions.

The notions of operand, operation, operation symbol, and expression

Operand is a constant, a variable, an array component, or a value returned by a function. (Functions are considered in the section on functions; arrays is considered in the section on arrays; at this present stage of learning, it is sufficient to understand operands as constants, and variables we have already studied.)

An operation is an action made upon operands.

An operation symbol is a preset character or group of characters that order to execute an operation.

An expression is a sequence of operands and operation symbols; it is a program record, the calculated value of which is characterized by a data type.

Types of operations

These are the following types of operations in MQL4:

• Arithmetical
• Assignment
• Relational
• Boolean
• Bitwise
• Comma
• Function call

Operations are used in operators (see Operators). Only in operators does their use makes sense and is realized in a program. The possibility to use an operation is determined by the properties of operators; if the operator’s properties allow you to utilize this specific operation, you can use it; otherwise, you should not use this operation. It is prohibited to use operations outside operators.

Arithmetical operations

The following symbols are arithmetical operation symbols.

 Symbol Operation Example Analog + Addition of values x + 2 – Subtraction of values or sign change x – 3, y = – y * Multiplication of values 3 * x / Quotient of division x / 5 % Residue of division minutes = time % 60 ++ Addition of 1 to the value of the variable y++ y = y + 1 – – Subtraction of 1 from the value of the variable y- – y = y – 1

Assignment operations

The following symbols are assignment operation symbols.

 Symbol Operation Example Analog = Assignment of the value x to the variable y у = x += Increase of the variable y by x у += x y = y + x -= Reduction of the variable y by x y -= x y = y – x *= Multiplication of the variable y by x y *= x y = y * x /= Division of the variable y by x y /= x y = y / x %= Residue of division of the variable y by x y %= x y = y % x

Relational operations

The following symbols are relational operation symbols.

 Symbol Operation Example == True, if x is equal to y x ==y != True, if x is not equal to y x != y < True, if x is less than y x < y > True, if x is more than y x > y <= True, if x is equal to or less than y x <= y >= True, if x is equal to or more than y x >= y

Boolean (logical) operations

The following symbols are Boolean operation symbols.

 Symbol Operation Example Explanations ! NOT (logical negation) ! х TRUE(1), if the value of the operand is FALSE(0); FALSE(0), if the value of the operand is not FALSE(0) || OR (logical disjunction) x < 5 || x > 7 TRUE(1), if any value of the values is true && AND (logical conjunction) x == 3 && y < 5 TRUE(1), if all values are true

Bitwise operations

Bitwise operations can only be performed with integers. The following operations are bitwise operations.This returns the one’s complement of the value of the variable. The value of the expression contains a 1 in all places in which the values of the variable contain a 0, and it contains a 0 in all places in which the values of the variable contain a 1.

 b = ~n;