Пример #1
0
        /// <summary>
        /// This indicator returns 1 when we have n of consecutive bars up, otherwise returns 0. An up bar is defined as a bar where the close is above the open and the bars makes a higher high and a higher low. You can adjust the specific requirements with the indicator options.
        /// </summary>
        /// <returns></returns>
        public NBarsUp NBarsUp(Data.IDataSeries input, int barCount, bool barUp, bool higherHigh, bool higherLow)
        {
            if (cacheNBarsUp != null)
            {
                for (int idx = 0; idx < cacheNBarsUp.Length; idx++)
                {
                    if (cacheNBarsUp[idx].BarCount == barCount && cacheNBarsUp[idx].BarUp == barUp && cacheNBarsUp[idx].HigherHigh == higherHigh && cacheNBarsUp[idx].HigherLow == higherLow && cacheNBarsUp[idx].EqualsInput(input))
                    {
                        return(cacheNBarsUp[idx]);
                    }
                }
            }

            lock (checkNBarsUp)
            {
                checkNBarsUp.BarCount = barCount;
                barCount           = checkNBarsUp.BarCount;
                checkNBarsUp.BarUp = barUp;
                barUp = checkNBarsUp.BarUp;
                checkNBarsUp.HigherHigh = higherHigh;
                higherHigh             = checkNBarsUp.HigherHigh;
                checkNBarsUp.HigherLow = higherLow;
                higherLow = checkNBarsUp.HigherLow;

                if (cacheNBarsUp != null)
                {
                    for (int idx = 0; idx < cacheNBarsUp.Length; idx++)
                    {
                        if (cacheNBarsUp[idx].BarCount == barCount && cacheNBarsUp[idx].BarUp == barUp && cacheNBarsUp[idx].HigherHigh == higherHigh && cacheNBarsUp[idx].HigherLow == higherLow && cacheNBarsUp[idx].EqualsInput(input))
                        {
                            return(cacheNBarsUp[idx]);
                        }
                    }
                }

                NBarsUp indicator = new NBarsUp();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input      = input;
                indicator.BarCount   = barCount;
                indicator.BarUp      = barUp;
                indicator.HigherHigh = higherHigh;
                indicator.HigherLow  = higherLow;
                Indicators.Add(indicator);
                indicator.SetUp();

                NBarsUp[] tmp = new NBarsUp[cacheNBarsUp == null ? 1 : cacheNBarsUp.Length + 1];
                if (cacheNBarsUp != null)
                {
                    cacheNBarsUp.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheNBarsUp        = tmp;
                return(indicator);
            }
        }
Пример #2
0
        /// <summary>
        /// This indicator returns 1 when we have n of consecutive bars up, otherwise returns 0. An up bar is defined as a bar where the close is above the open and the bars makes a higher high and a higher low. You can adjust the specific requirements with the indicator options.
        /// </summary>
        /// <returns></returns>
        public NBarsUp NBarsUp(Data.IDataSeries input, int barCount, bool barUp, bool higherHigh, bool higherLow)
        {
            if (cacheNBarsUp != null)
                for (int idx = 0; idx < cacheNBarsUp.Length; idx++)
                    if (cacheNBarsUp[idx].BarCount == barCount && cacheNBarsUp[idx].BarUp == barUp && cacheNBarsUp[idx].HigherHigh == higherHigh && cacheNBarsUp[idx].HigherLow == higherLow && cacheNBarsUp[idx].EqualsInput(input))
                        return cacheNBarsUp[idx];

            lock (checkNBarsUp)
            {
                checkNBarsUp.BarCount = barCount;
                barCount = checkNBarsUp.BarCount;
                checkNBarsUp.BarUp = barUp;
                barUp = checkNBarsUp.BarUp;
                checkNBarsUp.HigherHigh = higherHigh;
                higherHigh = checkNBarsUp.HigherHigh;
                checkNBarsUp.HigherLow = higherLow;
                higherLow = checkNBarsUp.HigherLow;

                if (cacheNBarsUp != null)
                    for (int idx = 0; idx < cacheNBarsUp.Length; idx++)
                        if (cacheNBarsUp[idx].BarCount == barCount && cacheNBarsUp[idx].BarUp == barUp && cacheNBarsUp[idx].HigherHigh == higherHigh && cacheNBarsUp[idx].HigherLow == higherLow && cacheNBarsUp[idx].EqualsInput(input))
                            return cacheNBarsUp[idx];

                NBarsUp indicator = new NBarsUp();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.BarCount = barCount;
                indicator.BarUp = barUp;
                indicator.HigherHigh = higherHigh;
                indicator.HigherLow = higherLow;
                Indicators.Add(indicator);
                indicator.SetUp();

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