/// <summary> /// Resets this indicator to its initial state /// </summary> public override void Reset() { _price.Reset(); _volume.Reset(); _vwap = _price.WeightedBy(_volume, _period); base.Reset(); }
/// <summary> /// Initializes a new instance of the VWAP class with a given name and period /// </summary> /// <param name="name">string - the name of the indicator</param> /// <param name="period">The period of the VWAP</param> public VolumeWeightedAveragePriceIndicator(string name, int period) : base(name) { _price = new Identity("Price"); _volume = new Identity("Volume"); // This class will be using WeightedBy indicator extension _vwap = _price.WeightedBy(_volume, period); }
/// <summary> /// Initializes a new instance of the VWAP class with a given name and period /// </summary> /// <param name="name">string - the name of the indicator</param> /// <param name="period">The period of the VWAP</param> public VolumeWeightedAveragePriceIndicator(string name, int period) : base(name) { _price = new Identity("Price"); _volume = new Identity("Volume"); // This class will be using WeightedBy indicator extension _vwap = _price.WeightedBy(_volume, period); }
public void PipesDataFirstWeightedBySecond() { const int period = 4; var value = new Identity("Value"); var weight = new Identity("Weight"); var third = value.WeightedBy(weight, period); var data = Enumerable.Range(1, 10).ToList(); var window = Enumerable.Reverse(data).Take(period); var current = window.Sum(x => 2 * x * x) / (decimal)window.Sum(x => x); foreach (var item in data) { value.Update(new IndicatorDataPoint(DateTime.UtcNow, Convert.ToDecimal(2 * item))); weight.Update(new IndicatorDataPoint(DateTime.UtcNow, Convert.ToDecimal(item))); } Assert.AreEqual(current, third.Current.Value); }