# MESA Adaptive Moving Average (MAMA)

`D07-F01-A09` · Technical Indicators → Trend Smoothing · archetype `series-transform` · difficulty 5/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/technical-indicators/trend-smoothing/mama/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { mama } from "fintech-algorithms/technical-indicators/trend-smoothing/mama";
```

## Signature

```ts
mama(values, fastLimit, slowLimit)
```

MESA adaptive moving average. A Hilbert transform estimates the dominant cycle period of the series, and the smoothing rate follows the rate of phase change — so the average adapts to cycle length rather than to a fixed window.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `values` | `(number \| null)[]` | yes | Observation series in chronological order, oldest first. · nulls: propagate |
| `fastLimit` | `number` | no | Upper bound on the adaptive smoothing factor. · min: 0, max: 1 · default: 0.5 |
| `slowLimit` | `number` | no | Lower bound on the adaptive smoothing factor. · min: 0, max: 1 · default: 0.05 |

## Returns

`Record<string, (number | null)[]>` · length same-as-input

Every stage of the transform as a parallel series — `smooth`, `detrender`, the in-phase and quadrature components, `period`, `phase`, `mama` and `fama` — because the intermediate values are the only way to diagnose a suspicious result.

## Warm-up

The first `6` positions are `null`. The Hilbert transform needs six bars of history before its output is meaningful.

## Errors

- When fastLimit or slowLimit falls outside 0…1, or slowLimit > fastLimit — throws RangeError

## Complexity

Time `O(n)`, space `O(n)`.

## Worked example

Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

### Input

`values`:

```json
[100, 100.517638, 101, 101.414214, 101.732051, 101.931852]
```

Showing 6 of 144 elements.

### Call

```ts
mama(values, fastLimit, slowLimit)
```

### Returns

object with 14 fields: smooth, detrender, i1, q1, i2, q2, re, im, …

```json
{
  "smooth": [null, null, null, 100.96921320000001, 101.3688484, 101.67519890000001],
  "detrender": [null, null, null, null, null, null],
  "i1": [null, null, null, null, null, null],
  "q1": [null, null, null, null, null, null],
  "i2": [null, null, null, null, null, null],
  "q2": [null, null, null, null, null, null],
  "re": [null, null, null, null, null, null],
  "im": [null, null, null, null, null, null],
  "period": [null, null, null, null, null, null],
  "phase": [null, null, null, null, null, null],
  "deltaPhase": [null, null, null, null, null, null],
  "alpha": [null, null, null, null, null, null],
  "mama": [null, null, null, null, null, null],
  "fama": [null, null, null, null, null, null]
}
```

## Verification and provenance

Tier: **verified** (via scenario-fixture).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/technical-indicators/trend-smoothing/mama/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/trend-smoothing/mama/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/technical-indicators/llms.txt
