Loss
The Loss node sums the absolute magnitude of all negative first differences within the rolling window — the total downward movement expressed as a positive number. It is the directional complement to the Gain node. Dividing Gain by Loss gives the classic Relative Strength (RS) ratio used in RSI computation. Requires at least 2 non-null values.
Algorithm
- ▸Compute consecutive differences: d[i] = vals[i] − vals[i−1]
- ▸Loss = Σ |d[i]| for all d[i] < 0 (only negative changes, returned as positive)
- ▸Returns null with fewer than 2 non-null 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
RSI from Primitives
Compute Gain and Loss, divide Gain/Loss for RS, then 100 − 100/(1+RS) — this reconstructs RSI from scratch using just the Gain, Loss, Divide, and Subtract nodes.
Loss Velocity
Apply Slope to the Loss series to measure how quickly downward pressure is accelerating — a high and rising Loss with falling Gain warns of increasing bearish momentum.
Directional Stress
Compare Loss / (Gain + Loss) to see what fraction of recent movement has been downward — values above 0.6 indicate sustained selling pressure.