deviation
Mean Absolute Deviation
deviation(source, length)
Parameters
| Name | Type | Description |
|---|---|---|
source |
field | The data series to calculate deviation on |
length |
int | Number of periods for the calculation |
Formula
```
DEV = AVG(|source[i] - SMA(source, length)|) for i in [0, length-1]
Where:
- SMA(source, length) = Simple Moving Average of source
- |x| = Absolute value of x
- AVG = Average over the period window
```
Examples
dev(close, 20); # Standard 20-period deviation
dev(close, 14); # 14-period deviation
dev(close, 20) > 2.0; # High dispersion condition
x = dev(close, 20); x > dev(close, 50); # Short-term vs long-term volatility
Returns
Mean absolute deviation value (always non-negative, same units as source) ## References - TradingView: `ta.dev()` - Used internally by CCI (Commodity Channel Index) - Alternative to standard deviation using absolute differences ## Notes - Always returns non-negative values (uses absolute differences) - Higher values indicate greater dispersion/volatility - Lower values indicate tighter clustering around the mean - Used in CCI calculation with 0.015 scaling factor - Computationally simpler than standard deviation (no squaring) - Returns NULL when insufficient data (< length bars)