Volume Weighted Moving Average (VWMA)
Volume Weighted Moving Average is the volume adjusted average price over a lookback window. [Discuss] 💬
// C# usage syntax
IReadOnlyList<VwmaResult> results =
bars.ToVwma(lookbackPeriods);Parameters
| param | description |
|---|---|
lookbackPeriodsint | 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
IReadOnlyList<VwmaResult>- This method returns a time series of all available indicator values for the
barsprovided. - 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-1periods will havenullvalues forVwmasince there's not enough data to calculate.
VwmaResult
| property | description |
|---|---|
TimestampDateTime | Date from evaluated TBar |
Vwmadouble? | 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.
// 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:
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:
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:
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.