Operators/probuilder · probacktest · proorder · proscreener

NOT

NOT in ProBuilder is the logical negation operator that inverts a boolean condition. Covers syntax, precedence and worked examples across the languages.

Syntax

probuilder
NOT (condition)

How it works

NOT takes a single boolean condition and returns its opposite. If the condition is true, NOT makes it false, and the other way round. The parentheses are not always required, but they keep the scope of the negation clear, especially when the condition itself contains comparisons.

Among the logical operators, NOT binds the tightest. That means NOT a AND b is read as (NOT a) AND b, not as NOT (a AND b). When the whole of a compound expression should be negated, wrap it: NOT (a AND b). Getting this grouping wrong is one of the most common logic bugs.

NOT works the same way in ProBuilder indicators, ProScreener, ProBacktest, and ProOrder.

Examples

Example 1, Negating a comparison (Indicator)

probuilder
// Flag a bar where the close 10 periods ahead is not above the current close
result = 0
FOR i = 0 TO 20 DO
    a = close[i + 10]
    b = close[i]
    IF NOT (a > b) THEN
        result = 1
    ENDIF
NEXT
RETURN result

This is the pattern from the official reference. NOT (a > b) is true whenever a is not greater than b, that is when a is less than or equal to b.

Example 2, Excluding a state (ProScreener)

probuilder
// Instruments in an uptrend that are not overbought
trendUp = close > Average[200](close)
overbought = RSI[14](close) > 70
cond = trendUp AND NOT overbought
SCREENER[cond]

The filter keeps instruments above their long average while NOT overbought removes those with an RSI over 70.

Example 3, Position guard on an entry (ProOrder)

probuilder
DEFPARAM CumulateOrders = false
// Enter long only when no position is open and the signal fires
IF NOT OnMarket AND close CROSSES OVER Average[50](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

NOT OnMarket is the standard guard that stops a strategy from stacking orders while a position is already open. The same pattern uses NOT LongOnMarket or NOT ShortOnMarket to guard a single side.

Common errors and gotchas

  • Precedence. NOT binds tighter than AND and OR. NOT a AND b means (NOT a) AND b. To negate the whole condition, write NOT (a AND b).
  • Negating a value, not a condition. NOT close is meaningless, because close is a number. NOT requires a boolean, so negate a comparison such as NOT (close > open).
  • Double negatives. NOT (NOT cond) is just cond. Nested negations are easy to misread, so simplify them where possible.
  • Missing parentheses on a compound term. Forgetting the brackets around a multi-part condition is the usual cause of a guard that fires at the wrong time.
  • AND, true only when every operand is true.
  • OR, true when at least one operand is true.
  • XOR, true when exactly one operand is true.
  • IF, the conditional block NOT usually sits in.
  • THEN, ELSE, structure the branches of an IF.
  • ONMARKET, LONGONMARKET, SHORTONMARKET, position states commonly negated with NOT.