Files
wickra/docs/wiki/indicators/statistics/Indicator-WeightedClose.md
T
kingchenc 2d0ee926c5 F12: add price transforms and rolling linear regression
- Rust core: typical_price.rs ((H+L+C)/3), median_price.rs ((H+L)/2),
  weighted_close.rs ((H+L+2C)/4) — stateless per-bar OHLC transforms — and
  linreg.rs (LinearRegression — endpoint of a rolling ordinary-least-squares
  fit) and linreg_slope.rs (LinRegSlope — slope of that fit). Each with a
  full Indicator impl, runnable doctest and reference / property / warmup /
  reset / batch==streaming tests.
- Python: PyTypicalPrice / PyMedianPrice / PyWeightedClose /
  PyLinearRegression / PyLinRegSlope PyO3 classes + module registration +
  .pyi stubs.
- Node: explicit TypicalPriceNode / MedianPriceNode / WeightedCloseNode /
  LinearRegressionNode / LinRegSlopeNode; index.d.ts and index.js updated.
- WASM: explicit WasmTypicalPrice / WasmMedianPrice / WasmWeightedClose;
  WasmLinearRegression / WasmLinRegSlope via the scalar macro.
- Wiki: a new indicators/statistics/ folder with five Indicator-*.md pages,
  a new "Statistics" family in Indicators-Overview.md and Home.md.

cargo fmt + clippy (core/wickra/data/wasm/node) clean; 454 core tests,
25 data tests and 66 doctests green.
2026-05-22 19:52:04 +02:00

3.4 KiB

WeightedClose

Weighted Close — the bar's (high + low + 2·close) / 4, a per-bar price that gives the close double weight.

Quick reference

Field Value
Family Statistics
Sub-category Price transforms
Input type Candle (uses high, low, close)
Output type f64
Output range unbounded (price scale)
Default parameters none (no parameters)
Warmup period 1
Interpretation A representative per-bar price that leans on the close.

Formula

WeightedClose = (high + low + 2·close) / 4

Like the TypicalPrice, the weighted close collapses an OHLC bar to one number — but it counts the close twice, so the result sits closer to where the bar settled than to its range. Reach for it when the closing print carries more signal than the extremes.

Parameters

WeightedClose takes no parametersWeightedClose::new() in Rust, wickra.WeightedClose() in Python, new ta.WeightedClose() in Node.

Inputs / Outputs

From crates/wickra-core/src/indicators/weighted_close.rs:

impl Indicator for WeightedClose {
    type Input = Candle;
    type Output = f64;
    // update(&mut self, input: Candle) -> Option<f64>
}

WeightedClose is a candle-input indicator that reads high, low and close. In Python the streaming update accepts a 6-tuple or a dict; the batch helper takes high, low, close numpy arrays. Node and WASM expose update(high, low, close) and the matching batch.

Warmup

WeightedClose::new().warmup_period() == 1. It is a stateless per-bar transform — it emits a value from the very first candle.

Edge cases

  • No warmup. Every candle produces a value immediately.
  • Reset. wc.reset() only clears the is_ready flag; there is no rolling state to discard.

Examples

Rust

use wickra::{Candle, Indicator, WeightedClose};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut wc = WeightedClose::new();
    let v = wc.update(Candle::new(10.0, 12.0, 8.0, 11.0, 1.0, 0)?);
    println!("{:?}", v);
    Ok(())
}

Output:

Some(10.5)

(12 + 8 + 2·11) / 4 = 42 / 4 = 10.5. This matches the reference_value test in crates/wickra-core/src/indicators/weighted_close.rs.

Python

import numpy as np
import wickra as ta

wc = ta.WeightedClose()
print(wc.batch(np.array([12.0]), np.array([8.0]), np.array([11.0])))

Output:

[10.5]

Node

const ta = require('wickra');
const wc = new ta.WeightedClose();
console.log(wc.batch([12], [8], [11]));

Output:

[ 10.5 ]

Interpretation

The weighted close sits on the spectrum between the raw close and the TypicalPrice: closer to the close, but still nudged by the bar's range. Use it as a drop-in close replacement when you want the settlement to dominate without ignoring the extremes entirely.

Common pitfalls

  • Feeding it scalar prices. It needs the full high/low/close bar.

References

The Weighted Close; the (H + L + 2C) / 4 definition is standard (TA-Lib's WCLPRICE).

See also