/// <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(IBaseDataBar input) { var typicalPrice = (input.High + input.Low + input.Close) / 3.0m; TypicalPriceAverage.Update(input.Time, typicalPrice); TypicalPriceMeanDeviation.Update(input.Time, typicalPrice); // compare this to zero, since if the mean deviation is very small we can get // precision errors due to non-floating point math var weightedMeanDeviation = _k * TypicalPriceMeanDeviation.Current; if (weightedMeanDeviation == 0.0m) { return(0.0m); } return((typicalPrice - TypicalPriceAverage) / weightedMeanDeviation); }
/// <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) { var typicalPrice = (input[HighIdx] + input[LowIdx] + input[CloseIdx]) / 3.0d; TypicalPriceAverage.Update(time, typicalPrice); TypicalPriceMeanDeviation.Update(time, typicalPrice); // compare this to zero, since if the mean deviation is very small we can get // precision errors due to non-floating point math var weightedMeanDeviation = _k * TypicalPriceMeanDeviation.Current; if (weightedMeanDeviation == 0.0d) { return(0.0d); } return((typicalPrice - TypicalPriceAverage.Current.Value) / weightedMeanDeviation); }
/// <summary> /// Resets this indicator to its initial state /// </summary> public override void Reset() { TypicalPriceAverage.Reset(); TypicalPriceMeanDeviation.Reset(); base.Reset(); }