# Percent Above 20-Day MA

`D04-F03-A04` · Market Breadth and Internals → High/Low and Trend Breadth · archetype `snapshot-evaluate` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/market-breadth-and-internals/high-low-and-trend-breadth/percent-above-20-day-ma/
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 { evaluateSnapshot } from "fintech-algorithms/market-breadth-and-internals/high-low-and-trend-breadth/percent-above-20-day-ma";
```

## Signature

```ts
evaluateSnapshot(snapshot, decisionTime)
```

The share of the universe trading above its own 20-day moving average — a short-horizon participation gauge that turns over quickly.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `snapshot` | `Snapshot` | yes | Universe snapshot with `price_field`, `window_sessions` and per-security history. `universe_revision` is carried so a changing roster does not silently change the denominator. |
| `decisionTime` | `string` | yes | Point-in-time bound on which prices may be used. |

## Returns

`{ status, window_sessions, eligible_count, above_count, equal_count, percent_above, rows }`

The percentage with its numerator and denominator, and `equal_count` broken out separately — securities sitting exactly on their average are neither above nor below, and folding them either way biases the reading.

## Errors

- When a security has fewer sessions than the window requires — excluded from the denominator and reported

## Complexity

Time `O(securities × window)`, space `O(securities)`.

## Worked example

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`snapshot`:

```json
{
  "window_sessions": 20,
  "price_field": "adjusted_close",
  "securities": [
    {
      "security_id": "SYNTH-ABOVE",
      "member_at_session": true,
      "source_evidence_state": "ready",
      "available_at": "2026-06-30T21:30:00Z",
      "adjustment_basis": "split-adjusted-price-return",
      "prices": [100, 100, 100, 100, 100, 100]
    }
  ]
}
```

`decisionTime`:

```json
"2026-06-30T22:00:00Z"
```

### Call

```ts
evaluateSnapshot(snapshot, decisionTime)
```

### Returns

object with 7 fields: status, reason, window_sessions, eligible_count, above_count, equal_count, percent_above

```json
{
  "status": "resolved",
  "reason": null,
  "window_sessions": 20,
  "eligible_count": 1,
  "above_count": 1,
  "equal_count": 0,
  "percent_above": 100
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

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/market-breadth-and-internals/high-low-and-trend-breadth/percent-above-20-day-ma/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-breadth-and-internals/high-low-and-trend-breadth/percent-above-20-day-ma/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-breadth-and-internals/llms.txt
