Skip to content
Open RaamTrade

WeightedClose — Weighted Close

A one-number bar summary that leans toward the close: the close counts twice, the high and low once each. Sits between TypicalPrice (close counted once) and the raw close.

Signature

WeightedClose(period, on=<source>)
Argument Type Required Notes
period int Param or literal Yes Simple-average smoothing window. 1 (the default) returns the raw transform. Bounds 1–200.
on= symbol No Source symbol. Defaults to the trade symbol. Reads high, low and close.

Formula

$$ \text{WC}_t = \frac{H_t + L_t + 2C_t}{4} $$

With period > 1, the simple average of the last period weighted closes.

Warmup

period bars; the lead-in returns the average of the bars seen so far.

Reading the value

wc.value
wc.value_at(1)
wc > level

Example

class WeightedPullback(Strategy):
"""Buy a dip below the smoothed weighted close in an uptrend."""
smooth = Param(20, min=1, max=200)
trend = Param(100, min=10, max=400)
trade = Symbol()
sizing = FixedCapital()
def execute(self):
wc = WeightedClose(self.smooth, on=self.trade)
slow = SMA(self.trend, on=self.trade)
if self.trade.close > slow.value and self.trade.close < wc.value and self.trade.is_flat:
self.buy(self.trade, reason="Dip below weighted close in uptrend")
if self.trade.close < slow.value and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Trend gone")

Notes

  • Standard price transform (TA-Lib WCLPRICE).
  • Proven by an assert-via-trade run on SPY daily (matched (H+L+2C)/4 on every bar; zero alarm trades).
  • Prefer it over TypicalPrice when the close’s position in the range matters more than the range itself.