Beispiel #1
0
        void CalcTrendLine(List <Rate> range, double pointSize, BarsPeriodType period)
        {
            if (range.Count == 0)
            {
                return;
            }
            var minutes = (range.Last().StartDate - range[0].StartDate).Duration().TotalMinutes;
            Func <TimeSpan, IEnumerable <double> > groupped = ts => range.GroupedDistinct(rate => rate.StartDate.AddMilliseconds(-rate.StartDate.Millisecond), g => g.Average(rate => rate.PriceAvg));
            var doubles = period == BarsPeriodType.t1 ? groupped(1.FromSeconds()).ToArray() : range.Select(r => r.PriceAvg).ToArray();

            if (doubles.Length < 2 && range.Count > 1)
            {
                doubles = groupped(1.FromSeconds()).ToArray();
            }
            var coeffs = doubles.Linear();

            this.Slope                = coeffs.LineSlope();
            this.Angle                = Slope.Angle(period == BarsPeriodType.t1 ? 1.0 / 60 : (int)period, pointSize);
            this.StDev                = doubles.StDevByRegressoin(coeffs) / pointSize;
            this.InterseptStart       = coeffs.RegressionValue(0);
            this.InterseptEnd         = coeffs.RegressionValue(doubles.Length - 1);
            this.DistanceByRegression = DistanceByHeightAndAngle(InterseptStart.Abs(InterseptEnd), Angle).Abs() / pointSize;
        }