MQL4 Boolean Operations

Logical Negation (!)

  • **Operand Type:** Arithmetic.
  • **Result:** TRUE (1) if operand is FALSE (0); FALSE (0) if operand is non-zero.
  • **Example:** if(!a) Print("not 'a'");
  • Logical Operation OR (||)

  • **Operands:** x, y.
  • **Result:** TRUE (1) if x or y is true (non-null). FALSE (0) otherwise.
  • **Example:** if(x<0 || x>=max_bars) Print("out of range");
  • Logical Operation AND (&&)

  • **Operands:** x, y.
  • **Result:** TRUE (1) if both x and y are true (non-null). FALSE (0) otherwise.
  • Brief Estimate of Boolean Operations

  • **Mechanism:** Short-circuit evaluation. Calculation terminates when the result can be definitively determined.
  • **&& Example:** If the left operand is FALSE, the right operand is not evaluated.
  • **|| Example:** If the left operand is TRUE, the right operand is not evaluated.
  • **Code Example for Brief Estimate:**

    void OnStart() {
        // && example
        if(func_false() && func_true()) {
            Print("Operation &&: You will never see this expression");
        } else {
            Print("Operation &&: Result of the first expression is false, so the second wasn't calculated");
        }

    // || example if(!func_false() || !func_true()) { Print("Operation ||: Result of the first expression is true, so the second wasn't calculated"); } else { Print("Operation ||: You will never see this expression"); } }

    bool func_false() { Print("Function func_false()"); return(false); }

    bool func_true() { Print("Function func_true()"); return(true); }

    **See also:**

  • [Precedence Rules](/basis/operations/rules)
  • [Operations of Relation](/basis/operations/relation)
  • [Bitwise Operations](/basis/operations/bit)