Math¶
Combine and transform series — arithmetic, comparisons, logic and helpers.
- % Change — Per-bar percentage change — (current − N bars ago) ÷ (N bars ago). Output is a fraction (e.g. 0.01 = +1%), NOT a percent. Multiply by 100 if you want percent units. First N bars emit NaN; division-by-zero (prior value was 0) emits NaN.
- Add — Add two series element-wise. Either input may be price BARS (uses close) or any SERIES. Useful for offsets and combining indicators ('EMA + ATR×N', 'high + buffer', etc.).
- Cumulative Sum — Running total of a series — at bar i, the sum of values from bar 0 through bar i. Useful for cumulative volume, P&L curves built from per-bar deltas, or any 'so far' metric.
- Diff — Discrete difference — current value minus the value N bars ago. The bar-level analogue of a derivative; first N bars emit NaN. Useful for momentum, slope-of-anything, change-rate.
- Divide — Divide A by B element-wise. Useful for ratios ('close / sma', 'short EMA / long EMA'). Divide-by-zero produces NaN (engine treats as 'no value').
- Lag — Shift a series back by N bars — at bar i, emits the value from bar (i − N). Useful for 'price now vs price N bars ago' comparisons. First N bars emit NaN (no value to look back to).
- Min-Max Normalize — Rolling min-max rescale to [0, 1]: (value − rolling min) ÷ (rolling max − rolling min). 0 = at the window's bottom, 1 = at the top. Constant windows (zero range) emit NaN. Useful for combining heterogeneous indicators on a common 0–1 scale.
- Multiply — Multiply two series element-wise. Useful for scaling one series by another ('ATR × multiplier', 'volume × close').
- Rolling Max — Highest value in the trailing N bars.
- Rolling Median — Median of the trailing N bars — the outlier-resistant cousin of a rolling mean. Useful when one bad print would skew an SMA.
- Rolling Min — Lowest value in the trailing N bars.
- Rolling Percentile — Pth-percentile value within the trailing N bars. With percentile=50 acts as median; 75 reads the upper-quartile value; 95 surfaces near-extreme thresholds.
- Rolling Range — Spread between rolling max and rolling min — a simple proxy for volatility / regime expansion.
- Scalar Math — Combine a series with a fixed numeric value: add, subtract, multiply, or divide every bar by the same constant. Cheaper than Constant + BinaryOp when the second operand is genuinely fixed (offsets, unit conversions, scaling).
- Standardize — Rolling z-score: (value − rolling mean) ÷ rolling stddev. Output expresses each bar as 'how many standard deviations from the local mean it sits' — comparable across instruments and indicators. Constant windows (zero stddev) emit NaN.
- Subtract — Subtract B from A element-wise. Useful for spreads ('close − sma'), differences, and pair-trading constructions.
- Unary Math — Apply a single-input transformation: absolute value, sign, negate, square root, natural log, exponential, or reciprocal (1/x). Domain failures (sqrt of negative, log of non-positive, 1/0) emit NaN.