Deviation (dev)
[[dev]] measures the average dispersion of a series around its simple moving average over a given window. For each candle, it first computes the SMA of the current window, then takes the average of the absolute differences between that average and each value in the window.
The dev block does not indicate market direction. A higher value means the series is moving farther away from its recent average. A lower value means the values remain more tightly grouped around that average. You can use it to measure the recent dispersion of a price or derived series, filter some market phases, or compare multiple lengths in a grid search.
Block declaration
A strategy can contain multiple [[dev]] blocks. Each block produces a numeric series representing this mean absolute deviation.
Examples
Minimal setup
This block computes dev from close with a length of 20. Because source is omitted, the block uses the default value "close".
[[dev]]
id = "dev"
length = 20Finding the optimal length
This block explores a range of values for length to identify the best-performing length.
[[dev]]
id = "dev"
length.start = 10
length.stop = 30Parameters
| 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 Required | Window used to compute the reference SMA and the mean absolute deviation; must be ≥ 1. Usage: • Fixed: length = value• Grid search: – length.start = min_value– length.stop = max_value– length.step = value (optional, default 1) |
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 [backtest] symbol.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 DEV block exposes one numeric series and its length, as well as the input source, symbol, and timeframe.
Assume the block is configured as:
[[dev]]
id = "dev"
length = 20Then:
| Variable | Description |
|---|---|
dev or dev[0]Decimal | Current mean absolute deviation value. |
dev[n]Decimal | Mean absolute deviation value from n candles ago. |
dev.lengthDecimal | Length in use. |
dev.sourceString | Input series name. |
dev.symbolString | Symbol used. |
dev.timeframeString | Timeframe used. |
Notes
- Numeric variables support arithmetic, comparisons, and logical operators.
- Text variables are strings intended for equality/inequality checks only.