Standard Deviation (STDDEV)
StratForge indicator page for rolling dispersion of the input series.
Route: /indicators/stddev/
What It Does
stratforge::StdDev computes the population standard deviation of the last period input values. Output has the same unit as the input price; it is not a percentage. The implementation calculates the window mean and population variance, then takes the square root.
Formula and worked example
StdDev = sqrt(sum((Price - mean)^2) / period)
For period = 4 and prices [2, 4, 6, 8], the mean is 5, squared deviations are [9, 1, 1, 9], and variance is 20 / 4 = 5. The output is sqrt(5) ≈ 2.236 price units. A sample standard deviation would instead divide by 3; that is not this indicator.
The output is unavailable until four bars exist. A one-bar window yields zero. The current implementation normalizes period = 0 to a one-bar window; pass a positive period to make intent clear.
Parameters
period— rolling window size; required by the constructor.
C++23 API
#include <stratforge/indicators/stddev.hpp>
auto stddev = std::make_unique<stratforge::StdDev>(data().close(), 20);
The example assumes a StratForge strategy with data() available and <memory> included. Checked implementation (revision d25404d, 2026-08-28).
Common Usage
- Use price-unit dispersion in volatility filters or bands.
- To compare assets at different price levels, normalize by a defined price baseline and handle zero explicitly.
- A larger standard deviation describes spread in this window, not future returns.
