public void TestEMA() { long ticks = 1000; var data = new double[] { 20, 40, 22, 35, 33, 78, 21, 45, 33, 5, 67, 22, 98, 22, 34, 54 }; var input = new TimeSeries(); var ema = new EMA(input, 10); foreach (var d in data) input.Add(new DateTime().AddTicks(ticks++), d); for (var i = 0; i < ema.Count; i++) output.WriteLine(ema[i].ToString()); Assert.Equal(ema[0], 20, precision); Assert.Equal(ema[1], 23.6363636363636, precision); Assert.Equal(ema[2], 23.3388429752066, precision); Assert.Equal(ema[3], 25.4590533433509, precision); Assert.Equal(ema[4], 26.8301345536507, precision); Assert.Equal(ema[5], 36.1337464529869, precision); Assert.Equal(ema[6], 33.3821561888075, precision); Assert.Equal(ema[7], 35.4944914272061, precision); Assert.Equal(ema[8], 35.0409475313505, precision); Assert.Equal(ema[9], 29.5789570711049, precision); Assert.Equal(ema[10], 36.3827830581768, precision); Assert.Equal(ema[11], 33.7677315930537, precision); Assert.Equal(ema[12], 45.4463258488621, precision); Assert.Equal(ema[13], 41.1833575127054, precision); Assert.Equal(ema[14], 39.8772925103953, precision); Assert.Equal(ema[15], 42.4450575085053, precision); }
public static double Value(ISeries input, int index, int length1, int length2) { if (index >= Math.Max(length1, length2)) { var ad = new AD(input); var ema1 = new EMA(ad, length1); var ema2 = new EMA(ad, length2); return ema1[index] - ema2[index]; } return double.NaN; }
protected override void Init() { this.name = this.input is BarSeries ? $"MACD ({this.length1}, {this.length2}, {this.barData}" : $"MACD ({this.length1}, {this.length2})"; this.description = "Moving Average Convergence Divergence"; Clear(); this.calculate = true; Detach(); this.ema1 = new EMA(this.input, this.length1, this.barData); this.ema2 = new EMA(this.input, this.length2, this.barData); Attach(); }
public static double Value(ISeries input, int index, int length1, int length2) { if (index >= length2 - 1) { var ts = new TimeSeries(); for (var i = 0; i <= index; i++) ts.Add(input.GetDateTime(i), input[i, BarData.High] - input[i, BarData.Low]); var ema = new EMA(ts, length1); return (ema[index] - ema[index - length2 + 1])/ema[index - length2 + 1]*100; } return double.NaN; }
protected override void Init() { this.name = $"VCH ({this.length1}, {this.length2})"; this.description = "Chaikin Volatility"; Clear(); this.calculate = true; this.hlTS = new TimeSeries(); for (var i = 0; i < this.input.Count; i++) this.hlTS.Add(this.input.GetDateTime(i), this.input[i, BarData.High] - this.input[i, BarData.Low]); this.ema = new EMA(this.hlTS, this.length1); }
public static double Value(ISeries input, int index, int length, int order) { if (index >= length - 1) { var ts = new TimeSeries(); for (int i = 0; i <= index; i++) ts.Add(input.GetDateTime(i), input[i, BarData.High] - input[i, BarData.Low]); var ema = new EMA(ts, order); var ema_ema = new EMA(ema, order); return Enumerable.Range(index - length + 1, length).Reverse().Sum(i => ema[i]/ema_ema[i]); } return double.NaN; }
protected override void Init() { this.name = $"MASS ({this.length}, {this.order})"; this.description = "Mass Index"; Clear(); this.calculate = true; this.hlTS = new TimeSeries(); for (var i = 0; i < this.input.Count; i++) this.hlTS.Add(this.input.GetDateTime(i), this.input[i, BarData.High] - this.input[i, BarData.Low]); Detach(); this.ema = new EMA(this.hlTS, this.order); this.ema_ema = new EMA(this.ema, this.order); Attach(); }
protected override void Init() { this.name = $"CAD ({this.length1}, {this.length2})"; this.description = "Chaikin A/D Oscillator"; Clear(); this.calculate = true; Detach(); this.ad?.Detach(); this.ema1?.Detach(); this.ema2?.Detach(); this.ad = new AD(this.input); this.ema1 = new EMA(this.ad, this.length1); this.ema2 = new EMA(this.ad, this.length2); Attach(); }
protected override void Init() { this.name = $"MASS ({this.length}, {this.order})"; this.description = "Mass Index"; Clear(); this.calculate = true; this.hlTS = new TimeSeries(); for (var i = 0; i < this.input.Count; i++) { this.hlTS.Add(this.input.GetDateTime(i), this.input[i, BarData.High] - this.input[i, BarData.Low]); } Detach(); this.ema = new EMA(this.hlTS, this.order); this.ema_ema = new EMA(this.ema, this.order); Attach(); }
public static double Value(ISeries input, int index, int length1, int length2, BarData barData = BarData.Close) { return(index < 0 ? double.NaN : EMA.Value(input, index, length1, barData) - EMA.Value(input, index, length2, barData)); }