Esempio n. 1
0
        private static void DrawDealEventShape(string title, Graphics g,
                                               Font font, Pen pen, Brush foreBrush, Brush backBrush, PointD center, int diam, DealEventSymbol symb)
        {
            if (symb == DealEventSymbol.Circle)
            {
                // усики
                g.DrawLine(pen,
                           (int)center.X - diam * 2, (int)center.Y,
                           (int)center.X - diam / 2, (int)center.Y);
                g.DrawLine(pen,
                           (int)center.X + diam / 2, (int)center.Y,
                           (int)center.X + diam * 2, (int)center.Y);
                // кружок с заливкой
                g.FillEllipse(backBrush, (int)center.X - diam / 2, (int)center.Y - diam / 2, diam, diam);
                g.DrawEllipse(pen, (int)center.X - diam / 2, (int)center.Y - diam / 2, diam, diam);
            }
            if (symb == DealEventSymbol.Diamond)
            {
                var points = new[]
                {
                    new Point((int)center.X - diam / 2, (int)center.Y),
                    new Point((int)center.X, (int)center.Y - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y),
                    new Point((int)center.X, (int)center.Y + diam / 2)
                };
                g.FillPolygon(backBrush, points);
                g.DrawPolygon(pen, points);
            }

            if (symb == DealEventSymbol.TagUp)
            {
                diam -= 2;
                var points = new[]
                {
                    new Point((int)center.X + diam / 2, (int)center.Y - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y + diam / 2),
                    new Point((int)center.X - diam / 2, (int)center.Y + diam / 2),
                    new Point((int)center.X - diam / 2, (int)center.Y - diam / 2),
                    new Point((int)center.X, (int)center.Y - (int)(diam / 1.25))
                };
                g.FillPolygon(backBrush, points);
                g.DrawPolygon(pen, points);
            }

            if (symb == DealEventSymbol.TagDown)
            {
                diam -= 2;
                var points = new[]
                {
                    new Point((int)center.X - diam / 2, (int)center.Y + diam / 2),
                    new Point((int)center.X - diam / 2, (int)center.Y - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y + diam / 2),
                    new Point((int)center.X, (int)center.Y + (int)(diam / 1.25))
                };
                g.FillPolygon(backBrush, points);
                g.DrawPolygon(pen, points);
            }

            g.DrawString(title, font, foreBrush, (float)center.X, (float)center.Y,
                         new StringFormat {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
            });
        }
Esempio n. 2
0
 ///// <summary>
 ///// связать пунктирными дугами локированные сделки
 ///// </summary>
 //private void ConnectLockedDeals(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 //{
 //    if (!LinkLockingDeals) return;
 //    var pens = new[]
 //                   {
 //                       new Pen(Color.Green) { DashStyle = DashStyle.Dot },
 //                       new Pen(Color.Red) { DashStyle = DashStyle.Dot },
 //                       new Pen(Color.Blue) { DashStyle = DashStyle.Dot },
 //                       new Pen(Color.Purple) { DashStyle = DashStyle.Dot },
 //                       new Pen(Color.Black) { DashStyle = DashStyle.Dot }
 //                   };
 //    // - 1 - разбить на подмножества по принадлежности к серии
 //    var lockLists = new Dictionary<int, List<Position>>();
 //    foreach (var deal in deals)
 //    {
 //        if (deal.LockingSeriesID == 0) continue;
 //        if (lockLists.ContainsKey(deal.LockingSeriesID))
 //            lockLists[deal.LockingSeriesID].Add(deal);
 //        else
 //            lockLists.Add(deal.LockingSeriesID, new List<IVirtualDeal> { deal });
 //    }
 //    // - 2 - упорядочить каждую серию по времени открытия
 //    foreach (var list in lockLists.Values)
 //    {
 //        list.Sort((a, b) => a.EntryTime > b.EntryTime ? 1 : a.EntryTime == b.EntryTime ? 0 : -1);
 //    }
 //    // - 3 - соединить дугами
 //    var bendCurveUp = true;
 //    var penIndex = 0;
 //    foreach (var list in lockLists.Values)
 //    {
 //        for (var i = 1; i < list.Count; i++)
 //        {
 //            ConnectLockedPair(list[i], list[i - 1], g, pens[penIndex], worldRect, canvasRect, bendCurveUp);
 //            bendCurveUp = !bendCurveUp;
 //        }
 //        penIndex++;
 //        if (penIndex >= pens.Length) penIndex = 0;
 //    }
 //}
 ///// <summary>
 ///// связать две локированные сделки
 ///// </summary>        
 //private void ConnectLockedPair(IVirtualDeal a, IVirtualDeal b, Graphics g, Pen p,
 //    RectangleD worldRect, Rectangle canvasRect, bool bendUp)
 //{
 //    double chartX = Chart.CandleRange.GetXCoord(a.EntryTime);
 //    var centerA = Conversion.WorldToScreen(new PointD(chartX, (double)a.EntryPrice), worldRect, canvasRect);
 //    chartX = Chart.CandleRange.GetXCoord(b.EntryTime);
 //    var centerB = Conversion.WorldToScreen(new PointD(chartX, (double)b.EntryPrice), worldRect, canvasRect);
 //    var cX = (int)(centerA.X + centerB.X)/2;
 //    var abLen = (centerA.X - centerB.X)*(centerA.X - centerB.X)
 //                + (centerA.Y - centerB.Y)*(centerA.Y - centerB.Y);
 //    abLen = Math.Sqrt(abLen);
 //    var cY = bendUp
 //                 ? (int) (Math.Min(centerA.Y, centerB.Y) + abLen/2)
 //                 : (int) (Math.Max(centerA.Y, centerB.Y) - abLen/2);
 //    var points = new []
 //                     {   new Point((int) centerA.X, (int) centerA.Y),
 //                         new Point(cX, cY),
 //                         new Point((int) centerB.X, (int) centerB.Y) };
 //    g.DrawCurve(p, points);
 //}
 private void DrawDealEvent(DateTime time, float price, string title, Graphics g, 
     RectangleD worldRect, Rectangle canvasRect,
     Font font, Pen pen, Brush foreBrush, Brush backBrush, DealEventSymbol smb)
 {
     double chartX = Chart.CandleRange.GetXCoord(time);
     var center = Conversion.WorldToScreen(new PointD(chartX, price), worldRect, canvasRect);
     var sz = g.MeasureString(title, font);
     var diam = (int)Math.Max(sz.Width, sz.Height) + 1;
     DrawDealEventShape(title, g, font, pen, foreBrush, backBrush, center, diam, smb);
 }
Esempio n. 3
0
        ///// <summary>
        ///// связать пунктирными дугами локированные сделки
        ///// </summary>
        //private void ConnectLockedDeals(Graphics g, RectangleD worldRect, Rectangle canvasRect)
        //{
        //    if (!LinkLockingDeals) return;
        //    var pens = new[]
        //                   {
        //                       new Pen(Color.Green) { DashStyle = DashStyle.Dot },
        //                       new Pen(Color.Red) { DashStyle = DashStyle.Dot },
        //                       new Pen(Color.Blue) { DashStyle = DashStyle.Dot },
        //                       new Pen(Color.Purple) { DashStyle = DashStyle.Dot },
        //                       new Pen(Color.Black) { DashStyle = DashStyle.Dot }
        //                   };
        //    // - 1 - разбить на подмножества по принадлежности к серии
        //    var lockLists = new Dictionary<int, List<Position>>();
        //    foreach (var deal in deals)
        //    {
        //        if (deal.LockingSeriesID == 0) continue;
        //        if (lockLists.ContainsKey(deal.LockingSeriesID))
        //            lockLists[deal.LockingSeriesID].Add(deal);
        //        else
        //            lockLists.Add(deal.LockingSeriesID, new List<IVirtualDeal> { deal });
        //    }
        //    // - 2 - упорядочить каждую серию по времени открытия
        //    foreach (var list in lockLists.Values)
        //    {
        //        list.Sort((a, b) => a.EntryTime > b.EntryTime ? 1 : a.EntryTime == b.EntryTime ? 0 : -1);
        //    }
        //    // - 3 - соединить дугами
        //    var bendCurveUp = true;
        //    var penIndex = 0;
        //    foreach (var list in lockLists.Values)
        //    {
        //        for (var i = 1; i < list.Count; i++)
        //        {
        //            ConnectLockedPair(list[i], list[i - 1], g, pens[penIndex], worldRect, canvasRect, bendCurveUp);
        //            bendCurveUp = !bendCurveUp;
        //        }
        //        penIndex++;
        //        if (penIndex >= pens.Length) penIndex = 0;
        //    }
        //}
        ///// <summary>
        ///// связать две локированные сделки
        ///// </summary>
        //private void ConnectLockedPair(IVirtualDeal a, IVirtualDeal b, Graphics g, Pen p,
        //    RectangleD worldRect, Rectangle canvasRect, bool bendUp)
        //{
        //    double chartX = Chart.CandleRange.GetXCoord(a.EntryTime);
        //    var centerA = Conversion.WorldToScreen(new PointD(chartX, (double)a.EntryPrice), worldRect, canvasRect);
        //    chartX = Chart.CandleRange.GetXCoord(b.EntryTime);
        //    var centerB = Conversion.WorldToScreen(new PointD(chartX, (double)b.EntryPrice), worldRect, canvasRect);
        //    var cX = (int)(centerA.X + centerB.X)/2;
        //    var abLen = (centerA.X - centerB.X)*(centerA.X - centerB.X)
        //                + (centerA.Y - centerB.Y)*(centerA.Y - centerB.Y);
        //    abLen = Math.Sqrt(abLen);
        //    var cY = bendUp
        //                 ? (int) (Math.Min(centerA.Y, centerB.Y) + abLen/2)
        //                 : (int) (Math.Max(centerA.Y, centerB.Y) - abLen/2);

        //    var points = new []
        //                     {   new Point((int) centerA.X, (int) centerA.Y),
        //                         new Point(cX, cY),
        //                         new Point((int) centerB.X, (int) centerB.Y) };
        //    g.DrawCurve(p, points);
        //}

        private void DrawDealEvent(DateTime time, float price, string title, Graphics g,
                                   RectangleD worldRect, Rectangle canvasRect,
                                   Font font, Pen pen, Brush foreBrush, Brush backBrush, DealEventSymbol smb)
        {
            double chartX = Chart.CandleRange.GetXCoord(time);
            var    center = Conversion.WorldToScreen(new PointD(chartX, price), worldRect, canvasRect);
            var    sz     = g.MeasureString(title, font);
            var    diam   = (int)Math.Max(sz.Width, sz.Height) + 1;

            DrawDealEventShape(title, g, font, pen, foreBrush, backBrush, center, diam, smb);
        }
Esempio n. 4
0
        private static void DrawDealEventShape(string title, Graphics g,
            Font font, Pen pen, Brush foreBrush, Brush backBrush, PointD center, int diam, DealEventSymbol symb)
        {
            if (symb == DealEventSymbol.Circle)
            {
                // усики
                g.DrawLine(pen,
                    (int)center.X - diam * 2, (int)center.Y,
                    (int)center.X - diam / 2, (int)center.Y);
                g.DrawLine(pen,
                    (int)center.X + diam / 2, (int)center.Y,
                    (int)center.X + diam * 2, (int)center.Y);
                // кружок с заливкой
                g.FillEllipse(backBrush, (int) center.X - diam/2, (int) center.Y - diam/2, diam, diam);
                g.DrawEllipse(pen, (int) center.X - diam/2, (int) center.Y - diam/2, diam, diam);
            }
            if (symb == DealEventSymbol.Diamond)
            {
                var points = new[]
                {
                    new Point((int)center.X - diam / 2, (int)center.Y),
                    new Point((int)center.X, (int)center.Y - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y),
                    new Point((int)center.X, (int)center.Y + diam / 2)
                };
                g.FillPolygon(backBrush, points);
                g.DrawPolygon(pen, points);
            }

            if (symb == DealEventSymbol.TagUp)
            {
                diam -= 2;
                var points = new[]
                {
                    new Point((int)center.X + diam / 2, (int)center.Y  - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y  + diam / 2),
                    new Point((int)center.X - diam / 2, (int)center.Y  + diam / 2),
                    new Point((int)center.X - diam / 2, (int)center.Y  - diam / 2),
                    new Point((int)center.X, (int)center.Y  - (int)(diam / 1.25))
                };
                g.FillPolygon(backBrush, points);
                g.DrawPolygon(pen, points);
            }

            if (symb == DealEventSymbol.TagDown)
            {
                diam -= 2;
                var points = new[]
                {
                    new Point((int)center.X - diam / 2, (int)center.Y  + diam / 2),
                    new Point((int)center.X - diam / 2, (int)center.Y  - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y  - diam / 2),
                    new Point((int)center.X + diam / 2, (int)center.Y  + diam / 2),
                    new Point((int)center.X, (int)center.Y  + (int)(diam / 1.25))
                };
                g.FillPolygon(backBrush, points);
                g.DrawPolygon(pen, points);
            }

            g.DrawString(title, font, foreBrush, (float)center.X, (float)center.Y,
                new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
        }