Exemple #1
0
        /// <summary>
        /// Developed by Perry Kaufman, this indicator is an EMA using an Efficiency Ratio to modify the smoothing constant, which ranges from a minimum of Fast Length to a maximum of Slow Length. Since this moving average is adaptive it tends to follow prices more closely than other MA's.
        /// </summary>
        /// <returns></returns>
        public KAMA KAMA(Data.IDataSeries input, int fast, int period, int slow)
        {
            if (cacheKAMA != null)
            {
                for (int idx = 0; idx < cacheKAMA.Length; idx++)
                {
                    if (cacheKAMA[idx].Fast == fast && cacheKAMA[idx].Period == period && cacheKAMA[idx].Slow == slow && cacheKAMA[idx].EqualsInput(input))
                    {
                        return(cacheKAMA[idx]);
                    }
                }
            }

            lock (checkKAMA)
            {
                checkKAMA.Fast   = fast;
                fast             = checkKAMA.Fast;
                checkKAMA.Period = period;
                period           = checkKAMA.Period;
                checkKAMA.Slow   = slow;
                slow             = checkKAMA.Slow;

                if (cacheKAMA != null)
                {
                    for (int idx = 0; idx < cacheKAMA.Length; idx++)
                    {
                        if (cacheKAMA[idx].Fast == fast && cacheKAMA[idx].Period == period && cacheKAMA[idx].Slow == slow && cacheKAMA[idx].EqualsInput(input))
                        {
                            return(cacheKAMA[idx]);
                        }
                    }
                }

                KAMA indicator = new KAMA();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input  = input;
                indicator.Fast   = fast;
                indicator.Period = period;
                indicator.Slow   = slow;
                Indicators.Add(indicator);
                indicator.SetUp();

                KAMA[] tmp = new KAMA[cacheKAMA == null ? 1 : cacheKAMA.Length + 1];
                if (cacheKAMA != null)
                {
                    cacheKAMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheKAMA           = tmp;
                return(indicator);
            }
        }
Exemple #2
0
        /// <summary>
        /// Developed by Perry Kaufman, this indicator is an EMA using an Efficiency Ratio to modify the smoothing constant, which ranges from a minimum of Fast Length to a maximum of Slow Length. Since this moving average is adaptive it tends to follow prices more closely than other MA's.
        /// </summary>
        /// <returns></returns>
        public KAMA KAMA(Data.IDataSeries input, int fast, int period, int slow)
        {
            if (cacheKAMA != null)
                for (int idx = 0; idx < cacheKAMA.Length; idx++)
                    if (cacheKAMA[idx].Fast == fast && cacheKAMA[idx].Period == period && cacheKAMA[idx].Slow == slow && cacheKAMA[idx].EqualsInput(input))
                        return cacheKAMA[idx];

            lock (checkKAMA)
            {
                checkKAMA.Fast = fast;
                fast = checkKAMA.Fast;
                checkKAMA.Period = period;
                period = checkKAMA.Period;
                checkKAMA.Slow = slow;
                slow = checkKAMA.Slow;

                if (cacheKAMA != null)
                    for (int idx = 0; idx < cacheKAMA.Length; idx++)
                        if (cacheKAMA[idx].Fast == fast && cacheKAMA[idx].Period == period && cacheKAMA[idx].Slow == slow && cacheKAMA[idx].EqualsInput(input))
                            return cacheKAMA[idx];

                KAMA indicator = new KAMA();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.Fast = fast;
                indicator.Period = period;
                indicator.Slow = slow;
                Indicators.Add(indicator);
                indicator.SetUp();

                KAMA[] tmp = new KAMA[cacheKAMA == null ? 1 : cacheKAMA.Length + 1];
                if (cacheKAMA != null)
                    cacheKAMA.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheKAMA = tmp;
                return indicator;
            }
        }