Standard deviation

How the standard deviation measures how spread out the last N prices are around their mean, with the deviation of a sample, and how to use it in a QTSurfer strategy.

The standard deviation measures how spread out the last N prices are around their mean. It is in the units of the price, and it is what the Bollinger bands are made of.

Try it on a series below and change the period.

The series are samples, synthetic ones and real crypto ones. They show how the indicator behaves, not what it earns. The line is computed in your browser by the engine’s own indicator class, so it is the line a strategy reads.

What it computes

s = √( Σ (price − mean)² / (N − 1) )        over the last N prices

The engine divides by N − 1, the deviation of a sample, and not by N. It reports it ready after N updates, and the chart draws from there. A price that does not move reads 0.

Reading it

  • It measures the spread of the prices in the window, not of their changes. A steady climb raises it as much as a noisy range does. For the size of the changes use the ATR or the percent volatility.
  • It is in price units, so a value is large or small next to the price.

In a strategy

setup:
  stdDev(20)

stdDev(20) registers stdDev20. Like the averages it can read another indicator, stdDev("name", "other", 20). In Java, .stdDev(5) on the builder.

The period is a parameter, so a parameter sweep can explore it, and walk-forward analysis tells you whether what it found holds outside the sample, which is the defence against overfitting.