Momentum
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
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 20 | Rolling window size. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| values | number | null | Computed value at each bar; null before the warmup period completes |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
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.