Exemplo n.º 1
0
        /// <summary>
        /// Возможно ли обработать входное значение.
        /// </summary>
        /// <param name="input">Входное значение.</param>
        /// <returns><see langword="true"/>, если возможно, иначе, <see langword="false"/>.</returns>
        public virtual bool CanProcess(IIndicatorValue input)
        {
            if (_valueType == null)
            {
                throw new InvalidOperationException(LocalizedStrings.Str909);
            }

            return(input.IsSupport(_valueType));
        }
Exemplo n.º 2
0
        /// <summary>
        /// To handle the input value.
        /// </summary>
        /// <param name="input">The input value.</param>
        /// <returns>The resulting value.</returns>
        protected override IIndicatorValue OnProcess(IIndicatorValue input)
        {
            var newValue = input.IsSupport(typeof(Candle)) ? input.GetValue <Candle>().HighPrice : input.GetValue <decimal>();

            var lastValue = Buffer.Count == 0 ? newValue : this.GetCurrentValue();

            // добавляем новое начало
            if (input.IsFinal)
            {
                Buffer.Add(newValue);
            }

            if (newValue > lastValue)
            {
                // Новое значение и есть экстремум
                lastValue = newValue;
            }

            if (Buffer.Count > Length)
            {
                var first = Buffer[0];

                // удаляем хвостовое значение
                if (input.IsFinal)
                {
                    Buffer.RemoveAt(0);
                }

                // удаляется экстремум, для поиска нового значения необходим проход по всему буфферу
                if (first == lastValue && lastValue != newValue)
                {
                    // ищем новый экстремум
                    lastValue = Buffer.Aggregate(newValue, (current, t) => Math.Max(t, current));
                }
            }

            return(new DecimalIndicatorValue(this, lastValue));
        }