NOT
NOT in ProBuilder is the logical negation operator that inverts a boolean condition. Covers syntax, precedence and worked examples across the languages.
Syntax
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)
// 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 resultThis 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)
// 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)
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
ENDIFNOT 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.
NOTbinds tighter thanANDandOR.NOT a AND bmeans(NOT a) AND b. To negate the whole condition, writeNOT (a AND b). - Negating a value, not a condition.
NOT closeis meaningless, becausecloseis a number.NOTrequires a boolean, so negate a comparison such asNOT (close > open). - Double negatives.
NOT (NOT cond)is justcond. 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.
