Single-series rolling midpoint: `(Highest(V, N) + Lowest(V, N)) * 0.5`. Returns the center of the value range within a lookback window. TA-Lib compatible (`MIDPOINT` function). Unlike MIDPRICE which operates on separate High/Low bar channels, MIDPOINT operates on a single value series.
## Historical Context
The midpoint of a rolling range is one of the simplest channel-center calculations in technical analysis. It appears in virtually every charting platform as the baseline for range-based indicators. TA-Lib implements it as `MIDPOINT` (single series) vs `MIDPRICE` (dual H/L series). The distinction matters: MIDPOINT feeds any single-valued series through a rolling window, while MIDPRICE decomposes OHLC bars into separate high/low channels.
## Architecture and Physics
### 1. RingBuffer Pattern
Uses a single `RingBuffer(period)` to store the last N values. On each update, the buffer provides `Max()` and `Min()` for the rolling window. This is self-contained with no external indicator dependencies.
### 2. Data Flow
```text
Input(value) --> NaN guard --> RingBuffer.Add(v, isNew)
|
(Max() + Min()) * 0.5
|
Output
```
### 3. State Synchronization
Uses the standard `_s` / `_ps` state local copy pattern for bar correction (`isNew = false`). The `RingBuffer.Add(v, isNew)` call handles rollback internally when `isNew` is false.
where $\text{range}(V, N) = \max(V, N) - \min(V, N)$.
### Properties
- **Bounded:** Always between the minimum and maximum of the window
- **Idempotent on constants:** If all values equal $c$, midpoint equals $c$
- **Lag:** Responds only when the max or min of the window changes
## Performance Profile
### Operation Count (Streaming Mode)
| Operation | Count |
|-----------|-------|
| Comparison (Max scan) | $O(N)$ per update |
| Comparison (Min scan) | $O(N)$ per update |
| Addition | 1 |
| Multiplication | 1 |
| **Total** | $O(N)$ |
### Batch Mode
The span-based `Batch` method uses a single `RingBuffer` with linear scan for max/min. For large datasets, amortized cost is $O(N \cdot P)$ where $P$ is the period.