public MACD(int shortDay ,int longDay,int m) { this.shortDay = shortDay; this.longDay = longDay; this.m = m; this.coefShort = 2 / (shortDay + 1); this.coefLong = 2 / (longDay + 1); emaS = new EMA(shortDay,10); emaL = new EMA(longDay,10); diffCache = new EMA(m,10); }
public MACD() { this.shortDay = 12; this.longDay = 26; this.m = 9; this.coefShort = 2 / (shortDay + 1); this.coefLong = 2 / (longDay + 1); emaS = new EMA(12,10); emaL = new EMA(26,10); diffCache = new EMA(m,10); }
public static bool TryCreateInstance(int period,double tolerance,double[] initSamples,out EMA ema,out int initLength) { ema = null; var multiplier = 2.0 / (period + 1.0); var exp = (period - 1.0) / (period + 1.0); ; initLength = initSamples.Length; var isFitTolerance = Math.Round(Math.Log(tolerance / initSamples[0], exp)) <= initSamples.Length; if (isFitTolerance) { ema = new EMA(period, tolerance); int i = 0; ema.Value = multiplier * initSamples.Aggregate(0.0, (seed, v) => { seed += Math.Pow(exp, i) * initSamples[initSamples.Length - 1 - i]; i++; return seed; }); } else { initLength = Convert.ToInt32(Math.Round(Math.Log(tolerance / initSamples[0], exp))); } return isFitTolerance; }