Esempio n. 1
0
        /// <summary>
        /// The ZigZag indicator shows trend lines filtering out changes below a defined level. 
        /// </summary>
        /// <returns></returns>
        public ZigZag ZigZag(Data.IDataSeries input, DeviationType deviationType, double deviationValue, bool useHighLow)
        {
            if (cacheZigZag != null)
                for (int idx = 0; idx < cacheZigZag.Length; idx++)
                    if (cacheZigZag[idx].DeviationType == deviationType && Math.Abs(cacheZigZag[idx].DeviationValue - deviationValue) <= double.Epsilon && cacheZigZag[idx].UseHighLow == useHighLow && cacheZigZag[idx].EqualsInput(input))
                        return cacheZigZag[idx];

            lock (checkZigZag)
            {
                checkZigZag.DeviationType = deviationType;
                deviationType = checkZigZag.DeviationType;
                checkZigZag.DeviationValue = deviationValue;
                deviationValue = checkZigZag.DeviationValue;
                checkZigZag.UseHighLow = useHighLow;
                useHighLow = checkZigZag.UseHighLow;

                if (cacheZigZag != null)
                    for (int idx = 0; idx < cacheZigZag.Length; idx++)
                        if (cacheZigZag[idx].DeviationType == deviationType && Math.Abs(cacheZigZag[idx].DeviationValue - deviationValue) <= double.Epsilon && cacheZigZag[idx].UseHighLow == useHighLow && cacheZigZag[idx].EqualsInput(input))
                            return cacheZigZag[idx];

                ZigZag indicator = new ZigZag();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.DeviationType = deviationType;
                indicator.DeviationValue = deviationValue;
                indicator.UseHighLow = useHighLow;
                Indicators.Add(indicator);
                indicator.SetUp();

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