Arithmetic Operations

Overview

MQL4 supports standard arithmetic operations for calculations.

Operators

  • **Additive:** + (addition), - (subtraction)
  • **Sign Change:** - (unary negation)
  • **Multiplicative:** * (multiplication), / (division)
  • **Modulo:** % (remainder of division)
  • **Increment:** ++ (adds 1 to variable)
  • **Decrement:** -- (subtracts 1 from variable)
  • Increment/Decrement Behavior

  • **Prefix (++i, --k):** Applied to the variable *before* it's used in an expression.
  • **Postfix (i++, k--):** Applied to the variable *after* it's used in an expression.
  • **MQL4 Implementation:** The postfix increment/decrement is applied to the variable *after* the entire expression is evaluated.

    Constraints

  • Increment and decrement operations can only be applied to variables, not constants.
  • Complex expressions involving mixed prefix/postfix operations can lead to compiler-dependent behavior and are not recommended for use.
  • Related Topics

  • [Expressions](/basis/operations/operexpression)
  • [Assignment Operations](/basis/operations/assign)
  • [Precedence Rules](/basis/operations/rules)