/// <summary>
        /// Plots lines at user defined values. Lines with values of zero will not plot.
        /// </summary>
        /// <returns></returns>
        public ConstantLines ConstantLines(Data.IDataSeries input, double line1Value, double line2Value, double line3Value, double line4Value)
        {
            if (cacheConstantLines != null)
            {
                for (int idx = 0; idx < cacheConstantLines.Length; idx++)
                {
                    if (Math.Abs(cacheConstantLines[idx].Line1Value - line1Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line2Value - line2Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line3Value - line3Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line4Value - line4Value) <= double.Epsilon && cacheConstantLines[idx].EqualsInput(input))
                    {
                        return(cacheConstantLines[idx]);
                    }
                }
            }

            lock (checkConstantLines)
            {
                checkConstantLines.Line1Value = line1Value;
                line1Value = checkConstantLines.Line1Value;
                checkConstantLines.Line2Value = line2Value;
                line2Value = checkConstantLines.Line2Value;
                checkConstantLines.Line3Value = line3Value;
                line3Value = checkConstantLines.Line3Value;
                checkConstantLines.Line4Value = line4Value;
                line4Value = checkConstantLines.Line4Value;

                if (cacheConstantLines != null)
                {
                    for (int idx = 0; idx < cacheConstantLines.Length; idx++)
                    {
                        if (Math.Abs(cacheConstantLines[idx].Line1Value - line1Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line2Value - line2Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line3Value - line3Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line4Value - line4Value) <= double.Epsilon && cacheConstantLines[idx].EqualsInput(input))
                        {
                            return(cacheConstantLines[idx]);
                        }
                    }
                }

                ConstantLines indicator = new ConstantLines();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input      = input;
                indicator.Line1Value = line1Value;
                indicator.Line2Value = line2Value;
                indicator.Line3Value = line3Value;
                indicator.Line4Value = line4Value;
                Indicators.Add(indicator);
                indicator.SetUp();

                ConstantLines[] tmp = new ConstantLines[cacheConstantLines == null ? 1 : cacheConstantLines.Length + 1];
                if (cacheConstantLines != null)
                {
                    cacheConstantLines.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheConstantLines  = tmp;
                return(indicator);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Plots lines at user defined values. Lines with values of zero will not plot.
        /// </summary>
        /// <returns></returns>
        public ConstantLines ConstantLines(Data.IDataSeries input, double line1Value, double line2Value, double line3Value, double line4Value)
        {
            if (cacheConstantLines != null)
                for (int idx = 0; idx < cacheConstantLines.Length; idx++)
                    if (Math.Abs(cacheConstantLines[idx].Line1Value - line1Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line2Value - line2Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line3Value - line3Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line4Value - line4Value) <= double.Epsilon && cacheConstantLines[idx].EqualsInput(input))
                        return cacheConstantLines[idx];

            lock (checkConstantLines)
            {
                checkConstantLines.Line1Value = line1Value;
                line1Value = checkConstantLines.Line1Value;
                checkConstantLines.Line2Value = line2Value;
                line2Value = checkConstantLines.Line2Value;
                checkConstantLines.Line3Value = line3Value;
                line3Value = checkConstantLines.Line3Value;
                checkConstantLines.Line4Value = line4Value;
                line4Value = checkConstantLines.Line4Value;

                if (cacheConstantLines != null)
                    for (int idx = 0; idx < cacheConstantLines.Length; idx++)
                        if (Math.Abs(cacheConstantLines[idx].Line1Value - line1Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line2Value - line2Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line3Value - line3Value) <= double.Epsilon && Math.Abs(cacheConstantLines[idx].Line4Value - line4Value) <= double.Epsilon && cacheConstantLines[idx].EqualsInput(input))
                            return cacheConstantLines[idx];

                ConstantLines indicator = new ConstantLines();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.Line1Value = line1Value;
                indicator.Line2Value = line2Value;
                indicator.Line3Value = line3Value;
                indicator.Line4Value = line4Value;
                Indicators.Add(indicator);
                indicator.SetUp();

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