/// <summary> /// Control points selection rectangle is rendered in absolute size, ignoring scaling. /// </summary> /// <param name="g"></param> /// <param name="pen">Pass null to use default control point pen.</param> protected void DrawControlPoints(GraphicsWrapper g) { float xMargin = 0.5f * Math.Abs(_defaultAbsoluteControlPointSelectionRectanglesSize / g.DrawingSpaceTransformClone.Elements[0]); float yMargin = 0.5f * Math.Abs(_defaultAbsoluteControlPointSelectionRectanglesSize / g.DrawingSpaceTransformClone.Elements[3]); for (int i = 0; i < _controlPoints.Count; i++) { PointF point = _controlPoints[i]; if (_selectedControlPoints.Contains(i)) { g.DrawRectangle(_defaultSelectedControlPointPen, point.X - xMargin, point.Y - yMargin, xMargin * 2, yMargin * 2); } else { g.DrawRectangle(_defaultControlPointPen, point.X - xMargin, point.Y - yMargin, xMargin * 2, yMargin * 2); } } }
protected void DrawIcon(GraphicsWrapper g, Pen pen, Brush fill, Rectangle rectangle) { if (Visible == false) { return; } if (fill != null) { g.FillRectangle(fill, rectangle); } if (pen != null) { g.DrawRectangle(pen, rectangle); } }
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> /// Override this routine, to add the price labels at the space outside of the current drawing pane. /// </summary> /// <param name="managingPane"></param> /// <param name="g"></param> public override void DrawInitialActualSpaceOverlays(ChartPane managingPane, GraphicsWrapper g) { base.DrawInitialActualSpaceOverlays(managingPane, g); if (_dataProvider == null || _dataProvider.OperationalState != OperationalStateEnum.Operational) { return; } decimal? ask = _dataProvider.Quotes.Ask; decimal? bid = _dataProvider.Quotes.Bid; if (ask.HasValue == false || bid.HasValue == false) { return; } // Measure based on a default format of 6 symbols. SizeF size = g.MeasureString("00.0000", managingPane.LabelsFont); Brush fillBrush = managingPane.LabelsFill; if (fillBrush == null) { fillBrush = managingPane.ActualDrawingSpaceAreaFill; } if (_showCurrentAskLine) { PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Ask), true); position.X = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight; position.Y -= size.Height; if (fillBrush != null) { g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height)); } if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null) { g.DrawString(ask.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position); g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width/* - 2*/, size.Height)); } } if (_showCurrentBidLine) { PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Bid), true); position.X = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight; if (fillBrush != null) { g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height)); } if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null) { g.DrawString(bid.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position); g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width/* - 2*/, size.Height)); } } }
/// <summary> /// Override this routine, to add the price labels at the space outside of the current drawing pane. /// </summary> /// <param name="managingPane"></param> /// <param name="g"></param> public override void DrawInitialActualSpaceOverlays(ChartPane managingPane, GraphicsWrapper g) { base.DrawInitialActualSpaceOverlays(managingPane, g); if (_dataProvider == null || _dataProvider.OperationalState != OperationalStateEnum.Operational) { return; } decimal?ask = _dataProvider.Quotes.Ask; decimal?bid = _dataProvider.Quotes.Bid; if (ask.HasValue == false || bid.HasValue == false) { return; } // Measure based on a default format of 6 symbols. SizeF size = g.MeasureString("00.0000", managingPane.LabelsFont); Brush fillBrush = managingPane.LabelsFill; if (fillBrush == null) { fillBrush = managingPane.ActualDrawingSpaceAreaFill; } if (_showCurrentAskLine) { PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Ask), true); position.X = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight; position.Y -= size.Height; if (fillBrush != null) { g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height)); } if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null) { g.DrawString(ask.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position); g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width /* - 2*/, size.Height)); } } if (_showCurrentBidLine) { PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Bid), true); position.X = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight; if (fillBrush != null) { g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height)); } if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null) { g.DrawString(bid.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position); g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width /* - 2*/, size.Height)); } } }
void DrawSelection(GraphicsWrapper g) { if (CurrentSelectionRectangle.HasValue == false) { return; } RectangleF selectionRectangle = CurrentSelectionRectangle.Value; if (selectionRectangle.Width > 0 && selectionRectangle.Height > 0 && _lastDrawingSpaceMouseRightButtonPosition.HasValue && _currentDrawingSpaceMousePosition.HasValue) { if (_selectionPen != null) { g.DrawRectangle(_selectionPen, selectionRectangle.X, selectionRectangle.Y, selectionRectangle.Width, selectionRectangle.Height); } if (_selectionFill != null) { g.FillRectangle(_selectionFill, selectionRectangle); } } }
void DrawDrawingSpace(GraphicsWrapper g) { RectangleF drawingSpaceClipping = _actualDrawingSpaceArea; drawingSpaceClipping.X -= _seriesItemMargin + _seriesItemWidth; drawingSpaceClipping.Y -= _seriesItemMargin + _seriesItemWidth; drawingSpaceClipping.Width += 2 * (_seriesItemMargin + _seriesItemWidth); drawingSpaceClipping.Height += 2 * (_seriesItemMargin + _seriesItemWidth); drawingSpaceClipping = GraphicsWrapper.ActualSpaceToDrawingSpace(drawingSpaceClipping); //drawingSpaceClipping.Y = DrawingSpace.Y - 10; //drawingSpaceClipping.Height = DrawingSpace.Height + 10; // Grid. _drawingSpaceGrid.Draw(g, drawingSpaceClipping, _drawingSpace, _seriesItemMargin + _seriesItemWidth); // Show clipping rectangle. if (ShowClippingRectangle) { Pen clippingRectanglePen = (Pen)Pens.DarkGray.Clone(); clippingRectanglePen.DashStyle = DashStyle.Dash; g.DrawRectangle(clippingRectanglePen, drawingSpaceClipping.X, drawingSpaceClipping.Y, drawingSpaceClipping.Width, drawingSpaceClipping.Height); } // Draw custom objects - pre series. _customObjectsManager.Draw(g, drawingSpaceClipping, CustomObject.DrawingOrderEnum.PreSeries); // Series. foreach (ChartSeries series in _series) { series.Draw(this, g, CurrentUnitUnification, drawingSpaceClipping, _seriesItemWidth, _seriesItemMargin); } // Draw custom objects - post series. _customObjectsManager.Draw(g, drawingSpaceClipping, CustomObject.DrawingOrderEnum.PostSeries); }
protected virtual void DrawPostActualSpaceOverlays(GraphicsWrapper g) { if (_titleFont != null && _titleFontBrush != null) { // Title SizeF titleSize = g.MeasureString(_chartName, _titleFont); Rectangle titleRectangle = new Rectangle(_actualDrawingSpaceArea.Left, _actualDrawingSpaceArea.Top, (int)titleSize.Width, (int)titleSize.Height); g.DrawString(_chartName, _titleFont, _titleFontBrush, titleRectangle.Location); PointF drawingLocation = new PointF(_actualDrawingSpaceArea.Left, titleRectangle.Height + _actualDrawingSpaceArea.Top); // After the title, render any messages the chart series might have. foreach (ChartSeries series in _series) { drawingLocation = series.DrawCustomMessages(this, g, drawingLocation); } } if (_actualDrawingSpaceAreaBorderPen != null) { // Border g.DrawRectangle(_actualDrawingSpaceAreaBorderPen, _actualDrawingSpaceArea.X - 1, _actualDrawingSpaceArea.Y - 1, _actualDrawingSpaceArea.Width + 1, _actualDrawingSpaceArea.Height + 1); } }
/// <summary> /// Enter locked. /// </summary> void DrawCandleStick(GraphicsWrapper g, ref PointF startingPoint, DataBar barData, float itemWidth, float itemMargin, int itemUnitification) { if (barData.IsRising) { if (_risingBarFill != null) { g.FillRectangle(_risingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight); } if (_risingBarPen != null) { if (itemWidth > 4) { g.DrawRectangle(_risingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight); } else { g.FillRectangle(Brushes.Green, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight); } // Draw a horizontal line for 0 height bars. if (barData.AbsoluteBodyHeight == 0) { g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close); } // Lower shadow g.DrawLine(_risingBarPen, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Low, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Open); // Upper shadow g.DrawLine(_risingBarPen, startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.High), startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.Close)); } } else { if (_fallingBarFill != null) { g.FillRectangle(_fallingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.AbsoluteBodyHeight); } if (_fallingBarPen != null) { if (itemWidth >= 4) {// Only if an item is clearly visible, show the border, otherwise, hide to improve. overal visibility. // Showing this border adds nice detail on close zooming, but not useful otherwise. g.DrawRectangle(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.AbsoluteBodyHeight); } // Draw a horizontal line for 0 height bars. if (barData.AbsoluteBodyHeight == 0) { g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close); } // Lower shadow g.DrawLine(_fallingBarPen, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Low, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Close); // Upper shadow g.DrawLine(_fallingBarPen, startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.High), startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.Open)); } } }