示例#1
0
        public void Calculate()
        {
            isCalculated = true;
            lrHigh.calculate();
            double mult = (1 - (1 / (double)lrHigh.Coord.Count));

            lrHigh.Slope = lrHigh.Slope * mult;
            lrLow.calculate();
            mult        = (1 - (1 / (double)lrLow.Coord.Count));
            lrLow.Slope = lrLow.Slope * mult;
            if (!isDirectionSet)
            {
                Trend highDirection = lrHigh.Slope > 0 ? Trend.Up : lrHigh.Slope < 0 ? Trend.Down : Trend.Flat;
                Trend lowDirection  = lrLow.Slope > 0 ? Trend.Up : lrLow.Slope < 0 ? Trend.Down : Trend.Flat;
                if (highDirection == lowDirection)
                {
                    direction = highDirection;
                }
                else
                {
                    direction = Trend.None;
                }
                isDirectionSet = true;
            }
        }
示例#2
0
 public void Calculate()
 {
     isCalculated = true;
     lr.calculate();
     lr.Slope  = Math.Min(maxSlope, lr.Slope);
     lr.Slope  = Math.Max(minSlope, lr.Slope);
     direction = lr.Slope > 0 ? Trend.Up : lr.Slope < 0 ? Trend.Down : Trend.Flat;
 }
示例#3
0
        public double CheckNewSlope(ChartPoint point)
        {
            LinearRegression tempLR = new LinearRegression(lr.Coord);

            tempLR.addPoint(point.Bar - interceptBar, point.Y);
            tempLR.calculate();
            double mult = (1 - (1 / (double)tempLR.Coord.Count));

            tempLR.Slope = tempLR.Slope * mult;
            return(tempLR.Slope);
        }
示例#4
0
        public void Calculate()
        {
            if (direction == Trend.None)
            {
                throw new ApplicationException("Must set direction before calculate.");
            }
            isCalculated = true;
            switch (direction)
            {
            case Trend.Down:
                lrHigh.calculate();
//					double mult = (1 - (1 / (double) lrHigh.Coord.Count));
//					lrHigh.Slope = lrHigh.Slope * mult;
                break;

            case Trend.Up:
                lrLow.calculate();
//					mult = (1 - (1 / (double) lrLow.Coord.Count));
//					lrLow.Slope = lrLow.Slope * mult;
                break;
            }
        }
        public void TestMethod()
        {
            LinearRegression lr = new LinearRegression();

            lr.addPoint(1.0, 2.6);
            lr.addPoint(2.3, 2.8);
            lr.addPoint(3.1, 3.1);
            lr.addPoint(4.8, 4.7);
            lr.addPoint(5.6, 5.1);
            lr.addPoint(6.3, 5.3);

            lr.calculate();
            Assert.IsTrue(0.5842 == Math.Round(lr.Slope * 10000) / 10000, "Linear Regression returned wrong slope.");
            Assert.IsTrue(1.6842 == Math.Round(lr.Intercept * 10000) / 10000, "Linear Regression wrong intercept.");
            Assert.IsTrue(0.9741 == Math.Round(lr.Correlation * 10000) / 10000, "Linear Regression returned wrong correlation.");

            // Should be able to repeat the test and it still work
            // since a reset() was added to calculate.
            lr.calculate();
            Assert.IsTrue(0.5842 == Math.Round(lr.Slope * 10000) / 10000, "Linear Regression returned wrong slope.");
            Assert.IsTrue(1.6842 == Math.Round(lr.Intercept * 10000) / 10000, "Linear Regression wrong intercept.");
            Assert.IsTrue(0.9741 == Math.Round(lr.Correlation * 10000) / 10000, "Linear Regression returned wrong correlation.");
        }
示例#6
0
        public void Calculate()
        {
            isCalculated = true;
            lr.calculate();
            if (!Calculate2())
            {
//				double mult = (1 - (1 / (double) lr.Coord.Count));
//				lr.Slope = lr.Slope * mult;
            }
            if (!isDirectionSet)
            {
                direction      = lr.Slope > 0 ? Trend.Up : lr.Slope < 0 ? Trend.Down : Trend.Flat;
                isDirectionSet = true;
            }
        }
示例#7
0
 private bool Calculate2()
 {
     if (lr2.Coord.Count > 1)
     {
         lr2.calculate();
         double newSlope = lr2.Slope;                 // (lr.Slope + lr2.Slope)/2;
         if (IsUp && newSlope > lr.Slope)
         {
             lr.Slope = newSlope;
             return(true);
         }
         if (IsDown && newSlope < lr.Slope)
         {
             lr.Slope = newSlope;
             return(true);
         }
     }
     return(false);
 }
示例#8
0
 public void calculate()
 {
     lr.calculate();
 }