Mathematical/probuilder · probacktest · proorder · proscreener

MAX

MAX in ProBuilder returns the larger of two values or variables. Syntax, parameters and examples for flooring, clamping and comparing two data series.

Syntax

probuilder
MAX(a, b)

Parameters

NameTypeDescription
anumberFirst value or variable to compare.
bnumberSecond value or variable to compare.

Formula

code
MAX(a, b) = a if a >= b, otherwise b

The result equals whichever argument is larger. When the two are equal, either value is returned since they are identical.

How it works

MAX takes exactly two arguments and returns the greater. It is the two-value counterpart of Highest, which scans a single series over a lookback window. To pick the largest of three or more values, nest calls: MAX(a, MAX(b, c)).

A frequent use is enforcing a lower bound, or floor. MAX(x, 0) clamps negatives to zero, and MAX(x, k) guarantees the result is never below k. Combined with MIN it clamps a value into a range: MIN(hi, MAX(lo, x)).

Examples

Example 1, Larger of two moving averages (Indicator)

probuilder
// Return whichever high-based average is greater
mmA = Average[20](high)
mmB = Average[50](high)
result = MAX(mmA, mmB)
RETURN result AS "Upper average"

MAX picks the higher of the two averages on every bar, producing an upper envelope that tracks whichever period is on top.

Example 2, Floor a reading at zero (ProScreener)

probuilder
// Never let the momentum reading go below zero
mom = close - close[10]
floored = MAX(mom, 0)
SCREENER[floored > 0](floored AS "Positive momentum")

MAX(mom, 0) clamps negative momentum to zero, so only genuine upward moves survive as positive readings.

Example 3, Widen a stop to a minimum distance (ProOrder)

probuilder
// Use the larger of an ATR-based stop and a fixed minimum distance
atrStop = 2 * AverageTrueRange[14](close)
minStop = 15 * pointsize
stopDist = MAX(atrStop, minStop)
IF NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP LOSS stopDist
ENDIF

MAX guarantees the stop is never tighter than the fixed minimum, even when the ATR-based figure is small in a quiet market.

Common errors and gotchas

  • Exactly two arguments. MAX compares two values only. For the highest across a series use Highest; for three or more values nest calls such as MAX(a, MAX(b, c)).
  • Not a running maximum. MAX(a, b) compares the current values of a and b. It does not track a peak over time. Use Highest for a rolling high.
  • Order does not matter. MAX(a, b) and MAX(b, a) return the same result, so argument order is irrelevant.
  • MIN, returns the smaller of two values, the companion of MAX.
  • ABS, absolute value, often combined with MAX to clamp distances.
  • Highest, highest value of a series over a lookback period.
  • Lowest, lowest value of a series over a lookback period.
  • ROUND, rounds to the nearest integer or decimal.
  • SGN, sign of a value.
  • Range, high-to-low span of a bar.