Skip to main content

Module helpers

Module helpers 

Source
Expand description

Calculations on scalar series for built-in and host-defined studies.

Outputs retain the input length. Missing results are NaN; lengths of zero are treated as one, except change, where zero means no change. Complete-window calculations require finite inputs throughout the window. Recursive averages skip non-finite inputs, emitting NaN there and retaining their previous state.

Functions§

change
Difference from period bars ago. Unavailable or non-finite endpoints yield NaN.
crossover
True where a moves from below b to above it. Equal values retain the last unequal comparison, so a touch and return does not cross. Missing values break comparisons. Output has a.len() entries; missing b entries are gaps.
crossunder
True where a moves from above b to below it; otherwise as crossover.
ema
Exponential average with alpha 2 / (period + 1), seeded by the first finite value.
ema_sma
Exponential average with alpha 2 / (period + 1), seeded by the mean of the first period finite values. Useful for nested averages with a full warm-up.
highest
Highest value in the trailing window, including partial warm-up windows. NaN never wins; an all-NaN window yields negative infinity, as f64::max does.
lowest
Lowest value in the trailing window, including partial warm-up windows. NaN never wins; an all-NaN window yields positive infinity, as f64::min does.
rma
Wilder’s average with alpha 1 / period, seeded by the mean of the first period finite values.
sma
Arithmetic mean of each complete trailing window.
stdev
Population standard deviation of each complete window, with divisor period.
sum
Sum of each complete trailing window, recovering after missing inputs leave it.
wma
Linear weighted mean of each complete window, weights 1..=period, newest heaviest.