Skip to content

Volume Weighted Moving Average (VWMA) ​

Volume Weighted Moving Average is the volume adjusted average price over a lookback window. [Discuss] 💬

Loading chart data...
csharp
// C# usage syntax
IReadOnlyList<VwmaResult> results =
  bars.ToVwma(lookbackPeriods);

Parameters ​

paramdescription
lookbackPeriods
int
Number of periods (N) in the moving average. Must be greater than 0.

Historical price bars requirements ​

You must have at least N periods of bars to cover the warmup periods.

bars is a collection of generic TBar historical price bars. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.

Response ​

csharp
IReadOnlyList<VwmaResult>
  • This method returns a time series of all available indicator values for the bars provided.
  • It always returns the same number of elements as there are in the historical price bars.
  • It does not return a single incremental indicator value.
  • The first N-1 periods will have null values for Vwma since there's not enough data to calculate.

VwmaResult ​

propertydescription
Timestamp
DateTime
Date from evaluated TBar
Vwma
double?
Volume Weighted Moving Average

Utilities ​

See Utilities and helpers for more information.

Chaining ​

Results can be further processed on Vwma with additional chain-enabled indicators.

csharp
// example
var results = bars
    .ToVwma(..)
    .ToRsi(..);

This indicator must be generated from bars and cannot be generated from results of another chain-enabled indicator or method.

See Chaining indicators for more.

Streaming ​

Use the buffer-style List<T> when you need incremental calculations without a hub:

csharp
VwmaList vwmaList = new(lookbackPeriods);

// call from your WebSocket or SSE message handler
void OnBarReceived(IBar bar) => vwmaList.Add(bar);

// based on `ICollection<VwmaResult>`; fills as the handler runs
IReadOnlyList<VwmaResult> results = vwmaList;

Subscribe to a BarHub for advanced streaming scenarios:

csharp
BarHub barHub = new();
VwmaHub observer = barHub.ToVwmaHub(lookbackPeriods);

// call from your WebSocket or SSE message handler
void OnBarReceived(IBar bar) => barHub.Add(bar);

// results fill as the handler runs
IReadOnlyList<VwmaResult> results = observer.Results;

Additional buffering methods ​

For volume-weighted calculations, VWMA also supports direct price and volume input:

csharp
VwmaList vwmaList = new(lookbackPeriods);

// Add individual price and volume data
vwmaList.Add(DateTime.Now, price: 100.50, volume: 1000);

Note: VWMA requires both price and volume data, so it only supports methods that accept IBar or direct price/volume parameters.

See Buffer lists and Stream hubs for full usage guides.