Clamp

Element-wiseCore Math

The Clamp node constrains each value to the closed interval [min, max]. Values below min are raised to min; values above max are capped at max; values already within range pass through unchanged. It is essential for bounding normalized oscillators, preventing indicator overflow into invalid ranges, and enforcing hard risk limits on signals feeding into downstream position-sizing nodes.

Algorithm

  • output[i] = Math.min(Math.max(input[i], min), max)
  • Requires min < max, otherwise the node errors
  • null inputs → null output

Parameters

NameTypeDefaultDescription
minnumber0Lower bound. Output will never be less than this.
maxnumber1Upper bound. Output will never exceed this.

Inputs & Outputs

PortTypeDescription
Inputs
inputnumber[]Source numeric array
Outputs
valuesnumber | nullComputed value at each bar; null before the warmup period completes
timestampsnumber[]Bar timestamps (UNIX ms), aligned 1-to-1 with values
Live mode: In live streaming mode the node updates only the last bar in-place rather than recalculating the full array, keeping CPU usage minimal during real-time data feeds.

Use Cases

Oscillator Bounding

After custom normalization, clamp to [0, 100] to prevent edge-case outputs from exceeding oscillator display bounds.

Signal Capping

Clamp a position-size multiplier to [0.1, 3.0] to enforce minimum and maximum exposure regardless of strategy output.

Confidence Guard

Clamp a raw confidence or scoring series to [0, 1] before feeding it into a threshold comparator node.