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
MAX(a, b)Parameters
| Name | Type | Description |
|---|---|---|
a | number | First value or variable to compare. |
b | number | Second value or variable to compare. |
Formula
MAX(a, b) = a if a >= b, otherwise bThe 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)
// 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)
// 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)
// 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
ENDIFMAX 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.
MAXcompares two values only. For the highest across a series useHighest; for three or more values nest calls such asMAX(a, MAX(b, c)). - Not a running maximum.
MAX(a, b)compares the current values ofaandb. It does not track a peak over time. UseHighestfor a rolling high. - Order does not matter.
MAX(a, b)andMAX(b, a)return the same result, so argument order is irrelevant.
Related instructions
MIN, returns the smaller of two values, the companion ofMAX.ABS, absolute value, often combined withMAXto 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.
