Momentum

Windowed · default period 20Statistics

The Momentum node computes the relative price change from the start to the end of the rolling window: (last − first) / |first|. Output is a rate of return: 0.05 means 5% gain over the period; −0.03 means 3% loss. This is the direct measure of period-over-period performance — the numerator behind most momentum-based strategies. Returns null when first value is zero or window has fewer than 2 values.

Algorithm

  • vals = non-null values in window
  • momentum = (vals[last] − vals[first]) / |vals[first]|
  • Returns null when vals[first] === 0 or fewer than 2 values

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size.

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

Cross-Sectional Ranking

Compute 12-month momentum for multiple assets, rank them, and go long the top decile / short the bottom decile for a classic momentum factor strategy.

Trend Filter

Require positive momentum (Momentum > 0) as a condition before entering long positions — this is the simplest trend filter compatible with any entry system.

Mean Reversion Timing

In a mean-reversion strategy, look for extreme negative momentum (< −0.15) followed by a Sign flip to positive as an entry trigger for oversold bounces.