Modulo

Element-wiseCore Math

The Modulo node computes A % B element-wise (the remainder after integer division of A by B). Division by zero yields null safely. Useful for cyclic analysis such as detecting bar indices modulo a session length (e.g., every 5 bars for weekly boundaries), wrapping phase values, and building periodic masks for time-of-day filters.

Algorithm

  • Array % Array: output[i] = A[i] % B[i]
  • Array % Constant: output[i] = A[i] % numericB
  • B[i] === 0 or numericB === 0 → null (zero-safe)

Parameters

NameTypeDefaultDescription
useNumericBbooleanfalseTake modulo against a constant divisor instead of a second array.
numericBnumber1The constant modulus when useNumericB is enabled.

Inputs & Outputs

PortTypeDescription
Inputs
input1number[]Primary input array A
input2number[]Secondary input array B (ignored when useNumericB is true)
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

Session Cycle Detection

Feed a bar-index series modulo 5 to detect the position within a trading week (0=Mon, 4=Fri) for session-aware strategy rules.

Periodic Rebalancing

Use modulo on a bar counter to generate a pulse every N bars — useful for triggering periodic rebalancing or fixed-interval trade reviews.

Phase Wrapping

Wrap a cyclic phase indicator (e.g., a Hilbert transform phase) modulo 360 to keep it within [0, 360) for display or thresholding.