Moving average (MA)
Summary
Generic moving-average dispatcher that forwards the job to the MA implementation selected by optInMAType. Single uniform interface over all TA-Lib moving averages.
Formula
outReal = MA_of_type(optInMAType)(inReal, optInTimePeriod); default type = SMA
Notes
- A period of 1 performs no smoothing for every MAType: the output is a copy of the input.
TA_MAType_DISABLEDbypasses smoothing explicitly, for any period: the output is a copy of the input with a lookback of 0. Every function that takes an MAType parameter accepts it.TA_MAType_DEFAULTselects the documented default of the parameter it is passed to — SMA here, EMA for APO, PPO and PVO. Every function that takes an MAType parameter accepts it.
Inputs
inReal— Series to average
Outputs
outReal— Selected moving average of the input
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 30 | 1–100000 | Averaging window length |
optInMAType | MAType | SMA (0) | any MAType | Which moving-average algorithm to dispatch to |
MAType values: 0 SMA · 1 EMA · 2 WMA · 3 DEMA · 4 TEMA · 5 TRIMA · 6 KAMA · 7 MAMA · 8 T3 · 9 HMA · 10 DISABLED · 11 DEFAULT
Properties
Numerical Stability: Depends on MA Type — This function's default, SMA, is start-independent.
| ✅ Overlap Input i |
| ☐ Independent Y-Axis |
| ☐ Candlestick |
| ☐ Can Output NaN or ±Inf |
| ✅ Identity at Period 1 i |
Implementation
TA-Lib Definition: ma.c · ma.yaml
| Native | File |
|---|---|
| C | ta_MA.c |
| Rust | ma.rs |
| Java | Core_MA.java |
TA-Lib is also available for Python, R and more using a wrapper.
Aliases
Moving Average, MovingAverage
See Also
SMA · EMA · WMA · DEMA · TEMA · TRIMA · KAMA · MAMA · T3 · HMA