MQL4 Precedence Rules

Overview

Precedence rules define the grouping of operations and operands in MQL4 expressions, determining the order of execution. Higher priority operation groups are evaluated before lower priority groups. Parentheses can be used to explicitly control the order of operations.

Current MQL4 Version Precedence

| Priority Group | Operations | Description | |---|---|---| | Highest | () [] . | Function Call, Array Element Reference, Structure Element Reference | | | ! ~ - ++ -- (type) sizeof | Logical Negation, Bitwise Negation, Sign Change, Increment, Decrement, Type Casting, Size in Bytes | | | * / % | Multiplication, Division, Module Division | | | + - | Addition, Subtraction | | | << >> | Left Shift, Right Shift | | | < <= > >= | Less Than, Less Than or Equal, Greater Than, Greater Than or Equal | | | == != | Equal, Not Equal | | | & | Bitwise AND | | | ^ | Bitwise Exclusive OR | | | | | Bitwise OR | | | && | Logical AND | | | || | Logical OR | | | ?: | Conditional Operator | | | = *= /= %= += -= <<= >>= &= ^= |= | Assignment Operators (various forms) | | Lowest | , | Comma Operator |

**Execution Order within groups:**

  • Left to Right: () [] ., * / %, + -, << >>, < <= > >=, == !=, &, ^, |, &&, ||, ,
  • Right to Left: ! ~ - ++ -- (type) sizeof, ?:, Assignment Operators
  • Old MQL4 Version Precedence (for reference)

    | Priority Group | Operations | Description | |---|---|---| | Highest | () [] | Function Call, Array Element Reference | | | ! - ++ -- ~ | Logical Negation, Sign Change, Increment, Decrement, Bitwise Negation | | | & ^ << >> | Bitwise AND, Bitwise Exclusive OR, Left Shift, Right Shift | | | * / % | Multiplication, Division, Module Division | | | + - | Addition, Subtraction | | | < <= > >= == != | Comparison Operators | | | || | Logical OR | | | && | Logical AND | | | = += -= *= /= %= >>= <<= &= |= ^= | Assignment Operators | | Lowest | , | Comma Operator |

    **Execution Order within groups (Old MQL4):**

  • Left to Right: () [], & ^ << >>, * / %, + -, < <= > >= == !=, ||, &&, ,
  • Right to Left: ! - ++ -- ~, Assignment Operators
  • **Note:** Priority in old MQL4 differs from C++ in some aspects.