/// <summary> /// Initializes a new instance of the <see cref="NormalizedAverageTrueRange"/> class using the specified name and period. /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of the NATR</param> public NormalizedAverageTrueRange(string name, int period) : base(name) { _period = period; _tr = new TrueRange(name + "_TR"); _atr = new AverageTrueRange(name + "_ATR", period, MovingAverageType.Simple); }
/// <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> /// Initializes a new instance of the <see cref="UltimateOscillator"/> class using the specified parameters /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period1">The first period</param> /// <param name="period2">The second period</param> /// <param name="period3">The third period</param> public UltimateOscillator(string name, int period1, int period2, int period3) : base(name) { _period = Math.Max(Math.Max(period1, period2), period3); _trueRange = new TrueRange(name + "_TR"); _sumBuyingPressure1 = new Sum(name + "_BP1", period1); _sumBuyingPressure2 = new Sum(name + "_BP2", period2); _sumBuyingPressure3 = new Sum(name + "_BP3", period3); _sumTrueRange1 = new Sum(name + "_TR1", period1); _sumTrueRange2 = new Sum(name + "_TR2", period2); _sumTrueRange3 = new Sum(name + "_TR3", period3); }
/// <summary> /// Resets this indicator to its initial state /// </summary> public override void Reset() { base.Reset(); _previousInput = null; TrueRange.Reset(); DirectionalMovementPlus.Reset(); DirectionalMovementMinus.Reset(); SmoothedTrueRange.Reset(); SmoothedDirectionalMovementMinus.Reset(); SmoothedDirectionalMovementPlus.Reset(); PositiveDirectionalIndex.Reset(); NegativeDirectionalIndex.Reset(); }
/// <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> /// Resets this indicator to its initial state /// </summary> public override void Reset() { _smoother.Reset(); TrueRange.Reset(); base.Reset(); }