Esempio n. 1
0
 /// <summary>
 /// Check if (X,Y) in the segment os
 /// </summary>
 /// <param name="X"></param>
 /// <param name="Y"></param>
 /// <param name="os"></param>
 /// <param name="PenWidth"></param>
 /// <returns></returns>
 public bool InLineSegment(int X, int Y, ObjectSegment os, int PenWidth)
 {
     return(InLineSegment(X, Y, os.op1, os.op2, PenWidth));
 }
Esempio n. 2
0
 public virtual void Add(ObjectSegment os)
 {
     base.List.Add(os);
 }
Esempio n. 3
0
 public virtual void Add(ObjectSegment os)
 {
     this.List.Add(os);
 }
Esempio n. 4
0
        public override void CalcPoint()
        {
            if (Area.FormulaDataArray.Count == 0)
            {
                return;
            }
            fd = Area.FormulaDataArray[0];
            //IDataProvider idp = Manager.Canvas.BackChart.DataProvider;
            //double[] dd = idp["DATE"];
            FormulaChart BackChart = Manager.Canvas.Chart;
            int          i1        = 0;
            int          i2        = 1;

            if (ControlPoints[0].X > ControlPoints[1].X)
            {
                i1 = 1;
                i2 = 0;
            }
            //Bar1 = FormulaChart.FindIndex(dd,ControlPoints[i1].X);
            //Bar2 = FormulaChart.FindIndex(dd,ControlPoints[i2].X);
            Bar1 = BackChart.DateToIndex(ControlPoints[i1].X);
            Bar2 = BackChart.DateToIndex(ControlPoints[i2].X);

            if (regressionType != RegressionType.UpDownTrend)
            {
                FormulaBase.CalcLinearRegression(fd, Bar2, Bar2 - Bar1, out A, out B);
            }
            else
            {
                A = ControlPoints[i1].Y;
                B = (ControlPoints[i2].Y - ControlPoints[i1].Y) / (Bar2 - Bar1);
            }

            ObjectPoint opStart = ControlPoints[i1];
            ObjectPoint opEnd   = ControlPoints[i2];

            opStart.Y = A;
            opEnd.Y   = A + B * (Bar2 - Bar1);

            scLines.Clear();
            if (centerLine)
            {
                scLines.Add(opStart, opEnd);
            }
            float Delta;

            if (regressionType == RegressionType.Channel ||
                regressionType == RegressionType.AsynChannel ||
                regressionType == RegressionType.UpDownTrend)
            {
                float dtUp   = CalcDelta(fd, A, B, Bar1, Bar2, "H", true);
                float dtDown = CalcDelta(fd, A, B, Bar1, Bar2, "L", false);
                if (regressionType == RegressionType.Channel)
                {
                    Delta = Math.Max(Math.Abs(dtUp), Math.Abs(dtDown));
                }
                else
                {
                    Delta = -dtUp;
                }
                if (upLine)
                {
                    AddLine(opStart, opEnd, Delta);
                }

                if (regressionType != RegressionType.Channel)
                {
                    Delta = dtDown;
                }
                if (downLine)
                {
                    AddLine(opStart, opEnd, -Delta);
                }
            }
            else if (regressionType == RegressionType.StdChannel ||
                     regressionType == RegressionType.StdErrorChannel)
            {
                Delta = Std(regressionType == RegressionType.StdErrorChannel);
                AddLine(opStart, opEnd, Delta);
                AddLine(opStart, opEnd, -Delta);
            }

            pfStart = new PointF[scLines.Count];
            pfEnd   = new PointF[scLines.Count];
            for (int j = 0; j < scLines.Count; j++)
            {
                ObjectSegment os = scLines[j];
                if (!double.IsNaN(os.op1.Y) && !double.IsNaN(os.op2.Y))
                {
                    pfStart[j] = ToPointF(os.op1);
                    pfEnd[j]   = ToPointF(os.op2);
                }
                else
                {
                    pfStart[j] = PointF.Empty;
                    pfEnd[j]   = PointF.Empty;
                }
            }
            OpenStartEnd(openStart, openEnd);
        }
        public override void CalcPoint()
        {
            float num3;

            this.fd = base.Area.FormulaDataArray[0];
            double[] dd    = base.Manager.Canvas.BackChart.DataProvider["DATE"];
            int      index = 0;
            int      num2  = 1;

            if (base.ControlPoints[0].X > base.ControlPoints[1].X)
            {
                index = 1;
                num2  = 0;
            }
            this.Bar1 = FormulaChart.FindIndex(dd, base.ControlPoints[index].X);
            this.Bar2 = FormulaChart.FindIndex(dd, base.ControlPoints[num2].X);
            if (this.regressionType != Easychart.Finance.Objects.RegressionType.UpDownTrend)
            {
                FormulaBase.CalcLinearRegression(this.fd, this.Bar2, this.Bar2 - this.Bar1, out this.A, out this.B);
            }
            else
            {
                this.A = base.ControlPoints[index].Y;
                this.B = (base.ControlPoints[num2].Y - base.ControlPoints[index].Y) / ((double)(this.Bar2 - this.Bar1));
            }
            ObjectPoint point  = base.ControlPoints[index];
            ObjectPoint point2 = base.ControlPoints[num2];

            point.Y  = this.A;
            point2.Y = this.A + (this.B * (this.Bar2 - this.Bar1));
            this.scLines.Clear();
            if (this.centerLine)
            {
                this.scLines.Add(point, point2);
            }
            if (((this.regressionType == Easychart.Finance.Objects.RegressionType.Channel) || (this.regressionType == Easychart.Finance.Objects.RegressionType.AsynChannel)) || (this.regressionType == Easychart.Finance.Objects.RegressionType.UpDownTrend))
            {
                float num4 = base.CalcDelta(this.fd, this.A, this.B, this.Bar1, this.Bar2, "H", true);
                float num5 = base.CalcDelta(this.fd, this.A, this.B, this.Bar1, this.Bar2, "L", false);
                if (this.regressionType == Easychart.Finance.Objects.RegressionType.Channel)
                {
                    num3 = Math.Max(Math.Abs(num4), Math.Abs(num5));
                }
                else
                {
                    num3 = -num4;
                }
                if (this.upLine)
                {
                    this.AddLine(point, point2, num3);
                }
                if (this.regressionType != Easychart.Finance.Objects.RegressionType.Channel)
                {
                    num3 = num5;
                }
                if (this.downLine)
                {
                    this.AddLine(point, point2, -num3);
                }
            }
            else if ((this.regressionType == Easychart.Finance.Objects.RegressionType.StdChannel) || (this.regressionType == Easychart.Finance.Objects.RegressionType.StdErrorChannel))
            {
                num3 = this.Std(this.regressionType == Easychart.Finance.Objects.RegressionType.StdErrorChannel);
                this.AddLine(point, point2, num3);
                this.AddLine(point, point2, -num3);
            }
            base.pfStart = new PointF[this.scLines.Count];
            base.pfEnd   = new PointF[this.scLines.Count];
            for (int i = 0; i < this.scLines.Count; i++)
            {
                ObjectSegment segment = this.scLines[i];
                if (!double.IsNaN(segment.op1.Y) && !double.IsNaN(segment.op2.Y))
                {
                    base.pfStart[i] = base.ToPointF(segment.op1);
                    base.pfEnd[i]   = base.ToPointF(segment.op2);
                    if (this.openStart)
                    {
                        base.ExpandLine(ref base.pfEnd[i], ref base.pfStart[i]);
                    }
                    if (this.openEnd)
                    {
                        base.ExpandLine(ref base.pfStart[i], ref base.pfEnd[i]);
                    }
                }
                else
                {
                    base.pfStart[i] = PointF.Empty;
                    base.pfEnd[i]   = PointF.Empty;
                }
            }
        }