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 | type | description |
|---|---|---|
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
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 | type | description |
|---|---|---|
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.
// 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);
foreach (IBar bar in bars) // simulating stream
{
vwmaList.Add(bar);
}
// based on `ICollection<VwmaResult>`
IReadOnlyList<VwmaResult> results = vwmaList;Subscribe to a BarHub for advanced streaming scenarios:
BarHub barHub = new();
VwmaHub observer = barHub.ToVwmaHub(lookbackPeriods);
foreach (IBar bar in bars) // simulating stream
{
barHub.Add(bar);
}
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.