/// <summary> /// The MAMA (MESA Adaptive Moving Average) was developed by John Ehlers. It adapts to price movement in a new and unique way. The adaptation is based on the Hilbert Transform Discriminator. The adavantage of this method features fast attack average and a slow decay average. The MAMA + the FAMA (Following Adaptive Moving Average) lines only cross at major market reversals. /// </summary> /// <returns></returns> public MAMA MAMA(Data.IDataSeries input, double fastLimit, double slowLimit) { if (cacheMAMA != null) { for (int idx = 0; idx < cacheMAMA.Length; idx++) { if (Math.Abs(cacheMAMA[idx].FastLimit - fastLimit) <= double.Epsilon && Math.Abs(cacheMAMA[idx].SlowLimit - slowLimit) <= double.Epsilon && cacheMAMA[idx].EqualsInput(input)) { return(cacheMAMA[idx]); } } } lock (checkMAMA) { checkMAMA.FastLimit = fastLimit; fastLimit = checkMAMA.FastLimit; checkMAMA.SlowLimit = slowLimit; slowLimit = checkMAMA.SlowLimit; if (cacheMAMA != null) { for (int idx = 0; idx < cacheMAMA.Length; idx++) { if (Math.Abs(cacheMAMA[idx].FastLimit - fastLimit) <= double.Epsilon && Math.Abs(cacheMAMA[idx].SlowLimit - slowLimit) <= double.Epsilon && cacheMAMA[idx].EqualsInput(input)) { return(cacheMAMA[idx]); } } } MAMA indicator = new MAMA(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.FastLimit = fastLimit; indicator.SlowLimit = slowLimit; Indicators.Add(indicator); indicator.SetUp(); MAMA[] tmp = new MAMA[cacheMAMA == null ? 1 : cacheMAMA.Length + 1]; if (cacheMAMA != null) { cacheMAMA.CopyTo(tmp, 0); } tmp[tmp.Length - 1] = indicator; cacheMAMA = tmp; return(indicator); } }
/// <summary> /// The MAMA (MESA Adaptive Moving Average) was developed by John Ehlers. It adapts to price movement in a new and unique way. The adaptation is based on the Hilbert Transform Discriminator. The adavantage of this method features fast attack average and a slow decay average. The MAMA + the FAMA (Following Adaptive Moving Average) lines only cross at major market reversals. /// </summary> /// <returns></returns> public MAMA MAMA(Data.IDataSeries input, double fastLimit, double slowLimit) { if (cacheMAMA != null) for (int idx = 0; idx < cacheMAMA.Length; idx++) if (Math.Abs(cacheMAMA[idx].FastLimit - fastLimit) <= double.Epsilon && Math.Abs(cacheMAMA[idx].SlowLimit - slowLimit) <= double.Epsilon && cacheMAMA[idx].EqualsInput(input)) return cacheMAMA[idx]; lock (checkMAMA) { checkMAMA.FastLimit = fastLimit; fastLimit = checkMAMA.FastLimit; checkMAMA.SlowLimit = slowLimit; slowLimit = checkMAMA.SlowLimit; if (cacheMAMA != null) for (int idx = 0; idx < cacheMAMA.Length; idx++) if (Math.Abs(cacheMAMA[idx].FastLimit - fastLimit) <= double.Epsilon && Math.Abs(cacheMAMA[idx].SlowLimit - slowLimit) <= double.Epsilon && cacheMAMA[idx].EqualsInput(input)) return cacheMAMA[idx]; MAMA indicator = new MAMA(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.FastLimit = fastLimit; indicator.SlowLimit = slowLimit; Indicators.Add(indicator); indicator.SetUp(); MAMA[] tmp = new MAMA[cacheMAMA == null ? 1 : cacheMAMA.Length + 1]; if (cacheMAMA != null) cacheMAMA.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheMAMA = tmp; return indicator; } }