Esempio n. 1
0
        ///// <summary>
        ///// Helper method, draws histogram bars.
        ///// </summary>
        //protected void DrawHistogramBars(GraphicsWrapper g, Pen pen, Brush fill, int unitsUnification,
        //    RectangleF clippingRectangle, float itemWidth, float itemMargin, object tag)
        //{
        //    PointF drawingPoint = new PointF();

        //    int startIndex, endIndex;
        //    GetDrawingRangeIndecesFromClippingRectange(clippingRectangle, drawingPoint, unitsUnification, out startIndex, out endIndex, itemWidth, itemMargin);

        //    for (int i = startIndex + unitsUnification - 1; i < endIndex && i < MaximumIndex + unitsUnification - 1; i += unitsUnification)
        //    {
        //        int actualIndex = i;
        //        int actualPreviousIndex = i - unitsUnification;

        //        if (actualIndex >= MaximumIndex)
        //        {
        //            actualIndex = MaximumIndex - 1;
        //        }

        //        DrawHistogramBar(g, ref drawingPoint, pen, fill, actualIndex, actualPreviousIndex,
        //            itemWidth, itemMargin, unitsUnification, tag);

        //        drawingPoint.X = i * (itemMargin + itemWidth);
        //    }
        //}

        //protected void DrawColoredArea(GraphicsWrapper g, Pen pen, Brush fill, int unitsUnification,
        //    RectangleF clippingRectangle, float itemWidth, float itemMargin, object tag)
        //{
        //    PointF drawingPoint = new PointF();

        //    int startIndex, endIndex;
        //    GetDrawingRangeIndecesFromClippingRectange(clippingRectangle, drawingPoint, unitsUnification, out startIndex, out endIndex, itemWidth, itemMargin);

        //    for (int i = startIndex + unitsUnification - 1; i < endIndex && i < MaximumIndex + unitsUnification - 1; i += unitsUnification)
        //    {
        //        int actualIndex = i;
        //        int actualPreviousIndex = i - unitsUnification;

        //        if (actualIndex >= MaximumIndex)
        //        {
        //            actualIndex = MaximumIndex - 1;
        //        }

        //        DrawColorAreaItem(g, ref drawingPoint, pen, fill, actualIndex,
        //            actualPreviousIndex, itemWidth, itemMargin, tag);

        //        drawingPoint.X = i * (itemMargin + itemWidth);
        //    }
        //}

        protected void DrawColorAreaItem(GraphicsWrapper g, ref PointF drawingPoint, Pen pen, Brush fill,
                                         int index, int previousItemIndex, float itemWidth, float itemMargin, object tag)
        {
            float indexValue             = GetDrawingValueAt(index, tag);
            float previousItemIndexValue = GetDrawingValueAt(previousItemIndex, tag);

            int unificationCount = index - previousItemIndex;

            for (int i = previousItemIndex; i <= index; i++)
            {
                if (float.IsNaN(previousItemIndexValue))
                {
                    previousItemIndexValue = GetDrawingValueAt(i, tag);
                }
                else if (float.IsNaN(indexValue))
                {
                    indexValue = GetDrawingValueAt(i, tag);
                }
            }

            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, 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;
            }
        }
Esempio n. 3
0
        public override void Draw(GraphicsWrapper g, PointF?mousePosition, RectangleF clippingRectangle, RectangleF drawingSpace)
        {
            if (Visible == false)
            {
                return;
            }

            if (_controlPoints.Count < 1)
            {
                return;
            }

            PointF point1 = _controlPoints[0];
            PointF point2;

            if (mousePosition.HasValue)
            {
                point2 = mousePosition.Value;
            }
            else
            {
                point2 = point1;
            }

            if (_controlPoints.Count == 2)
            {
                point2 = _controlPoints[1];
            }

            // Clipping opitmization.
            RectangleF rectangle = new RectangleF(
                Math.Min(point1.X, point2.X), Math.Min(point1.Y, point2.Y),
                Math.Abs(point2.X - point1.X), Math.Abs(point2.Y - point1.Y));

            if (rectangle.IntersectsWith(clippingRectangle) == false)
            {
                return;
            }

            SimpleLine line = new SimpleLine(point1, point2);
            PointF     vec  = new PointF(line.XDelta, line.YDelta);

            vec = g.DrawingSpaceToActualSpace(vec, false);
            vec = new PointF(vec.Y, vec.X);

            // Rotate
            PointF vec1 = SimpleLine.RotatePoint(vec, -(float)Math.PI / 2 + 0.3f);
            PointF vec2 = SimpleLine.RotatePoint(vec, -(float)Math.PI / 2 - 0.3f);

            // Scale
            vec1 = new PointF(vec1.X * 0.35f, vec1.Y * 0.35f);
            vec2 = new PointF(vec2.X * 0.35f, vec2.Y * 0.35f);

            vec1 = g.ActualSpaceToDrawingSpace(vec1, false);
            vec2 = g.ActualSpaceToDrawingSpace(vec2, false);

            g.DrawLine(_pen, point1, point2);
            g.FillPolygon(_brush, new PointF[] { point2, new PointF(point2.X + vec1.X, point2.Y + vec1.Y),
                                                 new PointF(point2.X + vec2.X, point2.Y + vec2.Y) });

            if (Selected)
            {
                DrawControlPoints(g);
            }
        }
        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;
            }
        }
        ///// <summary>
        ///// Helper method, draws histogram bars.
        ///// </summary>
        //protected void DrawHistogramBars(GraphicsWrapper g, Pen pen, Brush fill, int unitsUnification,
        //    RectangleF clippingRectangle, float itemWidth, float itemMargin, object tag)
        //{
        //    PointF drawingPoint = new PointF();
        //    int startIndex, endIndex;
        //    GetDrawingRangeIndecesFromClippingRectange(clippingRectangle, drawingPoint, unitsUnification, out startIndex, out endIndex, itemWidth, itemMargin);
        //    for (int i = startIndex + unitsUnification - 1; i < endIndex && i < MaximumIndex + unitsUnification - 1; i += unitsUnification)
        //    {
        //        int actualIndex = i;
        //        int actualPreviousIndex = i - unitsUnification;
        //        if (actualIndex >= MaximumIndex)
        //        {
        //            actualIndex = MaximumIndex - 1;
        //        }
        //        DrawHistogramBar(g, ref drawingPoint, pen, fill, actualIndex, actualPreviousIndex,
        //            itemWidth, itemMargin, unitsUnification, tag);
        //        drawingPoint.X = i * (itemMargin + itemWidth);
        //    }
        //}
        //protected void DrawColoredArea(GraphicsWrapper g, Pen pen, Brush fill, int unitsUnification,
        //    RectangleF clippingRectangle, float itemWidth, float itemMargin, object tag)
        //{
        //    PointF drawingPoint = new PointF();
        //    int startIndex, endIndex;
        //    GetDrawingRangeIndecesFromClippingRectange(clippingRectangle, drawingPoint, unitsUnification, out startIndex, out endIndex, itemWidth, itemMargin);
        //    for (int i = startIndex + unitsUnification - 1; i < endIndex && i < MaximumIndex + unitsUnification - 1; i += unitsUnification)
        //    {
        //        int actualIndex = i;
        //        int actualPreviousIndex = i - unitsUnification;
        //        if (actualIndex >= MaximumIndex)
        //        {
        //            actualIndex = MaximumIndex - 1;
        //        }
        //        DrawColorAreaItem(g, ref drawingPoint, pen, fill, actualIndex,
        //            actualPreviousIndex, itemWidth, itemMargin, tag);
        //        drawingPoint.X = i * (itemMargin + itemWidth);
        //    }
        //}
        protected void DrawColorAreaItem(GraphicsWrapper g, ref PointF drawingPoint, Pen pen, Brush fill, 
            int index, int previousItemIndex, float itemWidth, float itemMargin, object tag)
        {
            float indexValue = GetDrawingValueAt(index, tag);
            float previousItemIndexValue = GetDrawingValueAt(previousItemIndex, tag);

            int unificationCount = index - previousItemIndex;

            for (int i = previousItemIndex; i <= index; i++)
            {
                if (float.IsNaN(previousItemIndexValue))
                {
                    previousItemIndexValue = GetDrawingValueAt(i, tag);
                } else if (float.IsNaN(indexValue))
                {
                    indexValue = GetDrawingValueAt(i, tag);
                }
            }

            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);
            }
        }
        public override void Draw(GraphicsWrapper g, PointF? mousePosition, RectangleF clippingRectangle, RectangleF drawingSpace)
        {
            if (Visible == false)
            {
                return;
            }

            if (_controlPoints.Count < 1)
            {
                return;
            }

            PointF point1 = _controlPoints[0];
            PointF point2;

            if (mousePosition.HasValue)
            {
                point2 = mousePosition.Value;
            }
            else
            {
                point2 = point1;
            }

            if (_controlPoints.Count == 2)
            {
                point2 = _controlPoints[1];
            }

            // Clipping opitmization.
            RectangleF rectangle = new RectangleF(
                Math.Min(point1.X, point2.X), Math.Min(point1.Y, point2.Y),
                Math.Abs(point2.X - point1.X), Math.Abs(point2.Y - point1.Y));

            if (rectangle.IntersectsWith(clippingRectangle) == false)
            {
                return;
            }

            SimpleLine line = new SimpleLine(point1, point2);
            PointF vec = new PointF(line.XDelta, line.YDelta);

            vec = g.DrawingSpaceToActualSpace(vec, false);
            vec = new PointF(vec.Y, vec.X);

            // Rotate
            PointF vec1 = SimpleLine.RotatePoint(vec, -(float)Math.PI/2 + 0.3f);
            PointF vec2 = SimpleLine.RotatePoint(vec, -(float)Math.PI/2 -0.3f);

            // Scale
            vec1 = new PointF(vec1.X * 0.35f, vec1.Y * 0.35f);
            vec2 = new PointF(vec2.X * 0.35f, vec2.Y * 0.35f);

            vec1 = g.ActualSpaceToDrawingSpace(vec1, false);
            vec2 = g.ActualSpaceToDrawingSpace(vec2, false);

            g.DrawLine(_pen, point1, point2);
            g.FillPolygon(_brush, new PointF[] { point2, new PointF(point2.X + vec1.X, point2.Y + vec1.Y),
                new PointF(point2.X + vec2.X, point2.Y + vec2.Y) });

            if (Selected)
            {
                DrawControlPoints(g);
            }
        }