示例#1
0
 public void setPoints(int bar1, int y1, int bar2, int y2)
 {
     lr.clearPoints();
     this.bar1 = bar1;
     this.y1   = y1;
     this.bar2 = bar2;
     this.y2   = y2;
     lr.addPoint(interceptBar - bar1, y1);
     lr.addPoint(interceptBar - bar2, y2);
 }
示例#2
0
        public void AddBar(int bar)
        {
            switch (barsToUse)
            {
            case BarsToUse.Highs:
                lr.addPoint(bar - interceptBar, bars.High[bars.CurrentBar - bar]);
                break;

            case BarsToUse.Lows:
                lr.addPoint(bar - interceptBar, bars.Low[bars.CurrentBar - bar]);
                break;

            default:
            case BarsToUse.Middle:
                lr.addPoint(bar - interceptBar, model.Formula.Middle(bars, bars.CurrentBar - bar));
                break;
            }
        }
示例#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);
        }
        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.");
        }
示例#5
0
 public void addPoint2(int bar, int y)
 {
     lr2.addPoint(bar - interceptBar, y);
 }
示例#6
0
 public void addHigh(double bar)
 {
     lrHigh.addPoint(bar - interceptBar, bars.High[bars.CurrentBar - (int)bar]);
 }
示例#7
0
 public void addLow(double bar)
 {
     lrLow.addPoint(bar - interceptBar, bars.Low[bars.CurrentBar - (int)bar]);
 }
示例#8
0
 public void addPoint(int bar, double y)
 {
     lr.addPoint(bar - interceptBar, y);
 }
示例#9
0
 public void addBar(int bar)
 {
     lrHigh.addPoint(bar - interceptBar, bars.High[bars.CurrentBar - bar]);
     lrLow.addPoint(bar - interceptBar, bars.Low[bars.CurrentBar - bar]);
 }