/// <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) { Minimum.Update(time, input[LowIdx]); Maximum.Update(time, input[HighIdx]); if (!IsReady) { return(0); } var range = Maximum.Current.Value - Minimum.Current.Value; return(Math.Abs(range) < ZeroEpsilon ? 0 : -100.0d * (Maximum.Current.Value - input[CloseIdx]) / range); }
/// <summary> /// Creates a new AroonOscillator from the specified up/down periods. /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="upPeriod">The lookback period to determine the highest high for the AroonDown</param> /// <param name="downPeriod">The lookback period to determine the lowest low for the AroonUp</param> public AroonOscillator(string name, int upPeriod, int downPeriod) : base(name) { var max = new Maximum(name + "_Max", upPeriod + 1); AroonUp = new FunctionalIndicator(name + "_AroonUp", (time, input) => ComputeAroonUp(upPeriod, max, time, input), aroonUp => max.IsReady, () => max.Reset() ); var min = new Minimum(name + "_Min", downPeriod + 1); AroonDown = new FunctionalIndicator(name + "_AroonDown", (time, input) => ComputeAroonDown(downPeriod, min, time, input), aroonDown => min.IsReady, () => min.Reset() ); WarmUpPeriod = 1 + Math.Max(upPeriod, downPeriod); }
/// <inheritdoc /> public override void Reset() { base.Reset(); Maximum.Reset(); Delta.Reset(); }
/// <summary> /// Resets this indicator and both sub-indicators (Max and Min) /// </summary> public override void Reset() { Maximum.Reset(); Minimum.Reset(); base.Reset(); }
/// <summary> /// AroonUp = 100 * (period - {periods since max})/period /// </summary> /// <param name="upPeriod">The AroonUp period</param> /// <param name="max">A Maximum indicator used to compute periods since max</param> /// <param name="input">The next input data</param> /// <returns>The AroonUp value</returns> private static double ComputeAroonUp(int upPeriod, Maximum max, long time, DoubleArray input) { max.Update(time, input); return(100.0d * (upPeriod - max.PeriodsSinceMaximum) / upPeriod); }