Instructions/probuilder · probacktest · proorder · proscreener

Unset

Unset clears every stored value from a ProBuilder array in one call, returning the array to an empty state so it can be refilled with fresh data later.

Syntax

probuilder
Unset($array)

Parameters

NameTypeDefaultDescription
$arrayarrayrequiredThe array variable whose contents are cleared. Array names always start with $.

How it works

Unset wipes every element of the given array at once. After the call, no index counts as assigned anymore: IsSet returns 0 for every position and LastSet returns -1, exactly as if the array had never been written to. The variable itself is not deleted, subsequent assignments repopulate it normally.

The instruction exists because arrays persist from bar to bar. Values written on earlier bars remain available on later ones, which is what makes arrays useful as accumulation buffers, but it also means stale data survives unless it is explicitly cleared. Unset is the reset switch for that persistence.

Typical patterns tie the reset to a market event or a calendar boundary: clearing a session buffer when a new trading day starts, discarding collected statistics when price breaks a key level, or emptying a scratch array at the top of a per-bar calculation before refilling it. Only the named array is affected, other arrays and plain variables keep their values.

Reading an element after Unset without reassigning it first yields the unassigned state rather than the old value, so any code consuming the array should either refill it or check IsSet before reading.

Examples

Example 1, Clearing a buffer on a breakdown (Indicator)

probuilder
// Fill the array with moving average values
FOR i = 0 TO 19 DO
  $Array1[i] = average[i](close)
NEXT

// Reset the buffer when price breaks the 20-bar low
IF close crosses under low[20] THEN
  Unset($Array1)
ENDIF
RETURN lastset($Array1) AS "filled up to index"

The array holds average values until the breakdown condition fires, at which point Unset empties it so it can be rebuilt from fresh data.

Example 2, Resetting session statistics each day (ProOrder)

probuilder
// Collect the range of every bar during the session
IF intradaybarindex = 0 THEN
  // new trading day, discard yesterday's data
  Unset($barRanges)
ENDIF
$barRanges[max(0, lastset($barRanges) + 1)] = high - low

// Trade only when today already shows expanding ranges
IF lastset($barRanges) >= 5 THEN
  IF high - low > arraymax($barRanges) * 0.9 AND NOT onmarket THEN
    BUY 1 CONTRACT AT MARKET
  ENDIF
ENDIF

SET STOP %LOSS 1

Unset runs on the first bar of each day, so the statistics array only ever describes the current session.

Example 3, Scratch array rebuilt on every bar (ProScreener)

probuilder
// Start from an empty scratch buffer on each evaluation
Unset($gains)
FOR k = 0 TO 9 DO
  IF close[k] > close[k + 1] THEN
    $gains[k] = close[k] - close[k + 1]
  ENDIF
NEXT

// Sum only the indices that were actually set
total = 0
FOR k = 0 TO 9 DO
  IF isset($gains[k]) THEN
    total = total + $gains[k]
  ENDIF
NEXT

SCREENER[total > 0] (total AS "10-bar gain sum")

Because arrays persist between bars, the leading Unset guarantees the buffer contains only values computed for the current bar.

Common errors and gotchas

  • Reading after clearing. Elements accessed after Unset are unassigned, not zero-guaranteed leftovers. Refill the array or guard reads with IsSet before consuming values.
  • Forgetting that arrays persist. Skipping Unset does not raise an error, it silently mixes old bars' data into new calculations. Buffers rebuilt per bar or per session need an explicit reset.
  • Clearing more than intended. Unset always wipes the entire array. There is no per-index form, removing a single element requires rebuilding the array without it.
  • LastSet returns -1 afterwards. Code that appends with $array[lastset($array) + 1] still works after Unset because -1 + 1 = 0, but code that reads $array[lastset($array)] without a guard indexes -1.
  • IsSet, tests whether a specific array index holds a value.
  • LastSet, returns the highest assigned index, -1 after Unset.
  • ArrayMax, largest value currently stored in an array.
  • ArrayMin, smallest value currently stored in an array.
  • ArraySort, sorts array contents in place.
  • ONCE, one-time initialization for plain variables.
  • BarIndex, current bar position, often paired with arrays as an index.