/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="input">The input given to the indicator</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(TradeBar input) { _trueRange.Update(input); if (Samples == 1) { _previousInput = input; return(50m); } var buyingPressure = new IndicatorDataPoint { Value = input.Close - Math.Min(input.Low, _previousInput.Close) }; _sumBuyingPressure1.Update(buyingPressure); _sumBuyingPressure2.Update(buyingPressure); _sumBuyingPressure3.Update(buyingPressure); _sumTrueRange1.Update(_trueRange.Current); _sumTrueRange2.Update(_trueRange.Current); _sumTrueRange3.Update(_trueRange.Current); _previousInput = input; if (!IsReady) { return(50m); } var average1 = _sumBuyingPressure1 / _sumTrueRange1; var average2 = _sumBuyingPressure2 / _sumTrueRange2; var average3 = _sumBuyingPressure3 / _sumTrueRange3; return(100m * (4 * average1 + 2 * average2 + average3) / 7); }
/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="input">The input given to the indicator</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(TradeBar input) { // compute the true range and then send it to our smoother TrueRange.Update(input); _smoother.Update(input.Time, TrueRange); return(_smoother.Current.Value); }
/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="input">The input given to the indicator</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(TradeBar input) { TrueRange.Update(input); DirectionalMovementPlus.Update(input); DirectionalMovementMinus.Update(input); SmoothedTrueRange.Update(Current); SmoothedDirectionalMovementMinus.Update(Current); SmoothedDirectionalMovementPlus.Update(Current); if (_previousInput != null) { PositiveDirectionalIndex.Update(Current); NegativeDirectionalIndex.Update(Current); } var diff = Math.Abs(PositiveDirectionalIndex - NegativeDirectionalIndex); var sum = PositiveDirectionalIndex + NegativeDirectionalIndex; var value = sum == 0 ? 50 : ((_period - 1) * Current.Value + 100 * diff / sum) / _period; _previousInput = input; return(value); }
/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="input">The input given to the indicator</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(TradeBar input) { _tr.Update(input); if (!IsReady) { _atr.Update(input); return(input.Close != 0 ? _atr / input.Close * 100 : 0m); } if (Samples == _period + 1) { // first output value is SMA of TrueRange _atr.Update(input); _lastAtrValue = _atr; } else { // next TrueRange values are smoothed using Wilder's approach _lastAtrValue = (_lastAtrValue * (_period - 1) + _tr) / _period; } return(input.Close != 0 ? _lastAtrValue / input.Close * 100 : 0m); }