MQL4 Book  Operators

Operators


This section deals with the rules of formatting and execution of operators used in MQL4. Each section includes simple examples that demonstrate the execution of operators. To digest the material in full, it is recommended to compile and launch for execution all exemplary programs. This will also help you to consolidate skills in working with MetaEditor.


  • Assignment Operator.
    This is the simplest and the most intuitive operator. We all know the assignment operation from school maths: The name of a variable is located to the left of the equality sign, the value to be assigned to it is to the right of the equality sign.
  • Conditional Operator "if-else".
    It is often necessary to guide the program in one or another direction regarding certain conditions. In these cases, the operator "if-else" is very helpful.
  • Cycle Operator "while".
    The processing of large one-type data arrays usually requires multiple repetitions of the same operations. You can organize a loop of such operations in the cycle operator "while". Each one execution of operations in a cycle is called iteration.
  • Cycle Operator "for".
    The operator "for" is also a cycle operator. However, unlike the operator "while", we usually specify in it the initial and the final value of a certain condition for execution of iterations.
  • Operator "break".
    If you want to interrupt the working of a cycle operator without execution of the resting iterations, you need the operator "break". It is used only in the operators "while", "for", "switch", nowhere else.
  • Operator "continue".
    One more very helpful operator - the operator of going to the next iteration within a cycle. It allows the program to skip all the resting operators in the current iteration and go to the next one.
  • Operator "switch".
    This operator is a "toggle" that allows the program to choose one of many possible alternatives. For each alternative, its predefined constant is described that is the case for this alternative.
  • Function Call.
    We understand under function call that the function to be called will execute some operations. The function may return a value of the predefined type. The amount of parameters passed into the function may not exceed 64.
  • Function Description and Operator "return".
    Before to call a user-defined function, you should describe it first. The function description is specifying its type, name and the list of parameters. Besides, the body of the function contains executable operators. The work of a function is ended in execution of the operator "return".