# Moving Average Calculator (SMA & EMA)

> Moving Average Calculator (SMA & EMA) is a paid API for AI agents from agent402.tools, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-14).

Computes simple (SMA) and/or exponential (EMA) moving averages over a numeric series, returning one value per input position with standard alpha smoothing for EMA.

## Facts

- Endpoint: POST https://agent402.tools/api/moving-average
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/moving-average-calculator-sma-ema-581c8a9b
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_59VdqpHTt7piKHE6vlovW

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability moving-average-calculator-sma-ema-581c8a9b -d '<json body>'
```

Example prompt: Can you compute both the SMA and EMA moving averages with a window of 14 for this price series: [45.2, 46.1, 45.8, 47.3, 48.0, 47.5, 49.2, 50.1, 49.8, 51.0, 52.3, 51.7, 53.0, 54.2, 53.8, 55.1]?

## When to prefer this

Use this endpoint when you need fast, pay-per-call moving average computation without setting up your own data pipeline or statistical library. Ideal for agents processing financial time series, sensor data, or any numeric sequence that needs smoothing on-the-fly. Prefer over manual computation when you need both SMA and EMA in a single call.

## Known failure modes

- Window size smaller than 2 or larger than the array length returns a validation error
- Non-numeric values in the series cause a parsing error
- Array length exceeds 10000 items results in rejection
- Invalid 'which' parameter value other than sma/ema/both returns an error
- Empty values array returns an error or empty result

## How this service works

Compute simple (SMA) and exponential (EMA) moving averages over a numeric series. Returns one value per input position - the first (window-1) SMA values are null since there isn't enough history. EMA uses the standard alpha = 2/(window+1) smoothing factor used in technical analysis.

## Output

Returns an object with one array per requested type (sma and/or ema), each containing one value per input element. The first (window-1) SMA values are null due to insufficient history. EMA uses alpha = 2/(window+1) and populates from the first valid window onward.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "which": {
   "type": "string",
   "description": "\"sma\", \"ema\", or \"both\" (default \"both\")"
  },
  "values": {
   "type": "array",
   "description": "Numeric series (max 10000)"
  },
  "window": {
   "type": "number",
   "description": "Window size, 2 to values.length"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "ema": [
   10,
   10.5,
   11.25,
   12.125,
   13.0625,
   14.0312,
   15.0156,
   16.0078,
   17.0039,
   18.002
  ],
  "sma": [
   null,
   null,
   11,
   12,
   13,
   14,
   15,
   16,
   17,
   18
  ],
  "count": 10,
  "window": 3
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/moving-average-calculator-sma-ema-581c8a9b/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.tools](https://www.zero.xyz/host/agent402.tools/llms.txt)
