Exemplo n.º 1
0
        /// <summary>
        ///      Computes the next value for this indicator from the given state.
        /// </summary>
        /// <param name="time"></param>
        /// <param name="input">The TradeBar to this indicator on this time step</param>
        /// <returns>A new value for this indicator</returns>
        protected override DoubleArray Forward(long time, DoubleArray input)
        {
            AverageTrueRange.Update(time, input);

            var typicalPrice = (input[HighIdx] + input[LowIdx] + input[CloseIdx]) / 3d;

            MiddleBand.Update(time, typicalPrice);

            // poke the upper/lower bands, they actually don't use the input, they compute
            // based on the ATR and the middle band
            LowerBand.Update(time, input);
            UpperBand.Update(time, input);
            return(MiddleBand);
        }
Exemplo n.º 2
0
        /// <summary>
        ///      Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="time"></param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override DoubleArray Forward(long time, DoubleArray input)
        {
            _tr.Update(time, input);

            if (!IsReady)
            {
                _atr.Update(time, input);
                return(input[CloseIdx] != 0 ? _atr / input[CloseIdx] * 100 : 0d);
            }

            if (Samples == _period + 1)
            {
                // first output value is SMA of TrueRange
                _atr.Update(time, input);
                _lastAtrValue = _atr;
            }
            else
            {
                // next TrueRange values are smoothed using Wilder's approach
                _lastAtrValue = (_lastAtrValue * (_period - 1) + _tr) / _period;
            }

            return(input[CloseIdx] != 0 ? _lastAtrValue / input[CloseIdx] * 100 : 0d);
        }