Mathematical/probuilder · probacktest · proorder · proscreener

MIN

MIN in ProBuilder returns the smaller of two values or variables. Syntax, parameters and examples for capping, clamping and comparing two data series.

Syntax

probuilder
MIN(a, b)

Parameters

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

Formula

code
MIN(a, b) = a if a <= b, otherwise b

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

How it works

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

A frequent use is enforcing an upper bound, or cap. MIN(x, k) guarantees the result is never above k. Combined with MAX it clamps a value into a range: MIN(hi, MAX(lo, x)), a pattern used to keep inputs inside a valid domain.

Examples

Example 1, Smaller of two moving averages (Indicator)

probuilder
// Return whichever low-based average is lower
mmA = Average[20](low)
mmB = Average[50](low)
result = MIN(mmA, mmB)
RETURN result AS "Lower average"

MIN picks the lower of the two averages on every bar, producing a lower envelope that tracks whichever period is beneath.

Example 2, Cap a reading at a ceiling (ProScreener)

probuilder
// Limit an overheated ratio to a maximum of 2
ratio = close / Average[50](close)
capped = MIN(ratio, 2)
SCREENER[ratio > 1](capped AS "Capped ratio")

MIN(ratio, 2) prevents extreme values from dominating the scan by holding the reading at a ceiling.

Example 3, Clamp an input into a valid range (ProOrder)

probuilder
// Keep a normalized reading inside [-1, 1] before using it
raw = (close - Average[20](close)) / (2 * STD[20](close))
clamped = MIN(1, MAX(-1, raw))
IF NOT LongOnMarket AND clamped > 0.8 THEN
  BUY 1 CONTRACT AT MARKET
ENDIF

Pairing MIN with MAX clamps the reading into [-1, 1], which is the safe input range for functions like ASIN and ACOS.

Common errors and gotchas

  • Exactly two arguments. MIN compares two values only. For the lowest across a series use Lowest; for three or more values nest calls such as MIN(a, MIN(b, c)).
  • Not a running minimum. MIN(a, b) compares the current values of a and b. It does not track a trough over time. Use Lowest for a rolling low.
  • Order does not matter. MIN(a, b) and MIN(b, a) return the same result, so argument order is irrelevant.
  • MAX, returns the larger of two values, the companion of MIN.
  • ABS, absolute value, often combined with MIN to clamp distances.
  • Lowest, lowest value of a series over a lookback period.
  • Highest, highest 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.