Exemple #1
0
        public List <IndicatorResult> Calculate(List <QuotesModel> quotes, MacdParams inputParams)
        {
            if (!Validate(quotes, inputParams))
            {
                return(null);
            }

            var slowEma   = new EMA().Calculate(quotes, inputParams.SlowEmaPeriod);
            var fastEma   = new EMA().Calculate(quotes, inputParams.FastEmaPeriod);
            var macdLine  = fastEma.Substract(slowEma);
            var signalEma = new EMA().Calculate(macdLine.AsQuotesModel(QuoteModelField.Close), inputParams.SignalEmaPeriod);
            var macdHist  = macdLine.Substract(signalEma);

            var result = macdHist.Select(c => new IndicatorResult(c.Date)
            {
                Value = c.Value
            }).ToList();

            return(result.OrderByDescending(r => r.Date).ToList());
        }
Exemple #2
0
        public List <IndicatorResult> Calculate(List <QuotesModel> quotes, int period)
        {
            if (!Validate(quotes, period))
            {
                return(null);
            }

            var ema       = new EMA();
            var emaResult = ema.Calculate(quotes, period);

            var initialMargin = quotes.Max(q => q.High - q.Low) / 2;
            var margin        = initialMargin;

            while (InsideChannel(emaResult, quotes, margin) > 89)
            {
                margin = margin + initialMargin * (decimal)0.1;
            }

            emaResult.ForEach(r => r.Value = r.Value + margin);

            return(emaResult.OrderByDescending(r => r.Date).ToList());
        }
Exemple #3
0
        public List <IndicatorResult> Calculate(List <QuotesModel> quotes, ImpulseSystemParams inputParams)
        {
            var macdHist    = new MACD().Calculate(quotes, inputParams.MacdParams);
            var ema         = new EMA().Calculate(quotes, inputParams.EmaPeriod);
            var impulseData = (from h in macdHist
                               join e in ema
                               on h.Date equals e.Date
                               select new ImpulseData {
                Date = h.Date, Histogram = h.Value, Ema = e.Value
            })
                              .ToList();

            var result = impulseData.AsImpulseSystemModel().OrderByDescending(r => r.Date).ToList();

            foreach (var quote in quotes)
            {
                var data = result.FirstOrDefault(i => i.Date == quote.Date);
                if (data != null)
                {
                    quote.Impulse = data.Value;
                }
            }
            return(result);
        }