fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Percent Above 50-Day MA

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-50-day-ma";

Signature#

evaluateSnapshot(snapshot, decisionTime)

The same participation measure over 50 sessions — the intermediate-horizon reading, and the one most often quoted for trend health.

Parameters#

NameTypeNotes
snapshotSnapshotUniverse snapshot with price_field, window_sessions and per-security history.
decisionTimestringPoint-in-time bound.

Returns#

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

The percentage with its counts.

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#

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

Input#

snapshot
{
  "window_sessions": 50,
  "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
"2026-06-30T22:00:00Z"

Call#

evaluateSnapshot(snapshot, decisionTime)

Returns#

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

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

Diagrams#

Percent Above 50-Day MA — decision boundary
Percent Above 50-Day MA — family map
Percent Above 50-Day MA — worked state

Calculation flow#

Topic decision flow — Percent Above 50-Day MA
flowchart LR
    A["Point-in-time members"] --> B["Require 50 comparable adjusted closes"]
    B --> C{"Every member ready?"}
    C -->|"No"| I["Incomplete: keep denominator atomic"]
    C -->|"Yes"| D["Compute each SMA50"]
    D --> E{"Current price > SMA50?"}
    E -->|"Yes"| F["Add one to numerator"]
    E -->|"No or equal"| G["Keep only in denominator"]
    F --> H["100 × above / eligible"]
    G --> H

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

  • Percent Above Moving Average
  • Corporate Actions and Events Manual, Equities
  • Rolling Mean Documentation
  • Evidence decision

The rest of the High/Low and Trend Breadth family#