Example #1
0
        /// <summary>
        /// The APZ (Adaptive Prize Zone) forms a steady channel based on double smoothed exponential moving averages around the average price.
        /// </summary>
        /// <returns></returns>
        public APZ APZ(Data.IDataSeries input, double bandPct, int period)
        {
            if (cacheAPZ != null)
            {
                for (int idx = 0; idx < cacheAPZ.Length; idx++)
                {
                    if (Math.Abs(cacheAPZ[idx].BandPct - bandPct) <= double.Epsilon && cacheAPZ[idx].Period == period && cacheAPZ[idx].EqualsInput(input))
                    {
                        return(cacheAPZ[idx]);
                    }
                }
            }

            lock (checkAPZ)
            {
                checkAPZ.BandPct = bandPct;
                bandPct          = checkAPZ.BandPct;
                checkAPZ.Period  = period;
                period           = checkAPZ.Period;

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

                APZ indicator = new APZ();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input   = input;
                indicator.BandPct = bandPct;
                indicator.Period  = period;
                Indicators.Add(indicator);
                indicator.SetUp();

                APZ[] tmp = new APZ[cacheAPZ == null ? 1 : cacheAPZ.Length + 1];
                if (cacheAPZ != null)
                {
                    cacheAPZ.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheAPZ            = tmp;
                return(indicator);
            }
        }
Example #2
0
        /// <summary>
        /// The APZ (Adaptive Prize Zone) forms a steady channel based on double smoothed exponential moving averages around the average price.
        /// </summary>
        /// <returns></returns>
        public APZ APZ(Data.IDataSeries input, double bandPct, int period)
        {
            if (cacheAPZ != null)
                for (int idx = 0; idx < cacheAPZ.Length; idx++)
                    if (Math.Abs(cacheAPZ[idx].BandPct - bandPct) <= double.Epsilon && cacheAPZ[idx].Period == period && cacheAPZ[idx].EqualsInput(input))
                        return cacheAPZ[idx];

            lock (checkAPZ)
            {
                checkAPZ.BandPct = bandPct;
                bandPct = checkAPZ.BandPct;
                checkAPZ.Period = period;
                period = checkAPZ.Period;

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

                APZ indicator = new APZ();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.BandPct = bandPct;
                indicator.Period = period;
                Indicators.Add(indicator);
                indicator.SetUp();

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