/// <summary> /// Initializes a new instance of the <see cref="CoppockCurve" /> indicator /// </summary> /// <param name="name">A name for the indicator</param> /// <param name="shortRocPeriod">The period for the short ROC</param> /// <param name="longRocPeriod">The period for the long ROC</param> /// <param name="lwmaPeriod">The period for the LWMA</param> public CoppockCurve(string name, int shortRocPeriod, int longRocPeriod, int lwmaPeriod) : base(name) { _shortRoc = new RateOfChangePercent(shortRocPeriod); _longRoc = new RateOfChangePercent(longRocPeriod); _lwma = new LinearWeightedMovingAverage(lwmaPeriod); }
/// <summary> /// Creates a new LinearWeightedMovingAverage indicator. This indicator will linearly distribute /// the weights across the periods. /// </summary> /// <param name="symbol">The symbol whose Williams %R we want</param> /// <param name="period">The period over which to compute the Williams %R</param> /// <param name="resolution">The resolution</param> /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to the Value property of BaseData (x => x.Value)</param> /// <returns></returns> public LinearWeightedMovingAverage LWMA(string symbol, int period, Resolution?resolution = null, Func <BaseData, decimal> selector = null) { string name = CreateIndicatorName(symbol, "LWMA" + period, resolution); var lwma = new LinearWeightedMovingAverage(name, period); RegisterIndicator(symbol, lwma, resolution, selector); return(lwma); }
public HullMovingAverage(string name, int period) : base(name) { var nsquared = period * period; _fast = new LinearWeightedMovingAverage(nsquared / 2); _slow = new LinearWeightedMovingAverage(nsquared); _smooth = new LinearWeightedMovingAverage(period); }
// See http://en.wikipedia.org/wiki/Moving_average // for the formula and the numbers in this test. public void ComputesCorrectly(int period) { var values = new[] { 77m, 79m, 79m, 81m, 83m }; var weights = Enumerable.Range(1, period).ToArray(); var current = weights.Sum(i => i * values[i - 1]) / weights.Sum(); var lwma = new LinearWeightedMovingAverage(period); var time = DateTime.UtcNow; for (var i = 0; i < period; i++) { lwma.Update(time.AddSeconds(i), values[i]); } Assert.AreEqual(current, lwma.Current.Value); }
public void Lwma2ComputesCorrectly() { const int period = 2; decimal[] values = { 1m, 2m }; var lwma = new LinearWeightedMovingAverage(period); decimal current = 0m; for (int i = 0; i < values.Length; i++) { lwma.Update(new IndicatorDataPoint(DateTime.UtcNow.AddSeconds(i), values[i])); } current = ((2 * 2m) + (1 * 1m)) / 3; Assert.AreEqual(current, lwma.Current.Value); }
// See http://en.wikipedia.org/wiki/Moving_average // for the formula and the numbers in this test. public void Lwma5ComputesCorrectly() { const int period = 5; decimal[] values = { 77m, 79m, 79m, 81m, 83m }; var lwma = new LinearWeightedMovingAverage(period); decimal current = 0m; for (int i = 0; i < values.Length; i++) { lwma.Update(new IndicatorDataPoint(DateTime.UtcNow.AddSeconds(i), values[i])); } current = 83 * (5m / 15) + 81 * (4m / 15) + 79 * (3m / 15) + 79 * (2m / 15) + 77 * (1m / 15); Assert.AreEqual(current, lwma.Current.Value); }
// See http://en.wikipedia.org/wiki/Moving_average // for the formula and the numbers in this test. public void Lwma5ComputesCorrectly() { const int period = 5; decimal[] values = { 77m, 79m, 79m, 81m, 83m }; var lwma = new LinearWeightedMovingAverage(period); decimal current = 0m; for (int i = 0; i < values.Length; i++) { lwma.Update(new IndicatorDataPoint(DateTime.UtcNow.AddSeconds(i), values[i])); } current = 83 * (5m / 15) + 81 * (4m / 15) + 79 * (3m / 15) + 79 * (2m / 15) + 77 * (1m / 15); Assert.AreEqual(current, lwma.Current.Value); }
public void Lwma2ComputesCorrectly() { const int period = 2; decimal[] values = { 1m, 2m }; var lwma = new LinearWeightedMovingAverage(period); decimal current = 0m; for (int i = 0; i < values.Length; i++) { lwma.Update(new IndicatorDataPoint(DateTime.UtcNow.AddSeconds(i), values[i])); } current = ((2 * 2m) + (1 * 1m)) / 3; Assert.AreEqual(current, lwma.Current.Value); }
public void Lwma4ComputesCorrectly() { const int period = 4; decimal[] values = { 1m, 2m, 3m, 4m }; var lwma = new LinearWeightedMovingAverage(period); decimal current = 0m; for (int i = 0; i < values.Length; i++) { lwma.Update(new IndicatorDataPoint(DateTime.UtcNow.AddSeconds(i), TimeZone.Utc, values[i])); } current = ((4 * .4m) + (3 * .3m) + (2 * .2m) + (1 * .1m)); Assert.Equal(current, lwma.Current.Price); }
// See http://en.wikipedia.org/wiki/Moving_average // for the formula and the numbers in this test. public void WarmsUpProperly(int period) { var values = new[] { 77m, 79m, 79m, 81m, 83m }; var weights = Enumerable.Range(1, period).ToArray(); var current = weights.Sum(i => i * values[i - 1]) / weights.Sum(); var lwma = new LinearWeightedMovingAverage(period); var time = DateTime.UtcNow; var warmUpPeriod = (lwma as IIndicatorWarmUpPeriodProvider)?.WarmUpPeriod; for (var i = 0; i < warmUpPeriod; i++) { lwma.Update(time.AddSeconds(i), values[i]); Assert.AreEqual(i == warmUpPeriod - 1, lwma.IsReady); } Assert.AreEqual(current, lwma.Current.Value); }
public void ResetsProperly() { const int period = 4; decimal[] values = { 1m, 2m, 3m, 4m, 5m }; var lwma = new LinearWeightedMovingAverage(period); for (int i = 0; i < values.Length; i++) { lwma.Update(new IndicatorDataPoint(DateTime.UtcNow.AddSeconds(i), TimeZone.Utc, values[i])); } Assert.True(lwma.IsReady); Assert.NotEqual(0m, lwma.Current.Price); Assert.NotEqual(0, lwma.Samples); lwma.Reset(); TestHelper.AssertIndicatorIsInDefaultState(lwma); }
// See http://en.wikipedia.org/wiki/Moving_average // for the formula and the numbers in this test. public void ResetsProperly(int period) { var values = new[] { 77m, 79m, 79m, 81m, 83m }; var weights = Enumerable.Range(1, period).ToArray(); var current = weights.Sum(i => i * values[i - 1]) / weights.Sum(); var lwma = new LinearWeightedMovingAverage(period); var time = DateTime.UtcNow; for (var i = 0; i < period; i++) { lwma.Update(time.AddSeconds(i), values[i]); } Assert.AreEqual(current, lwma.Current.Value); Assert.IsTrue(lwma.IsReady); Assert.AreNotEqual(0m, lwma.Current.Value); Assert.AreNotEqual(0, lwma.Samples); lwma.Reset(); TestHelper.AssertIndicatorIsInDefaultState(lwma); }
public void ResetsProperly() { const int period = 4; decimal[] values = { 1m, 2m, 3m, 4m, 5m }; var lwma = new LinearWeightedMovingAverage(period); for (int i = 0; i < values.Length; i++) { lwma.Update(new IndicatorDataPoint(DateTime.UtcNow.AddSeconds(i), values[i])); } Assert.IsTrue(lwma.IsReady); Assert.AreNotEqual(0m, lwma.Current.Value); Assert.AreNotEqual(0, lwma.Samples); lwma.Reset(); TestHelper.AssertIndicatorIsInDefaultState(lwma); }