> *MMA is a compromise: less lag than SMA, less overshoot than fully weighted filters. It's what you get when an SMA and a WMA have a carefully engineered offspring.*
- MMA (Modified Moving Average) uses a **simple mean** as a baseline, then adds a **weighted correction** based on the position of values within the ...
MMA (Modified Moving Average) uses a **simple mean** as a baseline, then adds a **weighted correction** based on the position of values within the buffer. The weighting tilts toward newer bars without fully discarding older ones, creating a filter that sits between SMA (equal weights) and WMA (linear weights) in both lag and smoothness characteristics.
## Historical Context
MMA is not a standardized textbook indicator. It appears in multiple custom trading systems, often labeled "modified," "balanced," or "adjusted" moving average. The specific formulation here follows the PineScript reference implementation (`mma.pine`), which uses a mathematically elegant correction term based on position-weighted deviations from the mean.
The design philosophy is pragmatic: SMA is too laggy, EMA can overshoot, and WMA is computationally expensive. MMA threads the needle by adding just enough recency bias to reduce lag while maintaining the smoothness benefits of averaging.
## Architecture & Physics
MMA operates in two conceptual stages that are combined into a single efficient calculation.
### 1. SMA Baseline
The foundation is a standard simple moving average:
The effective weights emphasize recent values while still including all $N$ bars.
### Lag Analysis
- **SMA lag**: $(N-1)/2$ bars
- **MMA lag**: Approximately $(N-1)/3$ bars (varies with input characteristics)
- **Lag reduction**: ~33% compared to SMA
### Equivalence to Other Filters
MMA is closely related to the Linear Weighted Moving Average (LWMA), but with a different normalization that produces slightly different lag/smoothness characteristics.
1.**O(N) Complexity**: Unlike EMA's O(1) update, MMA requires iterating over the entire buffer each update. For large periods (N > 100), this can become a bottleneck in high-frequency applications.
2.**Warmup Requirement**: The weighted correction produces unstable results until the buffer fills completely. Use `IsHot` to detect when $N$ bars have accumulated. Early outputs will be NaN or SMA approximations.
3.**Non-finite Input Handling**: NaN/Infinity values are replaced with the last valid value to prevent corruption of the running calculations. If no valid value exists yet, output is NaN.
4.**Memory Footprint**: MMA requires storing $N$ values in a circular buffer, unlike IIR filters (EMA, RMA) which need only constant state. For many parallel MMA instances, memory usage scales with $O(N \times \text{instances})$.
5.**Comparison with WMA**: MMA is not equivalent to WMA despite both using recency weighting. The mathematical relationship differs, and direct period comparisons will produce different results.
6.**Period Selection**: Due to the correction term, MMA(N) behaves more like SMA(N×0.7) in terms of lag. When migrating from SMA, consider increasing the period to maintain similar smoothness.
7.**Bar Correction**: Use `isNew=false` when correcting the current bar. The buffer must update correctly to maintain calculation integrity.