Beispiel #1
0
        /// <summary>
        /// ZZBollingerAndMovingStdDev Bands are plotted at standard deviation levels above and below a moving average. Since standard deviation is a measure of volatility, the bands are self-adjusting: widening during volatile markets and contracting during calmer periods.
        /// </summary>
        /// <returns></returns>
        public ZZBollingerAndMovingStdDev ZZBollingerAndMovingStdDev(Data.IDataSeries input, double numStdDev, int period)
        {
            if (cacheZZBollingerAndMovingStdDev != null)
            {
                for (int idx = 0; idx < cacheZZBollingerAndMovingStdDev.Length; idx++)
                {
                    if (Math.Abs(cacheZZBollingerAndMovingStdDev[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheZZBollingerAndMovingStdDev[idx].Period == period && cacheZZBollingerAndMovingStdDev[idx].EqualsInput(input))
                    {
                        return(cacheZZBollingerAndMovingStdDev[idx]);
                    }
                }
            }

            lock (checkZZBollingerAndMovingStdDev)
            {
                checkZZBollingerAndMovingStdDev.NumStdDev = numStdDev;
                numStdDev = checkZZBollingerAndMovingStdDev.NumStdDev;
                checkZZBollingerAndMovingStdDev.Period = period;
                period = checkZZBollingerAndMovingStdDev.Period;

                if (cacheZZBollingerAndMovingStdDev != null)
                {
                    for (int idx = 0; idx < cacheZZBollingerAndMovingStdDev.Length; idx++)
                    {
                        if (Math.Abs(cacheZZBollingerAndMovingStdDev[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheZZBollingerAndMovingStdDev[idx].Period == period && cacheZZBollingerAndMovingStdDev[idx].EqualsInput(input))
                        {
                            return(cacheZZBollingerAndMovingStdDev[idx]);
                        }
                    }
                }

                ZZBollingerAndMovingStdDev indicator = new ZZBollingerAndMovingStdDev();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input     = input;
                indicator.NumStdDev = numStdDev;
                indicator.Period    = period;
                Indicators.Add(indicator);
                indicator.SetUp();

                ZZBollingerAndMovingStdDev[] tmp = new ZZBollingerAndMovingStdDev[cacheZZBollingerAndMovingStdDev == null ? 1 : cacheZZBollingerAndMovingStdDev.Length + 1];
                if (cacheZZBollingerAndMovingStdDev != null)
                {
                    cacheZZBollingerAndMovingStdDev.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1]             = indicator;
                cacheZZBollingerAndMovingStdDev = tmp;
                return(indicator);
            }
        }
        /// <summary>
        /// ZZBollingerAndMovingStdDev Bands are plotted at standard deviation levels above and below a moving average. Since standard deviation is a measure of volatility, the bands are self-adjusting: widening during volatile markets and contracting during calmer periods.
        /// </summary>
        /// <returns></returns>
        public ZZBollingerAndMovingStdDev ZZBollingerAndMovingStdDev(Data.IDataSeries input, double numStdDev, int period)
        {
            if (cacheZZBollingerAndMovingStdDev != null)
                for (int idx = 0; idx < cacheZZBollingerAndMovingStdDev.Length; idx++)
                    if (Math.Abs(cacheZZBollingerAndMovingStdDev[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheZZBollingerAndMovingStdDev[idx].Period == period && cacheZZBollingerAndMovingStdDev[idx].EqualsInput(input))
                        return cacheZZBollingerAndMovingStdDev[idx];

            lock (checkZZBollingerAndMovingStdDev)
            {
                checkZZBollingerAndMovingStdDev.NumStdDev = numStdDev;
                numStdDev = checkZZBollingerAndMovingStdDev.NumStdDev;
                checkZZBollingerAndMovingStdDev.Period = period;
                period = checkZZBollingerAndMovingStdDev.Period;

                if (cacheZZBollingerAndMovingStdDev != null)
                    for (int idx = 0; idx < cacheZZBollingerAndMovingStdDev.Length; idx++)
                        if (Math.Abs(cacheZZBollingerAndMovingStdDev[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheZZBollingerAndMovingStdDev[idx].Period == period && cacheZZBollingerAndMovingStdDev[idx].EqualsInput(input))
                            return cacheZZBollingerAndMovingStdDev[idx];

                ZZBollingerAndMovingStdDev indicator = new ZZBollingerAndMovingStdDev();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.NumStdDev = numStdDev;
                indicator.Period = period;
                Indicators.Add(indicator);
                indicator.SetUp();

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