/// <summary> /// Calculates next RSI value from previous /// </summary> /// <param name="previousRSI">Previous RSI value</param> /// <param name="latestCandlestick">Last candlestick</param> /// <returns>Updated RSI value</returns> public virtual RSIValue CalculateNextValue(RSIValue previousRSI, Lib.Candlestick latestCandlestick) { if (null == latestCandlestick) { throw new ArgumentNullException("candlestick"); } return(CalculateNextValue(previousRSI, latestCandlestick.StartEndDifference)); }
/// <summary> /// Calculates next RSI value from previous /// </summary> /// <param name="previousRSI">Previous RSI value</param> /// <param name="latestDifference">Last difference</param> /// <returns>Updated RSI value</returns> public virtual RSIValue CalculateNextValue(RSIValue previousRSI, decimal latestDifference) { if (null == previousRSI) { throw new ArgumentNullException("previousRSI"); } return(new RSIValue( Math.Round(((previousRSI.AverageGain) * (NumberOfSamples - 1) + Math.Max(0, latestDifference)) / NumberOfSamples, PRECISION), Math.Round(((previousRSI.AverageLoss) * (NumberOfSamples - 1) - Math.Min(0, latestDifference)) / NumberOfSamples, PRECISION), PRECISION )); }