예제 #1
0
        protected void DrawColorAreaItem(GraphicsWrapper g, ref PointF drawingPoint, float[] values, Pen pen, Brush fill,
                                         int index, int previousItemIndex, float itemWidth, float itemMargin)
        {
            float indexValue             = values[index];
            float previousItemIndexValue = values[previousItemIndex];

            int unificationCount = index - previousItemIndex;

            for (int i = previousItemIndex; i <= index; i++)
            {
                if (float.IsNaN(previousItemIndexValue))
                {
                    previousItemIndexValue = values[i];
                }
                else if (float.IsNaN(indexValue))
                {
                    indexValue = values[i];
                }
            }

            if (float.IsNaN(indexValue) || float.IsNaN(previousItemIndexValue))
            {// Failed to find reasonable values to draw.
                return;
            }

            if (fill != null)
            {
                g.FillPolygon(fill, new PointF[] {
                    drawingPoint,
                    new PointF(drawingPoint.X + (itemMargin + itemWidth) * unificationCount, drawingPoint.Y),
                    new PointF(drawingPoint.X + (itemMargin + itemWidth) * unificationCount, drawingPoint.Y + indexValue),
                    new PointF(drawingPoint.X, drawingPoint.Y + previousItemIndexValue)
                });
            }

            if (pen != null)
            {
                g.DrawLine(pen, drawingPoint.X, drawingPoint.Y + previousItemIndexValue,
                           drawingPoint.X + (itemMargin + itemWidth) * unificationCount, drawingPoint.Y + indexValue);
            }
        }
        protected void DrawColorAreaItem(GraphicsWrapper g, ref PointF drawingPoint, float[] values, Pen pen, Brush fill, 
            int index, int previousItemIndex, float itemWidth, float itemMargin)
        {
            float indexValue = values[index];
            float previousItemIndexValue = values[previousItemIndex];

            int unificationCount = index - previousItemIndex;

            for (int i = previousItemIndex; i <= index; i++)
            {
                if (float.IsNaN(previousItemIndexValue))
                {
                    previousItemIndexValue = values[i];
                } else if (float.IsNaN(indexValue))
                {
                    indexValue = values[i];
                }
            }

            if (float.IsNaN(indexValue) || float.IsNaN(previousItemIndexValue))
            {// Failed to find reasonable values to draw.
                return;
            }

            if (fill != null)
            {
                g.FillPolygon(fill, new PointF[] {
                    drawingPoint,
                    new PointF(drawingPoint.X + (itemMargin + itemWidth) * unificationCount, drawingPoint.Y),
                    new PointF(drawingPoint.X + (itemMargin + itemWidth) * unificationCount, drawingPoint.Y + indexValue),
                    new PointF(drawingPoint.X, drawingPoint.Y + previousItemIndexValue) });
            }

            if (pen != null)
            {
                g.DrawLine(pen, drawingPoint.X, drawingPoint.Y + previousItemIndexValue,
                    drawingPoint.X + (itemMargin + itemWidth) * unificationCount, drawingPoint.Y + indexValue);
            }
        }
        void DrawOrder(GraphicsWrapper g, ref PointF updatedImageDrawingPoint, Order order, float itemWidth, float itemMargin,
                       float yToXScaling, BarData 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;
            }

            float price = (float)order.OpenPrice;

            if (drawOpening == false)
            {
                price = (float)order.ClosePrice;
            }

            if (drawOpening && _showPendingOrdersTracing && order.IsOpen)
            {// Open orders tracking line.
                PointF point1    = new PointF(updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + price);
                float  sellPrice = (float)_dataProvider.Bid;
                if (order.IsBuy == false)
                {
                    sellPrice = (float)_dataProvider.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) });

                    // Take profit level.
                    if (double.IsInfinity(order.SourceTakeProfit) == false &&
                        double.IsNaN(order.SourceTakeProfit) == false &&
                        order.SourceTakeProfit != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit,
                                   updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit);

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

                    // Stop loss level.
                    if (double.IsInfinity(order.SourceStopLoss) == false &&
                        double.IsNaN(order.SourceStopLoss) == false &&
                        order.SourceStopLoss != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss,
                                   updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss);

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

            float imageHeight = 2 * (yToXScaling * itemWidth);

            if (_showOrderArrow)
            {
                // Draw up image.

                g.DrawImage(image, updatedImageDrawingPoint.X - (itemWidth / 2f), updatedImageDrawingPoint.Y +
                            (float)orderBarData.Low - (yToXScaling * itemWidth), 2 * itemWidth, -imageHeight);

                updatedImageDrawingPoint.Y -= 1.2f * imageHeight;
            }
        }
        void DrawOrder(GraphicsWrapper g, ref PointF updatedImageDrawingPoint, Order order, float itemWidth, float itemMargin,
            float yToXScaling, BarData 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;
            }

            float price = (float)order.OpenPrice;
            if (drawOpening == false)
            {
                price = (float)order.ClosePrice;
            }

            if (drawOpening && _showPendingOrdersTracing && order.IsOpen)
            {// Open orders tracking line.
                PointF point1 = new PointF(updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + price);
                float sellPrice = (float)_dataProvider.Bid;
                if (order.IsBuy == false)
                {
                    sellPrice = (float)_dataProvider.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) });

                    // Take profit level.
                    if (double.IsInfinity(order.SourceTakeProfit) == false
                        && double.IsNaN(order.SourceTakeProfit) == false
                        && order.SourceTakeProfit != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit,
                            updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit);

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

                    // Stop loss level.
                    if (double.IsInfinity(order.SourceStopLoss) == false
                        && double.IsNaN(order.SourceStopLoss) == false
                        && order.SourceStopLoss != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss,
                            updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss);

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

            }

            float imageHeight = 2 * (yToXScaling * itemWidth);
            if (_showOrderArrow)
            {
                // Draw up image.

                g.DrawImage(image, updatedImageDrawingPoint.X - (itemWidth / 2f), updatedImageDrawingPoint.Y +
                    (float)orderBarData.Low - (yToXScaling * itemWidth), 2 * itemWidth, -imageHeight);

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