Instructions/probuilder · probacktest · proorder · proscreener

ArrayMin

ArrayMin returns the smallest value stored in a ProBuilder array. Use it to extract the minimum from collected data points in indicators and strategies.

Syntax

probuilder
result = ArrayMin($MyArray)

Parameters

NameTypeDefaultDescription
$MyArrayarrayrequiredThe array variable to scan. Array names always start with $.

How it works

ArrayMin inspects the assigned elements of an array and returns the single smallest value. It is the counterpart of ArrayMax and saves the boilerplate of iterating over indices while tracking a running minimum.

The result reflects the array's full contents at the time of the call. Because ProBuilder arrays persist between bars, an array that gains an element on every bar keeps growing, and ArrayMin then covers the whole accumulated history rather than a recent window. To evaluate only recent data, overwrite a fixed range of indices each bar or clear the array with Unset before refilling it.

ArrayMin only works with numerical data. When the array is empty, the function returns an undefined value, so calls should be guarded with IsSet or a LastSet check when the population of the array is conditional.

For built-in series there are simpler alternatives: Lowest[n](series) returns the minimum of a series over the last n bars, and MIN(a, b) compares two scalars. ArrayMin is the right tool when the values were gathered manually into an array, for example filtered samples that do not map onto consecutive bars.

Examples

Example 1, Lowest of five stored prices (Indicator)

probuilder
// Store five closing prices in an array
$myPrices[1] = 130
$myPrices[2] = 135
$myPrices[3] = 128
$myPrices[4] = 140
$myPrices[5] = 132

// Extract the smallest stored value
lowestPrice = ArrayMin($myPrices)
RETURN lowestPrice

The array holds five values and ArrayMin returns 128, the smallest of them.

Example 2, Protective stop from recorded pullback lows (ProOrder)

probuilder
DEFPARAM CumulateOrders = false

// Record the low of each bar where RSI dipped below 40
IF RSI[14](close) < 40 THEN
  $pullbackLows[LastSet($pullbackLows) + 1] = low
ENDIF

// Long entry on a moving average cross, stop below the weakest recorded low
IF Average[20](close) CROSSES OVER Average[50](close) AND IsSet($pullbackLows[1]) THEN
  supportLevel = ArrayMin($pullbackLows)
  BUY 1 CONTRACT AT MARKET
  SET STOP PRICE supportLevel
ENDIF

The strategy accumulates pullback lows in an array and uses ArrayMin to place the stop under the deepest recorded low.

Example 3, New low versus a stored window (ProScreener)

probuilder
// Collect the lows of the previous 20 bars into an array
FOR i = 1 TO 20 DO
  $lows[i] = low[i]
NEXT

// Flag instruments printing a low beneath every stored value
windowMin = ArrayMin($lows)
SCREENER[low < windowMin] (close AS "Last price")

The screener stores the last 20 lows and keeps only instruments whose current low undercuts the ArrayMin of that window.

Common errors and gotchas

  • Argument must be an array. Handing ArrayMin a plain variable or a price series fails to compile. Only $-prefixed, bracket-indexed array variables are accepted.
  • Empty array returns undefined. Before any element is assigned, ArrayMin yields an undefined value that can silently corrupt downstream arithmetic. Test with IsSet or LastSet before relying on the result.
  • Non-numerical contents cause errors. The function is defined for numerical data only. Boolean flags stored as 0 and 1 are fine, but the array must contain numbers.
  • History keeps accumulating. An array appended to on every bar makes ArrayMin a lifetime minimum, not a rolling one. Reuse fixed indices or clear with Unset to get a windowed result.
  • ArrayMax, returns the largest value stored in an array.
  • ArraySort, orders array elements in ascending or descending order.
  • IsSet, tests whether a given array element has been assigned.
  • LastSet, returns the highest index assigned in an array.
  • Unset, clears an array or a single element.
  • Lowest, lowest value of a series over a fixed number of bars.
  • MIN, smaller of two scalar values.
  • BarIndex, position of the current bar in the loaded data.