public SMACrossEvent(int capacity, int firstSMAPeriod, int secondSMAPeriod, Action crossed) : base(capacity) { _sma1 = new SMACalculator(capacity, firstSMAPeriod); _sma2 = new SMACalculator(capacity, secondSMAPeriod); _maxPeriod = Math.Max(firstSMAPeriod, secondSMAPeriod); _crossed = crossed; }
public void CanCalculateSMA() { List <double> _shortPrices = new List <double> { 11, 12, 13, 14, 15, 16, 17 }; double[] smas = SMACalculator.CalculateSMA(5, _shortPrices.ToArray()); Assert.IsTrue(smas.Length == 3); Assert.IsTrue(smas[0].AlmostEqual(13.0)); Assert.IsTrue(smas[1].AlmostEqual(14)); Assert.IsTrue(smas[2].AlmostEqual(15)); }
public Indicator AnalyzeData(DataState state) { double[] closePrices = _analyseRepo.LoadClosePriceBySymbol(state.Symbol, true).ToArray(); double[] sma5Values = SMACalculator.CalculateSMA(5, closePrices); double[] sma10Values = SMACalculator.CalculateSMA(10, closePrices); double[] sma20Values = SMACalculator.CalculateSMA(20, closePrices); double[] sma50Values = SMACalculator.CalculateSMA(50, closePrices); double[] sma200Values = SMACalculator.CalculateSMA(200, closePrices); SMA value = new SMA(); value.Symbol = state.Symbol; value.Date = state.Last.Value; value.SMA5 = AlgorithmHelper.GetLast(sma5Values); value.SMA10 = AlgorithmHelper.GetLast(sma10Values); value.SMA20 = AlgorithmHelper.GetLast(sma20Values); value.SMA50 = AlgorithmHelper.GetLast(sma50Values); value.SMA200 = AlgorithmHelper.GetLast(sma200Values); return(value.ToIndicator()); }