Пример #1
0
        /// <inheritdoc />
        public IList <Signal> GenerateSignals(IList <Price> prices)
        {
            var signals = new List <Signal>();
            var values  = Calculate(prices);
            var trend   = MovingAverageHelper.ExpotentialMovingAverage(prices, Term);

            for (int i = Term; i < prices.Count; i++)
            {
                if (prices[i].ClosePrice > trend[i - Term + 1].Value && trend[i - Term].Value < trend[i - Term + 1].Value && values[i - Term].Value < 0)
                {
                    signals.Add(new Signal(SignalAction.Buy)
                    {
                        Date = prices[i].Date
                    });
                }
                else if (prices[i].ClosePrice <trend[i - Term + 1].Value && trend[i - Term].Value> trend[i - Term + 1].Value && values[i - Term].Value > 0)
                {
                    signals.Add(new Signal(SignalAction.Sell)
                    {
                        Date = prices[i].Date
                    });
                }
            }
            return(signals);
        }
        /// <inheritdoc />
        public IList <IndicatorValue> Calculate(IList <Price> prices)
        {
            var longEma    = MovingAverageHelper.ExpotentialMovingAverage(prices, LongTerm);
            var shortEma   = MovingAverageHelper.ExpotentialMovingAverage(prices, ShortTerm);
            var macdLine   = SubstractLongEmaFromShortEma(shortEma, longEma);
            var signalLine = MovingAverageHelper.ExpotentialMovingAverage(macdLine, SignalTerm);

            return(PrepareResult(macdLine, signalLine));
        }
Пример #3
0
        public void Moving_averages_should_ignore_holes_between_dates()
        {
            var data = new List <Price>
            {
                new Price {
                    ClosePrice = 10, Date = new DateTime(2016, 10, 1)
                },
                new Price {
                    ClosePrice = 20, Date = new DateTime(2016, 10, 4)
                }
            };
            var ema = MovingAverageHelper.ExpotentialMovingAverage(data, 1);

            ema.Count.Should().Be(2);
        }
Пример #4
0
 /// <inheritdoc />
 public IList <IndicatorValue> Calculate(IList <Price> prices)
 {
     return(MovingAverageHelper.ExpotentialMovingAverage(prices, Term));
 }
Пример #5
0
        public void ExpotentialMovingAverage12Test()
        {
            var actual12DaysEma = MovingAverageHelper.ExpotentialMovingAverage(MacdData.HistoricalData, 12);

            actual12DaysEma.ShouldAllBeEquivalentTo(MacdData.Ema12DaysResults);
        }