コード例 #1
0
        void DrawOrder(GraphicsWrapper g, ref PointF updatedImageDrawingPoint, Order order, float itemWidth, float itemMargin,
                       float yToXScaling, DataBar orderBarData, float lastBarX, bool drawOpening)
        {
            Image image     = _imageUp;
            Brush brush     = Brushes.Green;
            Pen   dashedPen = _buyDashedPen;
            Pen   pen       = Pens.GreenYellow;

            if (order.IsBuy == false)
            {
                image     = _imageDown;
                brush     = Brushes.Red;
                pen       = Pens.Red;
                dashedPen = _sellDashedPen;
            }

            if (drawOpening == false)
            {
                image = _imageCross;
            }

            if (order.OpenPrice.HasValue == false)
            {
                SystemMonitor.OperationError("Order with no open price assigned for drawing.", TracerItem.PriorityEnum.Low);
                return;
            }

            float price = (float)order.OpenPrice.Value;

            if (drawOpening == false)
            {
                if (order.ClosePrice.HasValue == false)
                {
                    return;
                }

                price = (float)order.ClosePrice.Value;
            }

            if (drawOpening && _showPendingOrdersTracing &&
                (order is ActiveOrder && order.State == OrderStateEnum.Executed) &&
                _dataProvider.Quotes.Bid.HasValue &&
                _dataProvider.Quotes.Ask.HasValue)
            {// Open orders tracking line.
                PointF point1    = new PointF(updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + price);
                float  sellPrice = (float)_dataProvider.Quotes.Bid;
                if (order.IsBuy == false)
                {
                    sellPrice = (float)_dataProvider.Quotes.Ask;
                }
                PointF point2 = new PointF(lastBarX - itemWidth / 2f, updatedImageDrawingPoint.Y + sellPrice);
                g.DrawLine(dashedPen, point1, point2);
            }

            //if (drawOpening && _showClosedOrdersTracing && order.IsOpen == false)
            //{// Closed order tracking.
            // Close order tracing is implemented in main draw function.
            //}

            if (_showOrderSpot)
            {
                PointF basePoint = new PointF(updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + price);
                float  height    = (yToXScaling * itemWidth);
                if (order.IsBuy == false)
                {
                    height = -height;
                }

                if (drawOpening)
                {
                    g.FillPolygon(brush, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y),
                                                        new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) });
                    g.DrawPolygon(Pens.White, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y),
                                                             new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) });

                    float drawToLeft  = (float)(1.5 * itemWidth);
                    float drawToRight = (float)(2.5 * itemWidth);

                    // Take profit level.
                    if (order.TakeProfit.HasValue &&
                        order.TakeProfit.Value != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X - drawToLeft, updatedImageDrawingPoint.Y + (float)order.TakeProfit,
                                   updatedImageDrawingPoint.X + drawToRight, updatedImageDrawingPoint.Y + (float)order.TakeProfit);

                        g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.TakeProfit,
                                   updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.TakeProfit - height);
                    }

                    // Stop loss level.
                    if (order.StopLoss.HasValue &&
                        order.StopLoss.Value != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X - drawToLeft, updatedImageDrawingPoint.Y + (float)order.StopLoss,
                                   updatedImageDrawingPoint.X + drawToRight, updatedImageDrawingPoint.Y + (float)order.StopLoss);

                        g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.StopLoss,
                                   updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.StopLoss + height);
                    }
                }
                else
                {
                    g.DrawRectangle(Pens.White, basePoint.X, basePoint.Y,
                                    itemWidth, yToXScaling * itemWidth);
                }
            }

            float imageHeight = 2 * (yToXScaling * itemWidth);

            if (_showOrderArrow)
            {
                float x      = updatedImageDrawingPoint.X - (itemWidth / 2f);
                float y      = updatedImageDrawingPoint.Y + (float)orderBarData.Low - (yToXScaling * itemWidth);
                float width  = 2 * itemWidth;
                float height = -imageHeight;
                GraphicsWrapper.NormalizedRectangle(ref x, ref y, ref width, ref height);
                RectangleF rectange = new RectangleF(x, y, width, height);

                // Draw up image.
                g.DrawImage(image, rectange.X, rectange.Y, rectange.Width, rectange.Height);

                if (order == _selectedOrder)
                {// This is selected order.
                    g.DrawRectangle(Pens.White, rectange);
                }

                _ordersArrows[order] = rectange;

                updatedImageDrawingPoint.Y -= 1.2f * imageHeight;
            }
        }