VWMA — Volume-Weighted Moving Average
A moving average where each bar’s close is weighted by its volume: the average price the traded
money actually paid, rather than the average of prints. Diverges from SMA exactly when heavy
bars sit away from the window’s middle.
Signature
VWMA(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Window. Default 20, bounds 1–400. |
on= |
symbol | No | Source symbol. Defaults to the trade symbol. Reads close and volume. |
Formula
$$ \text{VWMA}t = \frac{\sum{i=t-n+1}^{t} C_i V_i}{\sum_{i=t-n+1}^{t} V_i} $$
Warmup
period bars; the lead-in averages the bars seen so far. If the whole window has zero volume,
the current close is returned instead of dividing by zero.
Reading the value
vwma.valuevwma.crossed_above(sma)Example
class VolumeConfirmedTrend(Strategy): """Long when the volume-weighted average leads the plain one.""" period = Param(20, min=1, max=400) trade = Symbol() sizing = FixedCapital()
def execute(self): vwma = VWMA(self.period, on=self.trade) sma = SMA(self.period, on=self.trade) if vwma.value > sma.value and self.trade.close > vwma.value and self.trade.is_flat: self.buy(self.trade, reason="Volume behind the move") if vwma.value < sma.value and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Volume gone")Notes
- Standard definition (pandas-ta
vwma). - Not
RollingVWAP— that weights the typical price; this weights the close.