OR
OR in ProBuilder is a logical operator that returns true when at least one of its conditions is true. Covers syntax, precedence and worked examples.
Syntax
condition1 OR condition2How it works
OR evaluates the conditions on either side and returns true if either one is true, or if both are. The result is false only when all operands are false. Adding more conditions with further OR operators widens the test, since any single match makes the whole expression true.
Precedence matters when OR shares an expression with AND and NOT. NOT binds tightest, then AND, then OR. So a OR b AND c groups as a OR (b AND c). When the intended order is not obvious at a glance, add parentheses so the logic reads exactly as meant.
OR behaves identically across ProBuilder indicators, ProScreener, ProBacktest, and ProOrder, since all four share the same boolean evaluation rules.
Examples
Example 1, Either condition in an indicator (Indicator)
// Fire when the previous close or the previous low undercut the 10-bar lowest close
i1 = Lowest[10](close)
IF (close[1] < i1 OR low[1] < i1) THEN
result = 1
ELSE
result = 0
ENDIF
RETURN resultThis is the pattern from the official reference. Either the previous close or the previous low being below the lowest close of the last 10 periods sets result to 1, because only one side of the OR needs to be true.
Example 2, Any of several breakouts (ProScreener)
// New 20-bar high on close or on high
newCloseHigh = close >= Highest[20](close)
newHigh = high >= Highest[20](high)
cond = newCloseHigh OR newHigh
SCREENER[cond]The screener returns instruments that print a fresh 20-bar high on either measure. A match on either condition is enough.
Example 3, Exit on more than one trigger (ProOrder)
DEFPARAM CumulateOrders = false
// Exit the long if price loses the average or momentum turns down
lostTrend = close < Average[50](close)
momentumDown = MACDLine[12,26,9](close) CROSSES UNDER 0
IF LongOnMarket AND (lostTrend OR momentumDown) THEN
SELL AT MARKET
ENDIFThe parentheses group the two exit triggers so that either one, combined with an open long, closes the position. Without them the precedence rules would change the meaning.
Common errors and gotchas
- Precedence surprises.
a AND b OR cparses as(a AND b) OR c. If a single exit should fire on any of several triggers, group them with parentheses as in Example 3. - Each side must be a condition.
close OR high > lowis invalid, becauseclosealone is a value. Write a full comparison on each side. - Widening past the point of usefulness. Every added
ORcondition can only increase the number of matches. A screener returning almost everything often has one loose condition too many. - OR is not exclusive. If exactly one of two conditions should be true and not both, use
XORinstead.
