Files

93 lines
4.6 KiB
Markdown
Raw Permalink Normal View History

2026-02-23 17:27:35 -08:00
# TYPPRICE: Typical Price
> *Typical price weights high, low, and close equally — a three-point summary that drops the open and keeps the essential.*
2026-02-27 07:48:12 -08:00
| Property | Value |
| ---------------- | -------------------------------- |
| **Category** | Core |
| **Inputs** | OHLCV bar (TBar) |
| **Parameters** | None |
| **Outputs** | Single series (TYPPRICE) |
| **Output range** | Varies (see docs) |
| **Warmup** | `1` bars |
| **PineScript** | [typprice.pine](typprice.pine) |
2026-02-27 07:48:12 -08:00
2026-02-28 14:14:35 -08:00
- TYPPRICE computes the equal-weighted average of Open, High, and Low: $(O + H + L) \times \frac{1}{3}$.
2026-02-27 07:48:12 -08:00
- No configurable parameters; computation is stateless per bar.
2026-02-28 14:14:35 -08:00
- Equivalent to `TBar.OHL3` computed property.
2026-02-27 07:48:12 -08:00
2026-02-28 14:14:35 -08:00
TYPPRICE computes the equal-weighted average of Open, High, and Low: $(O + H + L) \times \frac{1}{3}$. This three-component mean captures the opening price and the full intra-bar range without including the settlement (Close). By excluding Close, Typical Price isolates the session's initial positioning and range extremes, making it useful as an input where you want a price representative that is independent of closing action. The calculation is stateless and costs a single FMA instruction per bar.
2026-02-23 17:27:35 -08:00
## Historical Context
2026-02-28 14:14:35 -08:00
The OHL3 variant of Typical Price represents the average of the bar's opening level and its range extremes. Unlike the more common HLC3 formulation (which TA-Lib implements as `TA_TYPPRICE`), OHL3 excludes the closing price entirely. This makes it suitable for analysis where the settlement price should not influence the representative price, for example when studying intra-session price discovery or when the closing price is already used as a separate signal component.
2026-02-23 17:27:35 -08:00
2026-02-28 14:14:35 -08:00
In QuanTAlib, `TBar.OHL3` provides the same value as a zero-cost computed property. The `Typprice` indicator class wraps this in the streaming `ITValuePublisher` interface with bar correction, NaN safety, and event chaining.
2026-02-23 17:27:35 -08:00
## Architecture & Physics
### 1. Core Formula
2026-02-28 14:14:35 -08:00
$$\text{TypPrice}_t = (O_t + H_t + L_t) \times \tfrac{1}{3}$$
2026-02-23 17:27:35 -08:00
Implemented as FMA with a precomputed reciprocal constant:
2026-02-28 14:14:35 -08:00
$$\text{TypPrice}_t = \text{FMA}\!\left(O_t,\; \tfrac{1}{3},\; (H_t + L_t) \times \tfrac{1}{3}\right)$$
2026-02-23 17:27:35 -08:00
The constant $\frac{1}{3}$ is stored as `private const double OneThird = 1.0 / 3.0`, evaluated at compile time. No runtime division occurs.
### 2. State Management
Stateless per bar. State exists only for:
2026-02-28 14:14:35 -08:00
- **Last-valid substitution**: Non-finite O, H, or L values are replaced with the last known finite value for that component.
2026-02-23 17:27:35 -08:00
- **Bar correction**: `isNew=false` rolls back to previous state for same-timestamp rewrites.
### 3. Complexity
$O(1)$ per bar. One addition, one FMA. No memory allocation. Always hot after the first bar.
## Mathematical Foundation
### Parameters
| Parameter | Description | Default | Constraint |
|-----------|-------------|---------|------------|
| (none) | No user-configurable parameters | | |
### Why Not Divide by 3?
Division by a non-power-of-two constant is 4-5x more expensive than multiplication on modern x86 CPUs (~15 cycles vs ~3 cycles). Precomputing $\frac{1}{3}$ as a `const double` and multiplying eliminates the division entirely. The compiler constant-folds `1.0 / 3.0` to the IEEE 754 double `0x3FD5555555555555` at compile time, so the hot path sees only multiply/FMA operations.
### Output Interpretation
| Context | Meaning |
|---------|---------|
2026-02-28 14:14:35 -08:00
| Close > TYPPRICE | Close above session's OHL center (bullish settlement relative to range) |
| Close < TYPPRICE | Close below session's OHL center (bearish settlement relative to range) |
| TYPPRICE trending up | Opening levels and range are rising |
| TYPPRICE as input | Useful where Close independence is desired |
2026-02-23 17:27:35 -08:00
## Performance Profile
### Operation Count (Streaming Mode)
| Operation | Count | Cost (cycles) | Subtotal |
|-----------|:-----:|:-------------:|:--------:|
2026-02-28 14:14:35 -08:00
| ADD (H+L) | 1 | 1 | 1 |
| MUL ((H+L) × OneThird) | 1 | 3 | 3 |
| FMA (O × OneThird + prev) | 1 | 4 | 4 |
2026-02-23 17:27:35 -08:00
| **Total (hot)** | **3** | | **~8 cycles** |
### Batch Mode (SIMD Analysis)
| Aspect | Assessment |
|--------|------------|
| SIMD vectorizable | Yes: element-wise arithmetic, no inter-bar dependency |
2026-02-28 14:14:35 -08:00
| Optimal strategy | `Vector<double>` over O/H/L spans with broadcast OneThird |
2026-02-23 17:27:35 -08:00
| Memory | $O(1)$ streaming; $O(n)$ batch output span |
| Throughput | Near memory-bandwidth bound for large series |
## Resources
- **QuanTAlib** `TBar.OHL3` computed property reference.