# Moving averages reference

> All 13 moving averages in AlgoBarsX, each with its parameters, defaults, ranges and an example: sma, ema, wma, rma, smma, hma, vwma, dema, tema, kama and 3 more.

Source: https://algobarsx.com/docs/ref-fn-moving-averages/

### `sma(source = close, length = 20)` → like source

Simple moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

**Formula** Arithmetic mean of the last length values.

**Warm-up** length bars

```algobarsx
average = sma(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `ema(source = close, length = 20)` → like source

Exponential moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

**Formula** alpha = 2 / (length + 1), seeded with the SMA of the first length values.

**Warm-up** length bars

```algobarsx
fast = ema(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `wma(source = close, length = 20)` → like source

Linearly weighted moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

**Formula** Weights length, length - 1, ..., 1 from newest to oldest.

**Warm-up** length bars

```algobarsx
weighted = wma(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `rma(source = close, length = 14)` → like source

Wilder's moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `14` | 1 to 5000 | Number of bars in the calculation. |

**Formula** alpha = 1 / length, seeded with the SMA of the first length values.

**Warm-up** length bars

```algobarsx
smoothed = rma(close, 14)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `smma(source = close, length = 14)` → like source

Smoothed moving average (identical to rma).

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `14` | 1 to 5000 | Number of bars in the calculation. |

```algobarsx
smoothed = smma(close, 14)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `hma(source = close, length = 20)` → like source

Hull moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

**Formula** wma(2 * wma(source, length / 2) - wma(source, length), round(sqrt(length)))

```algobarsx
hull = hma(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `vwma(source = close, length = 20)` → like source

Volume-weighted moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

```algobarsx
by_volume = vwma(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `dema(source = close, length = 20)` → like source

Double exponential moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

**Formula** 2 * ema - ema(ema)

```algobarsx
double = dema(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `tema(source = close, length = 20)` → like source

Triple exponential moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

**Formula** 3 * ema - 3 * ema(ema) + ema(ema(ema))

```algobarsx
triple = tema(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `kama(source = close, length = 10, fast = 2, slow = 30)` → like source

Kaufman's adaptive moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `10` | 1 to 5000 | Efficiency ratio length. |
| `fast` | int | `2` | 1 to 500 | Fastest smoothing length. |
| `slow` | int | `30` | 1 to 5000 | Slowest smoothing length. |

```algobarsx
adaptive = kama(close, 10, fast: 2, slow: 30)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `alma(source = close, length = 9, offset = 0.85, sigma = 6)` → like source

Arnaud Legoux moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `9` | 1 to 5000 | Number of bars in the calculation. |
| `offset` | number | `0.85` | 0 to 1 | Gaussian offset from 0 to 1. |
| `sigma` | number | `6` | 0.1 to 100 | Gaussian width. |

```algobarsx
smooth = alma(close, 9, offset: 0.85, sigma: 6)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `t3(source = close, length = 5, factor = 0.7)` → like source

Tillson T3 moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `5` | 1 to 5000 | Number of bars in the calculation. |
| `factor` | number | `0.7` | 0 to 1 | Volume factor. |

```algobarsx
t = t3(close, 5, factor: 0.7)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `zlema(source = close, length = 20)` → like source

Zero-lag exponential moving average.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `close` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

```algobarsx
zero_lag = zlema(close, 20)
```

Works in: strategy, indicator, alert, library. Since 1.0.
