Subtract

Element-wiseCore Math

The Subtract node computes A − B element-wise, or subtracts a constant from every element. It is fundamental for computing price differences, indicator divergence (price − MA), spread between two instruments, mean-demeaning before variance computation, and any baseline or offset removal operation in a processing pipeline.

Algorithm

  • Array − Array: output[i] = A[i] − B[i]
  • Array − Constant: output[i] = A[i] − numericB
  • Either operand null → null output

Parameters

NameTypeDefaultDescription
useNumericBbooleanfalseSubtract a constant instead of a second array.
numericBnumber0The constant to subtract 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

MA Deviation / Oscillator

Subtract a 20-period moving average from price to produce a centered oscillator showing how far price is from its mean.

MACD Histogram

Subtract the signal line from the MACD line to construct the MACD histogram — the primary entry trigger in histogram strategies.

Spread / Pair Differential

Subtract one instrument's normalized price from another to compute the spread in a pairs trading strategy.