Standard Deviation (stdev)
[[stdev]] measures how widely its source is dispersed around its mean over a length window. Whenever it is defined, the result is non-negative and expressed in the same unit as the source. A low value means observations remain clustered near their mean; a high value means they lie farther away.
Standard deviation does not show the direction of a move or distinguish deviations above the mean from deviations below it. The biased parameter controls whether the window is treated as the full population or as a sample.
Block declaration
A strategy can contain multiple [[stdev]] blocks. Each block outputs one numeric series representing the standard deviation value.
Examples
Minimal setup
This block computes stdev with a 20-period window. Because source and biased are omitted, the block uses the default values, namely source = "close" and biased = true.
[[stdev]]
id = "stdev"
length = 20Standard deviation on the closing price
This block computes the standard deviation of closing prices over the last 20 candles.
[[stdev]]
id = "stdev"
source = "close"
length = 20Normalized distance from a moving average
This example uses stdev to express the distance between price and a moving average in standard deviations.
The condition becomes true when the closing price moves more than 1.5 standard deviations above its moving average. The example identifies price extension phases while taking recent volatility into account.
[[ma]]
id = "baseline"
source = "close"
type = "ema"
length = 50
[[stdev]]
id = "volatility"
source = "close"
length = 50
[[condition]]
id = "price_extension"
condition = "(close - baseline) / volatility > 1.5"
next_block_id = "..."Parameters
| Parameter | Description |
|---|---|
idString Required | Unique series name. |
sourceString or Array Optional | Input series used for the calculation. Accepted forms: source = "hl2" or source = ["close", "hl2"].Each value can be either a standard price source ( open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume) or the id of another indicator.Default value: "close" |
lengthInteger or Range Required | Standard deviation window. It must be ≥ 1 when biased = true, and ≥ 2 when biased = false.Usage: • Fixed: length = value• Grid search: – length.start = min_value– length.stop = max_value– length.step = value (optional, default 1) |
biasedBoolean Optional | Chooses between population and sample standard deviation. When true, the block uses population stdev (division by ). When false, it uses sample stdev (division by ). Default is true. |
symbolString or Array Optional | Market symbol(s) used when source only consists of standard prices (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume).Symbols must include the exchange prefix in the EXCHANGE:SYMBOL format (for example "KUCOIN:BTCUSDT").If source mixes standard prices and indicator ids, symbol is applied only to combinations based on standard prices.If source contains only indicator ids, symbol is ignored.If omitted, the block inherits the symbol from [backtest].For symbol format, arrays, and alignment rules, see Exchanges, Symbols and Timeframes. |
timeframeString or Array Optional | Timeframe on which this indicator is computed. If timeframe is omitted, the computation uses the grid’s main timeframe defined in [backtest].For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes. |
Available variables
Use the identifiers below directly in your expressions. The stdev block exposes one numeric series, its parameters, and the input metadata.
Assume the block is configured as:
[[stdev]]
id = "stdev"
length = 20Then:
| Variable | Description |
|---|---|
stdev or stdev[0]Decimal | Current standard deviation value. |
stdev[n]Decimal | Standard deviation value from n candles ago. |
stdev.lengthDecimal | Window length in use. |
stdev.biasedDecimal | Bias flag in use, 1 for population standard deviation and 0 for sample standard deviation. |
stdev.sourceString | Name of the input series. |
stdev.symbolString | Symbol used (display format). |
stdev.timeframeString | Timeframe used for this block. |
Notes
- When
biased = false, the window must contain at least two values because sample standard deviation uses an divisor. - The engine skips
navalues when building the window and starts producing values only after it has collected enough valid samples.