/// <summary> /// On Paint /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); // Caption Data.GradientPaint(g, rectCaption, colorCaptionBack, LayoutColors.DepthCaption); if (showCaption) { g.DrawString(captionText, fontCaption, brushCaption, rectCaption, stringFormatCaption); } g.DrawLine(penBorder, 1, CaptionHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, CaptionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); // Paint the panel background var rectClient = new RectangleF(Border, CaptionHeight, width, height); Data.GradientPaint(g, rectClient, LayoutColors.ColorControlBack, LayoutColors.DepthControl); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
private void PnlDataInfoButtons_Paint(object sender, PaintEventArgs e) { var pnl = (Panel)sender; Graphics g = e.Graphics; // Paint the panel background Data.GradientPaint(g, pnl.ClientRectangle, LayoutColors.ColorControlBack, LayoutColors.DepthCaption); }
/// <summary> /// On Paint /// </summary> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; // Caption Data.GradientPaint(g, _rectfCaption, _colorCaptionBack, LayoutColors.DepthCaption); if (_isShowCaption) { g.DrawString(_caption, _fontCaption, _brushCaption, _rectfCaption, _stringFormatCaption); } g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height); g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); // Paint the panel background var rectClient = new RectangleF(Border, _captionHeight, _width, _height); Data.GradientPaint(g, rectClient, LayoutColors.ColorControlBack, LayoutColors.DepthControl); }
/// <summary> /// On Paint /// </summary> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; // Caption Data.GradientPaint(g, _rectfCaption, _colorCaptionBack, LayoutColors.DepthCaption); g.DrawString(_caption, _fontCaption, _brushCaption, _rectfCaption, _stringFormatCaption); for (int i = 0; i *_rowHeight + _captionHeight < _height; i++) { float fVerticalPosition = i * _rowHeight + _captionHeight; var pointFParam = new PointF(_paramTab + 2, fVerticalPosition); var pointFValue = new PointF(_valueTab + 2, fVerticalPosition); var rectRow = new RectangleF(Border, fVerticalPosition, _width, _rowHeight); // Row background g.FillRectangle( Math.Abs(i % 2f - 0) > 0.01 ? new SolidBrush(_colorBackroundEvenRows) : new SolidBrush(_colorBackroundOddRows), rectRow); if (i + _vScrollBar.Value >= _rows) { continue; } g.DrawString(_asParam[i + _vScrollBar.Value], _fontData, _brushParams, pointFParam, _stringFormatData); g.DrawString(_asValue[i + _vScrollBar.Value], _fontData, _brushData, pointFValue, _stringFormatData); } // Border g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height); g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); }
/// <summary> /// Panel properties Paint /// </summary> private void PnlPropertiesPaint(object sender, PaintEventArgs e) { var pnl = (Panel)sender; Graphics g = e.Graphics; int width = pnl.ClientSize.Width; Color colorCaptionBack = LayoutColors.ColorSlotCaptionBackAveraging; Color colorCaptionText = LayoutColors.ColorSlotCaptionText; Color colorBackground = LayoutColors.ColorSlotBackground; Color colorLogicText = LayoutColors.ColorSlotLogicText; Color colorDash = LayoutColors.ColorSlotDash; // Caption string stringCaptionText = Language.T("Strategy Properties"); var fontCaptionText = new Font(Font.FontFamily, 9); float captionHeight = Math.Max(fontCaptionText.Height, 18); float captionWidth = width; Brush brushCaptionText = new SolidBrush(colorCaptionText); var stringFormatCaption = new StringFormat { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap, Alignment = StringAlignment.Center }; var rectCaption = new RectangleF(0, 0, captionWidth, captionHeight); Data.GradientPaint(g, rectCaption, colorCaptionBack, LayoutColors.DepthCaption); g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectCaption, stringFormatCaption); // Border var penBorder = new Pen(Data.GetGradientColor(colorCaptionBack, -LayoutColors.DepthCaption), Border); g.DrawLine(penBorder, 1, captionHeight, 1, pnl.Height); g.DrawLine(penBorder, pnl.Width - Border + 1, captionHeight, pnl.Width - Border + 1, pnl.Height); g.DrawLine(penBorder, 0, pnl.Height - Border + 1, pnl.Width, pnl.Height - Border + 1); // Paint the panel's background var rectPanel = new RectangleF(Border, captionHeight, pnl.Width - 2 * Border, pnl.Height - captionHeight - Border); Data.GradientPaint(g, rectPanel, colorBackground, LayoutColors.DepthControl); int vPosition = (int)captionHeight + 2; // Padlock image if (ShowPadlockImg) { if (strategy.PropertiesStatus == StrategySlotStatus.Locked) { g.DrawImage(Resources.padlock_img, 1, 1, 16, 16); } else if (strategy.PropertiesStatus == StrategySlotStatus.Open) { g.DrawImage(Resources.open_padlock, 1, 1, 16, 16); } else if (strategy.PropertiesStatus == StrategySlotStatus.Linked) { g.DrawImage(Resources.linked, 1, 1, 16, 16); } } var stringFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }; var fontParam = new Font(Font.FontFamily, 9f, FontStyle.Regular); var fontValue = new Font(Font.FontFamily, 9f, FontStyle.Regular); Brush brushParam = new SolidBrush(colorLogicText); Brush brushValue = new SolidBrush(colorLogicText); var penDash = new Pen(colorDash); string strPermaSL = strategy.UsePermanentSL ? (Data.Strategy.PermanentSLType == PermanentProtectionType.Absolute ? "(Abs) " : "") + strategy.PermanentSL.ToString(CultureInfo.InvariantCulture) : Language.T("None"); string strPermaTP = strategy.UsePermanentTP ? (Data.Strategy.PermanentTPType == PermanentProtectionType.Absolute ? "(Abs) " : "") + strategy.PermanentTP.ToString(CultureInfo.InvariantCulture) : Language.T("None"); string strBreakEven = strategy.UseBreakEven ? strategy.BreakEven.ToString(CultureInfo.InvariantCulture) : Language.T("None"); if (SlotMinMidMax == SlotSizeMinMidMax.min) { string param = Language.T(strategy.SameSignalAction.ToString()) + "; " + Language.T(strategy.OppSignalAction.ToString()) + "; " + "SL-" + strPermaSL + "; " + "TP-" + strPermaTP + "; " + "BE-" + strBreakEven; SizeF sizeParam = g.MeasureString(param, fontParam); float maxParamWidth = sizeParam.Width; // Padding Param Padding Dash Padding Value Padding float padding = Space; float necessaryWidth = 2 * padding + maxParamWidth; padding = width > necessaryWidth?Math.Max((pnl.ClientSize.Width - maxParamWidth) / 2, padding) : 2; float tabParam = padding; var pointParam = new PointF(tabParam, vPosition); g.DrawString(param, fontParam, brushParam, pointParam); } else { // Find Maximum width of the strings var asParams = new[] { Language.T("Same direction signal"), Language.T("Opposite direction signal"), Language.T("Permanent Stop Loss"), Language.T("Permanent Take Profit"), Language.T("Break Even") }; var asValues = new[] { Language.T(strategy.SameSignalAction.ToString()), Language.T(strategy.OppSignalAction.ToString()), strPermaSL, strPermaTP, strBreakEven }; float maxParamWidth = 0; foreach (string param in asParams) { if (g.MeasureString(param, fontParam).Width > maxParamWidth) { maxParamWidth = g.MeasureString(param, fontParam).Width; } } float maxValueWidth = 0; foreach (string value in asValues) { if (g.MeasureString(value, fontParam).Width > maxValueWidth) { maxValueWidth = g.MeasureString(value, fontParam).Width; } } // Padding Param Padding Dash Padding Value Padding float padding = Space; const float dashWidth = 5; float necessaryWidth = 4 * padding + maxParamWidth + maxValueWidth + dashWidth; padding = width > necessaryWidth ? Math.Max((pnl.ClientSize.Width - maxParamWidth - maxValueWidth - dashWidth) / 6, padding) : 2; float tabParam = 2 * padding; float tabDash = tabParam + maxParamWidth + padding; float tabValue = tabDash + dashWidth + padding; // Same direction string parameter = Language.T("Same direction signal"); string text = Language.T(strategy.SameSignalAction.ToString()); var pointParam = new PointF(tabParam, vPosition); var pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(tabValue, vPosition); var sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); var rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(parameter, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(text, fontValue, brushValue, rectValue, stringFormat); vPosition += fontValue.Height + 2; // Opposite direction parameter = Language.T("Opposite direction signal"); text = Language.T(strategy.OppSignalAction.ToString()); pointParam = new PointF(tabParam, vPosition); pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); pointValue = new PointF(tabValue, vPosition); sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(parameter, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(text, fontValue, brushValue, rectValue, stringFormat); vPosition += fontValue.Height + 2; // Permanent Stop Loss parameter = Language.T("Permanent Stop Loss"); text = strPermaSL; pointParam = new PointF(tabParam, vPosition); pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); pointValue = new PointF(tabValue, vPosition); sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(parameter, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(text, fontValue, brushValue, rectValue, stringFormat); vPosition += fontValue.Height + 2; // Permanent Take Profit parameter = Language.T("Permanent Take Profit"); text = strPermaTP; pointParam = new PointF(tabParam, vPosition); pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); pointValue = new PointF(tabValue, vPosition); sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(parameter, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(text, fontValue, brushValue, rectValue, stringFormat); vPosition += fontValue.Height; // Break Even parameter = Language.T("Break Even"); text = strBreakEven; pointParam = new PointF(tabParam, vPosition); pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); pointValue = new PointF(tabValue, vPosition); sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(parameter, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(text, fontValue, brushValue, rectValue, stringFormat); } }
/// <summary> /// Panel Slot Paint /// </summary> private void PnlSlotPaint(object sender, PaintEventArgs e) { var pnl = (ContextPanel)sender; Graphics g = e.Graphics; var slot = (int)pnl.Tag; int width = pnl.ClientSize.Width; SlotTypes slotType = strategy.GetSlotType(slot); Color colorBackground = LayoutColors.ColorSlotBackground; Color colorCaptionText = LayoutColors.ColorSlotCaptionText; Color colorCaptionBackOpen = LayoutColors.ColorSlotCaptionBackOpen; Color colorCaptionBackOpenFilter = LayoutColors.ColorSlotCaptionBackOpenFilter; Color colorCaptionBackClose = LayoutColors.ColorSlotCaptionBackClose; Color colorCaptionBackCloseFilter = LayoutColors.ColorSlotCaptionBackCloseFilter; Color colorIndicatorNameText = LayoutColors.ColorSlotIndicatorText; Color colorLogicText = LayoutColors.ColorSlotLogicText; Color colorParamText = LayoutColors.ColorSlotParamText; Color colorValueText = LayoutColors.ColorSlotValueText; Color colorDash = LayoutColors.ColorSlotDash; // Caption string stringCaptionText = string.Empty; Color colorCaptionBack = LayoutColors.ColorSignalRed; switch (slotType) { case SlotTypes.Open: stringCaptionText = Language.T("Opening Point of the Position"); colorCaptionBack = colorCaptionBackOpen; break; case SlotTypes.OpenFilter: stringCaptionText = Language.T("Opening Logic Condition"); colorCaptionBack = colorCaptionBackOpenFilter; break; case SlotTypes.Close: stringCaptionText = Language.T("Closing Point of the Position"); colorCaptionBack = colorCaptionBackClose; break; case SlotTypes.CloseFilter: stringCaptionText = Language.T("Closing Logic Condition"); colorCaptionBack = colorCaptionBackCloseFilter; break; } var penBorder = new Pen(Data.GetGradientColor(colorCaptionBack, -LayoutColors.DepthCaption), Border); var fontCaptionText = new Font(Font.FontFamily, 9); float captionHeight = Math.Max(fontCaptionText.Height, 18); float captionWidth = width; Brush brushCaptionText = new SolidBrush(colorCaptionText); var stringFormatCaption = new StringFormat { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap, Alignment = StringAlignment.Center }; var rectCaption = new RectangleF(0, 0, captionWidth, captionHeight); Data.GradientPaint(g, rectCaption, colorCaptionBack, LayoutColors.DepthCaption); if (ShowRemoveSlotButtons && slot != strategy.OpenSlot && slot != strategy.CloseSlot) { int buttonDimentions = (int)captionHeight - 2; int buttonX = width - buttonDimentions - 1; float captionTextWidth = g.MeasureString(stringCaptionText, fontCaptionText).Width; float captionTextX = Math.Max((captionWidth - captionTextWidth) / 2f, 0); var pfCaptionText = new PointF(captionTextX, 0); var sfCaptionText = new SizeF(buttonX - captionTextX, captionHeight); rectCaption = new RectangleF(pfCaptionText, sfCaptionText); stringFormatCaption.Alignment = StringAlignment.Near; } g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectCaption, stringFormatCaption); // Border g.DrawLine(penBorder, 1, captionHeight, 1, pnl.Height); g.DrawLine(penBorder, pnl.Width - Border + 1, captionHeight, pnl.Width - Border + 1, pnl.Height); g.DrawLine(penBorder, 0, pnl.Height - Border + 1, pnl.Width, pnl.Height - Border + 1); // Paints the panel var rectPanel = new RectangleF(Border, captionHeight, pnl.Width - 2 * Border, pnl.Height - captionHeight - Border); Data.GradientPaint(g, rectPanel, colorBackground, LayoutColors.DepthControl); int vPosition = (int)captionHeight + 3; // Padlock image if (ShowPadlockImg) { if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Locked) { g.DrawImage(Resources.padlock_img, 1, 1, 16, 16); } else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Open) { g.DrawImage(Resources.open_padlock, 1, 1, 16, 16); } else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { g.DrawImage(Resources.linked, 1, 1, 16, 16); } } // Indicator name var stringFormatIndicatorName = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.NoWrap }; var fontIndicator = new Font(Font.FontFamily, 11f, FontStyle.Regular); Brush brushIndName = new SolidBrush(colorIndicatorNameText); float indNameHeight = fontIndicator.Height; float fGroupWidth = 0; if (Configs.UseLogicalGroups && (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)) { string sLogicalGroup = "[" + strategy.Slot[slot].LogicalGroup + "]"; fGroupWidth = g.MeasureString(sLogicalGroup, fontIndicator).Width; var rectGroup = new RectangleF(0, vPosition, fGroupWidth, indNameHeight); g.DrawString(sLogicalGroup, fontIndicator, brushIndName, rectGroup, stringFormatIndicatorName); } stringFormatIndicatorName.Trimming = StringTrimming.EllipsisCharacter; string indicatorName = strategy.Slot[slot].IndicatorName; float nameWidth = g.MeasureString(indicatorName, fontIndicator).Width; RectangleF rectIndName = width >= 2 * fGroupWidth + nameWidth ? new RectangleF(0, vPosition, width, indNameHeight) : new RectangleF(fGroupWidth, vPosition, width - fGroupWidth, indNameHeight); g.DrawString(indicatorName, fontIndicator, brushIndName, rectIndName, stringFormatIndicatorName); vPosition += (int)indNameHeight; if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter) { pnl.CloseButton.ColorBack = colorCaptionBack; pnl.CloseButton.ColorFore = colorCaptionText; pnl.CloseButton.Visible = ShowRemoveSlotButtons; } if (SlotMinMidMax == SlotSizeMinMidMax.min) { return; } // Logic var stringFormatLogic = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoClip }; float padding = Space; if (strategy.Slot[slot].IndParam.ListParam[0].Enabled) { string value = strategy.Slot[slot].IndParam.ListParam[0].Text; var fontLogic = new Font(Font.FontFamily, 10.5f, FontStyle.Regular); SizeF sizeValue = g.MeasureString(value, fontLogic, (int)(width - 2 * padding), stringFormatLogic); var rectValue = new RectangleF(padding, vPosition, width - 2 * padding, sizeValue.Height); Brush brushLogic = new SolidBrush(colorLogicText); g.DrawString(value, fontLogic, brushLogic, rectValue, stringFormatLogic); vPosition += (int)sizeValue.Height; } if (SlotMinMidMax == SlotSizeMinMidMax.mid) { return; } // Parameters var stringFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }; var fontParam = new Font(Font.FontFamily, 9f, FontStyle.Regular); var fontValue = new Font(Font.FontFamily, 9f, FontStyle.Regular); Brush brushParam = new SolidBrush(colorParamText); Brush brushValue = new SolidBrush(colorValueText); var penDash = new Pen(colorDash); // Find Maximum width of the strings float maxParamWidth = 0; float maxValueWidth = 0; for (int i = 1; i < 5; i++) { if (!strategy.Slot[slot].IndParam.ListParam[i].Enabled) { continue; } string caption = strategy.Slot[slot].IndParam.ListParam[i].Caption; string value = strategy.Slot[slot].IndParam.ListParam[i].Text; SizeF sizeParam = g.MeasureString(caption, fontParam); SizeF sizeValue = g.MeasureString(value, fontValue); if (maxParamWidth < sizeParam.Width) { maxParamWidth = sizeParam.Width; } if (maxValueWidth < sizeValue.Width) { maxValueWidth = sizeValue.Width; } } foreach (NumericParam numericParam in strategy.Slot[slot].IndParam.NumParam) { if (!numericParam.Enabled) { continue; } string caption = numericParam.Caption; string value = numericParam.ValueToString; SizeF sizeParam = g.MeasureString(caption, fontParam); SizeF sizeValue = g.MeasureString(value, fontValue); if (maxParamWidth < sizeParam.Width) { maxParamWidth = sizeParam.Width; } if (maxValueWidth < sizeValue.Width) { maxValueWidth = sizeValue.Width; } } foreach (CheckParam checkParam in strategy.Slot[slot].IndParam.CheckParam) { if (!checkParam.Enabled) { continue; } string param = checkParam.Caption; string value = checkParam.Checked ? "Yes" : "No"; SizeF sizeParam = g.MeasureString(param, fontParam); SizeF sizeValue = g.MeasureString(value, fontValue); if (maxParamWidth < sizeParam.Width) { maxParamWidth = sizeParam.Width; } if (maxValueWidth < sizeValue.Width) { maxValueWidth = sizeValue.Width; } } // Padding Parameter Padding Dash Padding Value Padding const float dashWidth = 5; float necessaryWidth = 4 * padding + maxParamWidth + maxValueWidth + dashWidth; padding = width > necessaryWidth ? Math.Max((pnl.ClientSize.Width - maxParamWidth - maxValueWidth - dashWidth) / 6, padding) : 2; float tabParam = 2 * padding; float tabDash = tabParam + maxParamWidth + padding; float tabValue = tabDash + dashWidth + padding; // List Parameters for (int i = 1; i < 5; i++) { if (!strategy.Slot[slot].IndParam.ListParam[i].Enabled) { continue; } string caption = strategy.Slot[slot].IndParam.ListParam[i].Caption; string value = strategy.Slot[slot].IndParam.ListParam[i].Text; var pointParam = new PointF(tabParam, vPosition); var pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(tabValue, vPosition); var sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); var rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(caption, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(value, fontValue, brushValue, rectValue, stringFormat); vPosition += fontValue.Height; } // Num Parameters foreach (NumericParam numericParam in strategy.Slot[slot].IndParam.NumParam) { if (!numericParam.Enabled) { continue; } string caption = numericParam.Caption; string value = numericParam.ValueToString; var pointParam = new PointF(tabParam, vPosition); var pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(tabValue, vPosition); var sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); var rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(caption, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(value, fontValue, brushValue, rectValue, stringFormat); vPosition += fontValue.Height; } // Check Parameters foreach (CheckParam checkParam in strategy.Slot[slot].IndParam.CheckParam) { if (!checkParam.Enabled) { continue; } string param = checkParam.Caption; string value = checkParam.Checked ? "Yes" : "No"; var pointParam = new PointF(tabParam, vPosition); var pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(tabValue, vPosition); var sizeValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2); var rectValue = new RectangleF(pointValue, sizeValue); g.DrawString(param, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(value, fontValue, brushValue, rectValue, stringFormat); vPosition += fontValue.Height; } }
/// <summary> /// Paints the charts /// </summary> private void PnlChartPaint(object sender, PaintEventArgs e) { var pnl = (Panel)sender; Graphics g = e.Graphics; const int space = 5; const int border = 2; // Chart Title string unit = " [" + (Configs.AccountInMoney ? Configs.AccountCurrency : Language.T("points")) + "]"; string str = Language.T("Balance Chart") + unit; var font = new Font(Font.FontFamily, 9); var fCaptionHeight = (float)Math.Max(font.Height, 18); var rectfCaption = new RectangleF(0, 0, pnl.ClientSize.Width, fCaptionHeight); var stringFormatCaption = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); g.DrawString(str, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectfCaption, stringFormatCaption); // Paint the panel background var rectClient = new RectangleF(border, fCaptionHeight, pnl.ClientSize.Width - 2 * border, pnl.Height - fCaptionHeight - border); Data.GradientPaint(g, rectClient, LayoutColors.ColorChartBack, LayoutColors.DepthControl); var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border); g.DrawLine(penBorder, 1, fCaptionHeight, 1, pnl.ClientSize.Height); g.DrawLine(penBorder, pnl.ClientSize.Width - border + 1, fCaptionHeight, pnl.ClientSize.Width - border + 1, pnl.ClientSize.Height); g.DrawLine(penBorder, 0, pnl.ClientSize.Height - border + 1, pnl.ClientSize.Width, pnl.ClientSize.Height - border + 1); if (!isPaintChart) { if (Backtester.AmbiguousBars == 0) { string sNote = Language.T("The Comparator is useful when the backtest shows ambiguous bars!"); var rectfNote = new RectangleF(0, 30, pnl.ClientSize.Width, Font.Height); g.DrawString(sNote, Font, new SolidBrush(LayoutColors.ColorChartFore), rectfNote, stringFormatCaption); } return; } int bars = Data.Bars - Data.FirstBar; int max = (int)Math.Max(maximum, maximumRandom) + 1; int min = (int)Math.Min(minimum, minimumRandom) - 1; min = (int)Math.Floor(min / 10f) * 10; int yTop = (int)fCaptionHeight + 2 * space + 1; int yBottom = (pnl.ClientSize.Height - 2 * space - border); var labelWidth = (int) Math.Max(g.MeasureString(min.ToString(CultureInfo.InvariantCulture), Font).Width, g.MeasureString(max.ToString(CultureInfo.InvariantCulture), Font).Width); labelWidth = Math.Max(labelWidth, 30); int xRight = pnl.ClientSize.Width - border - space - labelWidth; int xLeft = border + space; // // Grid // int cntLabels = Math.Max((yBottom - yTop) / 20, 1); var delta = (float)Math.Max(Math.Round((max - min) / (float)cntLabels), 10); int step = (int)Math.Ceiling(delta / 10) * 10; cntLabels = (int)Math.Ceiling((max - min) / (float)step); max = min + cntLabels * step; float scaleY = (yBottom - yTop) / (cntLabels * (float)step); Brush brushFore = new SolidBrush(LayoutColors.ColorChartFore); var penGrid = new Pen(LayoutColors.ColorChartGrid) { DashStyle = DashStyle.Dash, DashPattern = new float[] { 4, 2 } }; // Price labels for (int label = min; label <= max; label += step) { var labelY = (int)(yBottom - (label - min) * scaleY); g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, brushFore, xRight, labelY - Font.Height / 2 - 1); g.DrawLine(penGrid, border + space, labelY, xRight, labelY); } float xScale = (xRight - 2 * space - border) / (float)bars; if (isRandom) { // Draws the random area and Min Max lines var apntMinRandom = new PointF[bars]; var apntMaxRandom = new PointF[bars]; for (int iBar = 0; iBar < bars; iBar++) { apntMinRandom[iBar].X = border + space + iBar * xScale; apntMinRandom[iBar].Y = yBottom - (afMinRandom[iBar] - min) * scaleY; apntMaxRandom[iBar].X = border + space + iBar * xScale; apntMaxRandom[iBar].Y = yBottom - (afMaxRandom[iBar] - min) * scaleY; } apntMinRandom[0].Y = apntMaxRandom[0].Y; var path = new GraphicsPath(); path.AddLines(apntMinRandom); path.AddLine(apntMinRandom[bars - 1], apntMaxRandom[bars - 1]); path.AddLines(apntMaxRandom); var region = new Region(path); g.FillRegion(brushRandArea, region); g.DrawLines(penRandBands, apntMinRandom); g.DrawLines(penRandBands, apntMaxRandom); } // Draws the lines for (int m = 0; m < countMethods; m++) { if (!AchboxMethods[m].Checked) { continue; } var apntLines = new PointF[bars]; for (int iBar = 0; iBar < bars; iBar++) { apntLines[iBar].X = border + space + iBar * xScale; apntLines[iBar].Y = yBottom - (afMethods[m, iBar] - min) * scaleY; } var pen = new Pen(LayoutColors.ColorSignalRed); switch ((InterpolationMethod)AchboxMethods[m].Tag) { case InterpolationMethod.Pessimistic: pen = penPessimistic; break; case InterpolationMethod.Shortest: pen = penShortest; break; case InterpolationMethod.Nearest: pen = penNearest; break; case InterpolationMethod.Optimistic: pen = penOptimistic; break; case InterpolationMethod.Random: pen = penRandom; break; } g.DrawLines(pen, apntLines); } // Draws the average balance var apntBalance = new PointF[bars]; for (int bar = 0; bar < bars; bar++) { apntBalance[bar].X = border + space + bar * xScale; apntBalance[bar].Y = yBottom - (afBalance[bar] - min) * scaleY; } g.DrawLines(penBalance, apntBalance); // Coordinate axes g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, yTop - space, xLeft - 1, yBottom); g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft, yBottom, xRight, yBottom); // Balance label float fBalanceY = yBottom - (afBalance[bars - 1] - min) * scaleY; g.DrawLine(new Pen(LayoutColors.ColorChartCross), xLeft, fBalanceY, xRight - space, fBalanceY); var szBalance = new Size(labelWidth + space, Font.Height + 2); var point = new Point(xRight - space + 2, (int)(fBalanceY - Font.Height / 2.0 - 1)); var rec = new Rectangle(point, szBalance); string sBalance = ((int)afBalance[bars - 1]).ToString(CultureInfo.InvariantCulture); g.FillRectangle(new SolidBrush(LayoutColors.ColorLabelBack), rec); g.DrawRectangle(new Pen(LayoutColors.ColorChartCross), rec); g.DrawString(sBalance, Font, new SolidBrush(LayoutColors.ColorLabelText), rec, stringFormatCaption); // Scanning note var fontNote = new Font(Font.FontFamily, Font.Size - 1); if (Configs.Autoscan && !Data.IsIntrabarData) { g.DrawString(Language.T("Load intrabar data"), fontNote, Brushes.Red, xLeft, fCaptionHeight - 2); } else if (Backtester.IsScanPerformed) { g.DrawString(Language.T("Scanned") + " MQ " + Data.ModellingQuality.ToString("N2") + "%", fontNote, Brushes.LimeGreen, border + space, fCaptionHeight - 2); } // Scanned bars if (Backtester.IsScanPerformed && (Data.IntraBars != null && Data.IsIntrabarData || Data.Period == DataPeriod.M1 && Data.IsTickData && Configs.UseTickData)) { g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, yBottom, xLeft - 1, yBottom + 8); DataPeriod dataPeriod = Data.Period; Color color = Data.PeriodColor[Data.Period]; int iFromBar = Data.FirstBar; for (int bar = Data.FirstBar; bar < Data.Bars; bar++) { if (Data.IntraBarsPeriods[bar] != dataPeriod || bar == Data.Bars - 1) { int xStart = (int)((iFromBar - Data.FirstBar) * xScale) + xLeft; int xEnd = (int)((bar - Data.FirstBar) * xScale) + xLeft; iFromBar = bar; dataPeriod = Data.IntraBarsPeriods[bar]; Data.GradientPaint(g, new RectangleF(xStart, yBottom + 3, xEnd - xStart + 2, 5), color, 60); color = Data.PeriodColor[Data.IntraBarsPeriods[bar]]; } } // Tick Data if (Data.IsTickData && Configs.UseTickData) { int firstBarWithTicks = -1; int lastBarWithTicks = -1; for (int b = 0; b < Data.Bars; b++) { if (firstBarWithTicks == -1 && Data.TickData[b] != null) { firstBarWithTicks = b; } if (Data.TickData[b] != null) { lastBarWithTicks = b; } } int xStart = (int)(firstBarWithTicks * xScale) + xLeft; int xEnd = (int)((lastBarWithTicks - Data.FirstBar) * xScale) + xLeft; if (xStart < xLeft) { xStart = xLeft; } if (xEnd < xStart) { xEnd = xStart; } Data.DrawCheckerBoard(g, Color.ForestGreen, new Rectangle(xStart, yBottom + 4, xEnd - xStart + 2, 3)); } } }
/// <summary> /// Paints panel pnlOptions /// </summary> private void PnlOptionsPaint(object sender, PaintEventArgs e) { var pnl = (Panel)sender; Graphics g = e.Graphics; const int border = 2; // Chart Title string str = Language.T("Interpolation Methods"); var font = new Font(Font.FontFamily, 9); var fCaptionHeight = (float)Math.Max(font.Height, 18); var rectfCaption = new RectangleF(0, 0, pnl.ClientSize.Width, fCaptionHeight); var stringFormatCaption = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); g.DrawString(str, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectfCaption, stringFormatCaption); // Paint the panel background var rectClient = new RectangleF(border, fCaptionHeight, pnl.ClientSize.Width - 2 * border, pnl.Height - fCaptionHeight - border); Data.GradientPaint(g, rectClient, LayoutColors.ColorControlBack, LayoutColors.DepthControl); var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border); g.DrawLine(penBorder, 1, fCaptionHeight, 1, pnl.ClientSize.Height); g.DrawLine(penBorder, pnl.ClientSize.Width - border + 1, fCaptionHeight, pnl.ClientSize.Width - border + 1, pnl.ClientSize.Height); g.DrawLine(penBorder, 0, pnl.ClientSize.Height - border + 1, pnl.ClientSize.Width, pnl.ClientSize.Height - border + 1); int positionX = (PnlOptions.ClientSize.Width - 10) / 3; const int positionY = 35; int num = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { if (num < countMethods) { var pt1 = new Point(j * positionX + 10, i * 30 + positionY); var pt2 = new Point(j * positionX + 30, i * 30 + positionY); var pen = new Pen(Color.Red); switch ((InterpolationMethod)AchboxMethods[num].Tag) { case InterpolationMethod.Pessimistic: pen = new Pen(LayoutColors.ComparatorChartPessimisticLine); break; case InterpolationMethod.Shortest: pen = new Pen(LayoutColors.ComparatorChartShortestLine); break; case InterpolationMethod.Nearest: pen = new Pen(LayoutColors.ComparatorChartNearestLine); break; case InterpolationMethod.Optimistic: pen = new Pen(LayoutColors.ComparatorChartOptimisticLine); break; case InterpolationMethod.Random: var pntRnd1 = new Point(j * positionX + 10, i * 30 + positionY - 6); var pntRnd2 = new Point(j * positionX + 30, i * 30 + positionY - 6); var pntRnd3 = new Point(j * positionX + 10, i * 30 + positionY + 6); var pntRnd4 = new Point(j * positionX + 30, i * 30 + positionY + 6); var penRnd = new Pen(LayoutColors.ComparatorChartRandomBands, 2); Brush brushRnd = new SolidBrush(LayoutColors.ComparatorChartRandomArea); g.FillRectangle(brushRnd, new Rectangle(pntRnd1.X, pntRnd1.Y, pntRnd2.X - pntRnd1.X, pntRnd4.Y - pntRnd2.Y)); g.DrawLine(penRnd, pntRnd1, pntRnd2); g.DrawLine(penRnd, pntRnd3, pntRnd4); pen = new Pen(LayoutColors.ComparatorChartRandomLine); break; } pen.Width = 2; g.DrawLine(pen, pt1, pt2); } else { var pt1 = new Point(j * positionX + 10, i * 30 + positionY); var pt2 = new Point(j * positionX + 30, i * 30 + positionY); var pen = new Pen(LayoutColors.ComparatorChartBalanceLine) { Width = 3 }; g.DrawLine(pen, pt1, pt2); } num++; } } }
/// <summary> /// Sets the chart params /// </summary> protected override void OnPaint(PaintEventArgs e) { var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); try { g.Clear(LayoutColors.ColorChartBack); } catch (Exception exception) { Console.WriteLine(exception.Message); } Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); g.DrawString(caption, fontCaption, brushCaption, rectfCaption, stringFormatCaption); g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); if (tickData == null || tickData.Length < 2) { string text = Language.T("Waiting for ticks..."); g.DrawString(text, fontCaption, penChart.Brush, chartArea); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); return; } int ticks = tickData.Length; double maximum = double.MinValue; double minimum = double.MaxValue; foreach (double tick in tickData) { if (maximum < tick) { maximum = tick; } if (minimum > tick) { minimum = tick; } } maximum += point; minimum -= point; const int space = Border + 2; const int xLeft = space; int xRight = ClientSize.Width - space; double scaleX = (xRight - xLeft) / ((double)ticks - 1); int yTop = (int)captionHeight + space; int yBottom = ClientSize.Height - space; double scaleY = (yBottom - yTop) / (maximum - minimum); int index = 0; var apntTick = new PointF[ticks]; foreach (double tick in tickData) { apntTick[index].X = (float)(xLeft + index * scaleX); apntTick[index].Y = (float)(yBottom - (tick - minimum) * scaleY); index++; } g.DrawLines(penChart, apntTick); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Paints the journal /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); int hScroll = -hScrollBar.Value; var size = new Size(visibleWidth, rowHeight); var sf = new StringFormat { Alignment = StringAlignment.Center }; // Caption background var rectCaption = new RectangleF(0, 0, ClientSize.Width, 2 * rowHeight); Data.GradientPaint(g, rectCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); Color colorBack = LayoutColors.ColorControlBack; var brushCaptionText = new SolidBrush(LayoutColors.ColorCaptionText); var brushEvenRowBack = new SolidBrush(LayoutColors.ColorEvenRowBack); var brushRowText = new SolidBrush(LayoutColors.ColorControlText); var penLines = new Pen(LayoutColors.ColorJournalLines); var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), Border); var font = new Font(Font.FontFamily, 9); // Print the journal caption string caption = Language.T("Positions During the Bar") + (Configs.AccountInMoney ? " [" + Configs.AccountCurrency + "]" : " [" + Language.T("points") + "]"); g.DrawString(caption, font, brushCaptionText, new RectangleF(Point.Empty, size), sf); g.SetClip(new RectangleF(Border, rowHeight, ClientSize.Width - 2 * Border, rowHeight)); if (Configs.AccountInMoney) { for (int i = 0; i < columns; i++) { g.DrawString(titlesMoney[i], font, brushCaptionText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, rowHeight, sf); } } else { for (int i = 0; i < columns; i++) { g.DrawString(titlesPoints[i], font, brushCaptionText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, rowHeight, sf); } } g.ResetClip(); // Paints the journal's data field var rectField = new RectangleF(Border, 2 * rowHeight, ClientSize.Width - 2 * Border, ClientSize.Height - 2 * rowHeight - Border); g.FillRectangle(new SolidBrush(colorBack), rectField); size = new Size(ClientSize.Width - vScrollBar.Width - 2 * Border, rowHeight); // Prints the journal data for (int pos = firstPos; pos < firstPos + shownPos; pos++) { int row = pos - firstPos; int y = (row + 2) * rowHeight; var point = new Point(Border, y); // Even row if (Math.Abs(row % 2f - 0) > 0.0001) { g.FillRectangle(brushEvenRowBack, new Rectangle(point, size)); } // Draw the position icon int iImgY = y + (int)Math.Floor((rowHeight - 16) / 2.0); g.DrawImage(positionIcons[pos - firstPos], hScroll + 2, iImgY, 16, 16); // Prints the data g.DrawString(journalData[row, 0], font, brushRowText, hScroll + (16 + xScaled[1]) / 2, (row + 2) * rowHeight, sf); for (int i = 1; i < columns; i++) { g.DrawString(journalData[row, i], font, brushRowText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, (row + 2) * rowHeight, sf); } } for (int i = 1; i < columns; i++) { g.DrawLine(penLines, xScaled[i] + hScroll, 2 * rowHeight, xScaled[i] + hScroll, ClientSize.Height); } // Border g.DrawLine(penBorder, 1, 2 * rowHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, 2 * rowHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Form On Paint /// </summary> protected override void OnPaint(PaintEventArgs e) { Data.GradientPaint(e.Graphics, ClientRectangle, LayoutColors.ColorFormBack, LayoutColors.DepthControl); }
/// <summary> /// Repaint the panel Info /// </summary> private void PnlInfoPaint(object sender, PaintEventArgs e) { // +------------------------------------------------------+ // | Data | // |------------------- ----------------------------------+ // | Period | Bars | From | Until | Cover | % | Label | // |------------------------------------------------------+ //xp0 xp1 xp2 xp3 xp4 xp5 xp6 xp7 Graphics g = e.Graphics; g.Clear(LayoutColors.ColorControlBack); if (!Data.IsData || !Data.IsResult) { return; } var pnl = (Panel)sender; const int border = 2; const int xp0 = border; const int xp1 = 80; const int xp2 = 140; const int xp3 = 200; const int xp4 = 260; const int xp5 = 320; const int xp6 = 370; int xp7 = pnl.ClientSize.Width - border; var size = new Size(xp7 - xp0, infoRowHeight); var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near }; // Caption background var pntStart = new PointF(0, 0); SizeF szfCaption = new Size(pnl.ClientSize.Width - 0, 2 * infoRowHeight); var rectfCaption = new RectangleF(pntStart, szfCaption); Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); // Caption Text var stringFormatCaption = new StringFormat { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap, Alignment = StringAlignment.Near }; string stringCaptionText = Language.T("Intrabar Data"); float captionWidth = Math.Min(InfoPanel.ClientSize.Width, xp7 - xp0); float captionTextWidth = g.MeasureString(stringCaptionText, fontInfo).Width; float captionTextX = Math.Max((captionWidth - captionTextWidth) / 2f, 0); var pfCaptionText = new PointF(captionTextX, 0); var sfCaptionText = new SizeF(captionWidth - captionTextX, infoRowHeight); rectfCaption = new RectangleF(pfCaptionText, sfCaptionText); Brush brush = new SolidBrush(LayoutColors.ColorCaptionText); // First caption row g.DrawString(stringCaptionText, fontInfo, brush, rectfCaption, stringFormatCaption); // Second title row g.DrawString(Language.T("Period"), fontInfo, brush, (xp1 + xp0) / 2f, infoRowHeight, sf); g.DrawString(Language.T("Bars"), fontInfo, brush, (xp2 + xp1) / 2f, infoRowHeight, sf); g.DrawString(Language.T("From"), fontInfo, brush, (xp3 + xp2) / 2f, infoRowHeight, sf); g.DrawString(Language.T("Until"), fontInfo, brush, (xp4 + xp3) / 2f, infoRowHeight, sf); g.DrawString(Language.T("Coverage"), fontInfo, brush, (xp5 + xp4) / 2f, infoRowHeight, sf); g.DrawString("%", fontInfo, brush, (xp6 + xp5) / 2f, infoRowHeight, sf); g.DrawString(Language.T("Label"), fontInfo, brush, (xp7 + xp6) / 2f, infoRowHeight, sf); brush = new SolidBrush(LayoutColors.ColorControlText); int allPeriods = Enum.GetValues(typeof(DataPeriod)).Length; for (int period = 0; period <= allPeriods; period++) { int y = (period + 2) * infoRowHeight; var point = new Point(xp0, y); if (Math.Abs(period % 2f - 0) > 0.0001) { g.FillRectangle(new SolidBrush(LayoutColors.ColorEvenRowBack), new Rectangle(point, size)); } } // Tick statistics if (isTickDataFile) { g.DrawString(Language.T("Tick"), fontInfo, brush, (xp1 + xp0) / 2, 2 * infoRowHeight, sf); if (Data.IsTickData && Configs.UseTickData) { int firstBarWithTicks = -1; int lastBarWithTicks = -1; int tickBars = 0; for (int b = 0; b < Data.Bars; b++) { if (firstBarWithTicks == -1 && Data.TickData[b] != null) { firstBarWithTicks = b; } if (Data.TickData[b] != null) { lastBarWithTicks = b; tickBars++; } } double percentage = 100d * tickBars / Data.Bars; int y = 2 * infoRowHeight; string ticks = (Data.Ticks > 999999) ? (Data.Ticks / 1000).ToString(CultureInfo.InvariantCulture) + "K" : Data.Ticks.ToString(CultureInfo.InvariantCulture); g.DrawString(ticks, fontInfo, brush, (xp2 + xp1) / 2, y, sf); g.DrawString((firstBarWithTicks + 1).ToString(CultureInfo.InvariantCulture), fontInfo, brush, (xp3 + xp2) / 2, y, sf); g.DrawString((lastBarWithTicks + 1).ToString(CultureInfo.InvariantCulture), fontInfo, brush, (xp4 + xp3) / 2, y, sf); g.DrawString(tickBars.ToString(CultureInfo.InvariantCulture), fontInfo, brush, (xp5 + xp4) / 2, y, sf); g.DrawString(percentage.ToString("F2"), fontInfo, brush, (xp6 + xp5) / 2, y, sf); var rectf = new RectangleF(xp6 + 10, y + 4, xp7 - xp6 - 20, 9); Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriod.M1], 60); rectf = new RectangleF(xp6 + 10, y + 7, xp7 - xp6 - 20, 3); Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriod.D1], 60); } } for (int prd = 0; prd < allPeriods; prd++) { int startY = isTickDataFile ? 3 : 2; int y = (prd + startY) * infoRowHeight; var period = (DataPeriod)Enum.GetValues(typeof(DataPeriod)).GetValue(prd); int intraBars = Data.IntraBars == null || !Data.IsIntrabarData ? 0 : Data.IntraBars[prd]; int fromBar = 0; int untilBar = 0; int coveredBars = 0; double percentage = 0; bool isMultyAreas = false; if (intraBars > 0) { bool isFromBarFound = false; bool isUntilBarFound = false; untilBar = Data.Bars; for (int bar = 0; bar < Data.Bars; bar++) { if (!isFromBarFound && Data.IntraBarsPeriods[bar] == period) { fromBar = bar; isFromBarFound = true; } if (isFromBarFound && !isUntilBarFound && (Data.IntraBarsPeriods[bar] != period || bar == Data.Bars - 1)) { if (bar < Data.Bars - 1) { isUntilBarFound = true; untilBar = bar; } else { untilBar = Data.Bars; } coveredBars = untilBar - fromBar; } if (isFromBarFound && isUntilBarFound && Data.IntraBarsPeriods[bar] == period) { isMultyAreas = true; coveredBars++; } } if (isFromBarFound) { percentage = 100d * coveredBars / Data.Bars; fromBar++; } else { fromBar = 0; untilBar = 0; coveredBars = 0; percentage = 0; } } else if (period == Data.Period) { intraBars = Data.Bars; fromBar = 1; untilBar = Data.Bars; coveredBars = Data.Bars; percentage = 100; } g.DrawString(Data.DataPeriodToString(period), fontInfo, brush, (xp1 + xp0) / 2, y, sf); if (coveredBars > 0 || period == Data.Period) { g.DrawString(intraBars.ToString(CultureInfo.InvariantCulture), fontInfo, brush, (xp2 + xp1) / 2, y, sf); g.DrawString(fromBar.ToString(CultureInfo.InvariantCulture), fontInfo, brush, (xp3 + xp2) / 2, y, sf); g.DrawString(untilBar.ToString(CultureInfo.InvariantCulture), fontInfo, brush, (xp4 + xp3) / 2, y, sf); g.DrawString(coveredBars.ToString(CultureInfo.InvariantCulture) + (isMultyAreas ? "*" : ""), fontInfo, brush, (xp5 + xp4) / 2, y, sf); g.DrawString(percentage.ToString("F2"), fontInfo, brush, (xp6 + xp5) / 2, y, sf); var rectf = new RectangleF(xp6 + 10, y + 4, xp7 - xp6 - 20, 9); Data.GradientPaint(g, rectf, Data.PeriodColor[period], 60); } } var penLine = new Pen(LayoutColors.ColorJournalLines); g.DrawLine(penLine, xp1, 2 * infoRowHeight, xp1, pnl.ClientSize.Height); g.DrawLine(penLine, xp2, 2 * infoRowHeight, xp2, pnl.ClientSize.Height); g.DrawLine(penLine, xp3, 2 * infoRowHeight, xp3, pnl.ClientSize.Height); g.DrawLine(penLine, xp4, 2 * infoRowHeight, xp4, pnl.ClientSize.Height); g.DrawLine(penLine, xp5, 2 * infoRowHeight, xp5, pnl.ClientSize.Height); g.DrawLine(penLine, xp6, 2 * infoRowHeight, xp6, pnl.ClientSize.Height); // Border var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border); g.DrawLine(penBorder, 1, 2 * infoRowHeight, 1, pnl.ClientSize.Height); g.DrawLine(penBorder, pnl.ClientSize.Width - border + 1, 2 * infoRowHeight, pnl.ClientSize.Width - border + 1, pnl.ClientSize.Height); g.DrawLine(penBorder, 0, pnl.ClientSize.Height - border + 1, pnl.ClientSize.Width, pnl.ClientSize.Height - border + 1); }
/// <summary> /// Paints the chart /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); var chartArea = new Rectangle(Border, (int)captionHeight, ClientSize.Width - 2 * Border, ClientSize.Height - (int)captionHeight - Border); Data.GradientPaint(g, chartArea, LayoutColors.ColorChartBack, LayoutColors.DepthControl); // Panel caption Data.GradientPaint(g, captionRectangle, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); g.DrawString(captionText, captionFont, captionBrush, captionRectangle, captionStringFormat); // Border g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); if (!Data.IsData || !Data.IsResult || Data.Bars <= StatsBuffer.FirstBar) { return; } // Limits the drawing into the chart area only g.SetClip(new Rectangle(xLeft, yTop, xRight - xLeft, yPriceBottom - yTop)); // Draws Volume, Lots and Price int index = 0; for (int bar = chartFirstBar; bar <= chartLastBar; bar++) { // Draw the volume if (yVolume[index] != yPriceBottom) { g.DrawLine(penVolume, axisX[index], yVolume[index], axisX[index], yPriceBottom - 1); } // Draw position lots if (rectPosition[index] != Rectangle.Empty) { g.FillRectangle(brushPosition[index], rectPosition[index]); } // Draw the bar var penBar = new Pen(LayoutColors.ColorBarBorder); g.DrawLine(penBar, axisX[index], yLow[index], axisX[index], yHigh[index]); g.DrawLine(penBar, axisX[index], yClose[index], axisX[index] + 1, yClose[index]); index++; } // Drawing the indicators in the chart int slots = StatsBuffer.Strategy.Slots; for (int slot = 0; slot < slots; slot++) { if (isSeparatedChart[slot]) { continue; } for (int comp = 0; comp < componentLength[slot]; comp++) { switch (chartType[slot][comp]) { case IndChartType.Line: g.DrawLines(new Pen(chartBrush[slot][comp]), chartLine[slot][comp]); break; case IndChartType.Dot: for (int bar = chartFirstBar; bar <= chartLastBar; bar++) { g.FillRectangle(chartBrush[slot][comp], chartDot[slot][comp][bar - chartFirstBar]); } break; case IndChartType.Level: for (int bar = chartFirstBar; bar <= chartLastBar; bar++) { g.FillRectangle(chartBrush[slot][comp], chartLevel[slot][comp][bar - chartFirstBar]); } break; case IndChartType.CloudUp: g.DrawLines(new Pen(chartBrush[slot][comp]) { DashStyle = DashStyle.Dash }, chartLine[slot][comp]); break; case IndChartType.CloudDown: g.DrawLines(new Pen(chartBrush[slot][comp]) { DashStyle = DashStyle.Dash }, chartLine[slot][comp]); break; } } } g.ResetClip(); // Separate indicators for (int ind = 0; ind < separateIndicatorsCount; ind++) { int slot = indicatorSlots[ind]; for (int comp = 0; comp < componentLength[slot]; comp++) { switch (chartType[slot][comp]) { case IndChartType.Line: g.DrawLines(new Pen(chartBrush[slot][comp]), chartLine[slot][comp]); break; case IndChartType.Histogram: double zero = 0; if (zero < minValues[ind]) { zero = minValues[ind]; } if (zero > maxValues[ind]) { zero = maxValues[ind]; } var y0 = (int)(yIndBottom[ind] - (zero - minValues[ind]) * scales[ind]); g.DrawLine(penDarkGray, xLeft, y0, xRight, y0); for (int bar = chartFirstBar; bar <= chartLastBar; bar++) { double val = chartValue[slot][comp][bar - chartFirstBar]; int x = (bar - chartFirstBar) * chartBarWidth + xLeft; var y = (int)(yIndBottom[ind] - (val - minValues[ind]) * scales[ind]); g.DrawLine(chartPen[slot][comp][bar - chartFirstBar], x, y0, x, y); } break; } } } // Lines for (int ind = 0; ind < separateIndicatorsCount; ind++) { int y = yBottom - (ind + 1) * separateIndicatorsChartHeight; g.DrawLine(penFore, xLeft, y, xRight, y); } g.DrawLine(penFore, xLeft, yBottom, xRight, yBottom); g.DrawLine(penFore, xLeft, yTop, xLeft, yBottom); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Paints the chart /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); // Caption bar Data.GradientPaint(g, rectCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); g.DrawString(strChartTitle, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectCaption, sfCaption); // Border g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); // Paints the background by gradient var rectField = new RectangleF(Border, captionHeight, ClientSize.Width - 2 * Border, ClientSize.Height - captionHeight - Border); Data.GradientPaint(g, rectField, LayoutColors.ColorChartBack, LayoutColors.DepthControl); if (isNotPaint) { return; } string unit = " [" + (Configs.AccountInMoney ? Configs.AccountCurrency : Language.T("points")) + "]"; string subHeader = isCounts ? Language.T("Count of Trades") : Language.T("Accumulated Amount") + unit; g.DrawString(subHeader, Font, new SolidBrush(LayoutColors.ColorChartFore), rectSubHeader, sfCaption); var formatCenter = new StringFormat { Alignment = StringAlignment.Center }; // Grid and Price labels for (int label = xAxisMin10; label <= xAxisMax; label += stepX) { float xPoint = xLeft + ((xAxisMin10 - xAxisMin) + (label - xAxisMin10)) * xScale; float yPoint = yBottom - Font.Height; if (xPoint <= xRight - labelWidthX / 2) { g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, brushFore, xPoint, yPoint, formatCenter); } } for (int label = yAxisMin; label <= yAxisMax; label += stepY) { var labelY = (int)(xAxisY - (label - yAxisMin) * yScale); if (label > -1) { g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, brushFore, xRight, labelY - Font.Height / 2 - 1); } g.DrawLine(penGrid, xLeft, labelY, xRight, labelY); } foreach (var data in chartData) { double val = isCounts ? data.Value.TradesCount : Math.Abs(data.Value.TotalResult); float xPt = xLeft + (data.Key - minIndex + 1) * xScale; float yPtBottom = xAxisY; var yPtTop = (float)(xAxisY - (val - yAxisMin) * yScale); Color color = isCounts ? Color.Blue : data.Value.TotalResult < 0 ? Color.Red : Color.Green; g.DrawLine(new Pen(color), xPt, yPtBottom, xPt, yPtTop); } // Coordinate axes g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, yTop - Space, xLeft - 1, xAxisY); g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, xAxisY, xRight, xAxisY); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Paints the chart /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); // Caption bar Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); g.DrawString(chartTitle, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectfCaption, stringFormatCaption); // Border g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); // Paints the background by gradient var rectChartField = new RectangleF(Border, captionHeight, ClientSize.Width - 2 * Border, ClientSize.Height - captionHeight - Border); Data.GradientPaint(g, rectChartField, LayoutColors.ColorChartBack, LayoutColors.DepthControl); if (isNotPaint) { return; } // Grid and Price labels for (int labelPrice = data.Minimum; labelPrice <= data.Minimum + countLabels * labelStep; labelPrice += labelStep) { var labelY = (int)(yBottom - (labelPrice - data.Minimum) * yScale); g.DrawString(labelPrice.ToString(CultureInfo.InvariantCulture), Font, brushFore, xRight, labelY - Font.Height / 2 - 1); g.DrawLine(penGrid, xLeft, labelY, xRight, labelY); } // Price close if (showPriceLine) { g.DrawLines(new Pen(LayoutColors.ColorChartGrid), closePricePoints); } // Equity line g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), equityPoints); // Draw Long and Short balance if (Configs.AdditionalStatistics) { g.DrawLines(new Pen(Color.Red), shortBalancePoints); g.DrawLines(new Pen(Color.Green), longBalancePoints); } // Out of Sample if (IsOOS && OOSBar > 0) { g.DrawLine(new Pen(LayoutColors.ColorChartFore), xOOSBar, yTop, xOOSBar, yBottom); Brush brushOOS = new Pen(LayoutColors.ColorChartFore).Brush; g.DrawString("OOS", Font, brushOOS, xOOSBar, yBottom - Font.Height); float widthOOSBarDate = g.MeasureString(data.DataTimeBarOOS.ToShortDateString(), Font).Width; g.DrawString(data.DataTimeBarOOS.ToShortDateString(), Font, brushOOS, xOOSBar - widthOOSBarDate, yBottom - Font.Height); } // Draw Balance Line if (data.MarginCallBar > 0) // In case of Margin Call { // Draw balance line up to Margin Call var balPoints = new PointF[data.MarginCallBar - data.FirstBar]; for (int i = 0; i < balPoints.Length; i++) { balPoints[i] = balancePoints[i]; } if (balPoints.Length > 1) { g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), balPoints); } // Draw balance line after Margin Call var redBalancePoints = new PointF[data.Bars - data.MarginCallBar]; for (int i = 0; i < redBalancePoints.Length; i++) { redBalancePoints[i] = balancePoints[i + data.MarginCallBar - data.FirstBar]; } g.DrawLines(new Pen(LayoutColors.ColorSignalRed), redBalancePoints); // Margin Call line g.DrawLine(new Pen(LayoutColors.ColorChartCross), xMarginCallBar, yTop, xMarginCallBar, yBottom); // Margin Call label float widthMarginCallLabel = g.MeasureString(Language.T("Margin Call"), Font).Width; if (xMarginCallBar < xRight - widthMarginCallLabel) { g.DrawString(Language.T("Margin Call"), Font, brushFore, xMarginCallBar, yTop); } else if (xMarginCallBar > Space + widthMarginCallLabel) { g.DrawString(Language.T("Margin Call"), Font, brushFore, xMarginCallBar - widthMarginCallLabel, yTop); } else { g.DrawString("MC", Font, brushFore, xMarginCallBar, yTop); } } else { // Draw the balance line g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), balancePoints); } // Scanning note var fontNote = new Font(Font.FontFamily, Font.Size - 1); if (Data.Period != DataPeriod.M1 && Configs.Autoscan && !Data.IsIntrabarData) { g.DrawString(Language.T("Load intrabar data"), fontNote, Brushes.Red, xLeft, captionHeight - 2); } else if (Data.Period != DataPeriod.M1 && isScanPerformed) { g.DrawString(Language.T("Scanned") + data.ModellingQuolity, fontNote, Brushes.LimeGreen, xLeft, captionHeight - 2); } // Scanned bars if (isScanPerformed && !isHideScanningLine && (Data.IntraBars != null && Data.IsIntrabarData || Data.Period == DataPeriod.M1 && Data.IsTickData && Configs.UseTickData)) { DataPeriod dataPeriod = Data.Period; Color color = Data.PeriodColor[Data.Period]; int fromBar = data.FirstBar; for (int bar = data.FirstBar; bar < data.Bars; bar++) { if (Data.IntraBarsPeriods[bar] == dataPeriod && bar != data.Bars - 1) { continue; } int xStart = (int)((fromBar - data.FirstBar) * xScale) + xLeft; int xEnd = (int)((bar - data.FirstBar) * xScale) + xLeft; fromBar = bar; dataPeriod = Data.IntraBarsPeriods[bar]; Data.GradientPaint(g, new RectangleF(xStart, yBottom + 4, xEnd - xStart + 2, 5), color, 60); color = Data.PeriodColor[Data.IntraBarsPeriods[bar]]; } // Tick Data if (Data.IsTickData && Configs.UseTickData) { int firstBarWithTicks = -1; int lastBarWithTicks = -1; for (int b = 0; b < data.Bars; b++) { if (firstBarWithTicks == -1 && Data.TickData[b] != null) { firstBarWithTicks = b; } if (Data.TickData[b] != null) { lastBarWithTicks = b; } } int xStart = (int)(firstBarWithTicks * xScale) + xLeft; int xEnd = (int)((lastBarWithTicks - data.FirstBar) * xScale) + xLeft; if (xStart < xLeft) { xStart = xLeft; } if (xEnd < xStart) { xEnd = xStart; } Data.DrawCheckerBoard(g, Color.ForestGreen, new Rectangle(xStart, yBottom + 5, xEnd - xStart + 2, 3)); } // Vertical coordinate axes g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, yBottom, xLeft - 1, yBottom + 9); } // Coordinate axes g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, yTop - Space, xLeft - 1, yBottom + 1); g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, yBottom + 1, xRight, yBottom + 1); // Balance level g.DrawLine(new Pen(LayoutColors.ColorChartCross), xLeft, yBalance, xRight - Space + 1, yBalance); // Balance label var labelSize = new Size(labelWidth + Space, Font.Height + 2); var labelPoint = new Point(xRight - Space + 2, (int)(yBalance - Font.Height / 2.0 - 1)); var labelRect = new Rectangle(labelPoint, labelSize); g.FillRectangle(new SolidBrush(LayoutColors.ColorLabelBack), labelRect); g.DrawRectangle(new Pen(LayoutColors.ColorChartCross), labelRect); g.DrawString((Math.Round(data.NetBalance)).ToString(CultureInfo.InvariantCulture), Font, new SolidBrush(LayoutColors.ColorLabelText), labelRect, stringFormatCaption); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Paints the journal /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); int hScroll = -HScrollBar.Value; var sf = new StringFormat { Alignment = StringAlignment.Center }; // Caption background var rectCaption = new RectangleF(0, 0, ClientSize.Width, 2 * rowHeight); Data.GradientPaint(g, rectCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); var font = new Font(Font.FontFamily, 9); Color colorBack = LayoutColors.ColorControlBack; var brushCaptionText = new SolidBrush(LayoutColors.ColorCaptionText); var brushEvenRowBack = new SolidBrush(LayoutColors.ColorEvenRowBack); var brushSelectedRowBack = new SolidBrush(LayoutColors.ColorSelectedRowBack); var brushSelectedRowText = new SolidBrush(LayoutColors.ColorSelectedRowText); var brushRowText = new SolidBrush(LayoutColors.ColorControlText); var brushWarningBack = new SolidBrush(LayoutColors.ColorWarningRowBack); var brushWarningText = new SolidBrush(LayoutColors.ColorWarningRowText); var penLines = new Pen(LayoutColors.ColorJournalLines); var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), Border); // Print the journal caption string unit = Configs.AccountInMoney ? " [" + Configs.AccountCurrency + "]" : " [" + Language.T("points") + "]"; string accUnit = " [" + Configs.AccountCurrency + "]"; g.SetClip(new RectangleF(Border, 0, ClientSize.Width - 2 * Border, 2 * rowHeight)); g.DrawString(Language.T("Market Data"), font, brushCaptionText, hScroll + (xScaled[8] + xScaled[0]) / 2, 0, sf); g.DrawString(Language.T("Summary") + unit, font, brushCaptionText, hScroll + (xScaled[14] + xScaled[8]) / 2, 0, sf); g.DrawString(Language.T("Account") + unit, font, brushCaptionText, hScroll + (xScaled[16] + xScaled[14]) / 2, 0, sf); g.DrawString(Language.T("Margin") + accUnit, font, brushCaptionText, hScroll + (xScaled[18] + xScaled[16]) / 2, 0, sf); g.DrawString(Language.T("Backtest"), font, brushCaptionText, hScroll + (xScaled[19] + xScaled[18]) / 2, 0, sf); if (Configs.AccountInMoney) { for (int i = 0; i < columns; i++) { g.DrawString(titlesInMoney[i], font, brushCaptionText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, rowHeight, sf); } } else { for (int i = 0; i < columns; i++) { g.DrawString(titlesInPoints[i], font, brushCaptionText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, rowHeight, sf); } } g.ResetClip(); var rectField = new RectangleF(Border, 2 * rowHeight, ClientSize.Width - 2 * Border, ClientSize.Height - 2 * rowHeight - Border); g.FillRectangle(new SolidBrush(colorBack), rectField); var size = new Size(ClientSize.Width - VScrollBar.Width - 2 * Border, rowHeight); // Prints the journal data for (int bar = firstBar; bar < firstBar + shownBars; bar++) { int y = (bar - firstBar + 2) * rowHeight; var point = new Point(Border, y); // Even row if (Math.Abs((bar - firstBar) % 2f - 0) > 0.0001) { g.FillRectangle(brushEvenRowBack, new Rectangle(point, size)); } // Warning row bool isWarningRow = false; if (journalData[bar - firstBar, columns - 1] == Language.T("Ambiguous")) { g.FillRectangle(brushWarningBack, new Rectangle(point, size)); isWarningRow = true; } // Selected row Brush brush; if (bar - firstBar == selectedRow) { g.FillRectangle(brushSelectedRowBack, new Rectangle(point, size)); brush = brushSelectedRowText; } else { brush = isWarningRow ? brushWarningText : brushRowText; } int index = bar - firstBar; // Draw the position icon int imgY = y + (int)Math.Floor((rowHeight - 16) / 2.0); g.DrawImage(positionIcons[index], hScroll + 2, imgY, 16, 16); // Prints the data g.DrawString(journalData[index, 0], font, brush, hScroll + (16 + xScaled[1]) / 2, (index + 2) * rowHeight, sf); for (int i = 1; i < columns; i++) { g.DrawString(journalData[index, i], font, brush, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, (index + 2) * rowHeight, sf); } } // Vertical grid lines for (int i = 1; i < columns; i++) { if (i == 8 || i == 14 || i == 16 || i == 18) { var rectSeparator = new RectangleF(xScaled[i] + hScroll, (float)(rowHeight / 2.0), 1, (float)(3 * rowHeight / 2.0)); Data.GradientPaint(g, rectSeparator, LayoutColors.ColorCaptionBack, -2 * LayoutColors.DepthCaption); } g.DrawLine(penLines, xScaled[i] + hScroll, 2 * rowHeight, xScaled[i] + hScroll, ClientSize.Height); } // Borders g.DrawLine(penBorder, 1, 2 * rowHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, 2 * rowHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); OnSelectedBarChange(new EventArgs()); }
/// <summary> /// Paints the journal /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); // Caption background var rectCaption = new RectangleF(0, 0, ClientSize.Width, 2 * rowHeight); Data.GradientPaint(g, rectCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); int hScroll = -HScrollBar.Value; //var size = new Size(ContextButtonLocation.X, rowHeight); var size = new Size(ClientSize.Width, rowHeight); var sf = new StringFormat { Alignment = StringAlignment.Center }; // Print the journal caption string stringCaptionText = Language.T("Orders During the Bar") + (Configs.AccountInMoney ? " [" + Configs.AccountCurrency + "]" : " [" + Language.T("points") + "]"); g.DrawString(stringCaptionText, font, brushCaptionText, new RectangleF(Point.Empty, size), sf); g.SetClip(new RectangleF(Border, rowHeight, ClientSize.Width - 2 * Border, rowHeight)); if (Configs.AccountInMoney) { for (int i = 0; i < columns; i++) { g.DrawString(titlesMoney[i], font, brushCaptionText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, rowHeight, sf); } } else { for (int i = 0; i < columns; i++) { g.DrawString(titlesPoints[i], font, brushCaptionText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, rowHeight, sf); } } g.ResetClip(); // Paints the journal's data field var rectField = new RectangleF(Border, 2 * rowHeight, ClientSize.Width - 2 * Border, ClientSize.Height - 2 * rowHeight - Border); g.FillRectangle(new SolidBrush(colorBack), rectField); size = new Size(ClientSize.Width - VScrollBar.Width - 2 * Border, rowHeight); // Prints the journal data for (int ord = firstOrd; ord < firstOrd + shownOrd; ord++) { int row = ord - firstOrd; if (journalData == null || journalData[row, 0] == null) { Console.WriteLine("Break"); break; } int y = (row + 2) * rowHeight; var point = new Point(Border, y); // Even row if (Math.Abs(row % 2f - 0) > 0.0001) { g.FillRectangle(brushEvenRowBack, new Rectangle(point, size)); } // Draw the position icon int iImgY = y + (int)Math.Floor((rowHeight - 16) / 2.0); g.DrawImage(orderIcons[row], hScroll + 2, iImgY, 16, 16); // Prints the data g.DrawString(journalData[row, 0], font, brushRowText, hScroll + (16 + xScaled[1]) / 2, (row + 2) * rowHeight, sf); for (int i = 1; i < columns; i++) { if (i == columns - 1) { g.DrawString(journalData[row, i], font, brushRowText, hScroll + xScaled[i], (row + 2) * rowHeight); } else { g.DrawString(journalData[row, i], font, brushRowText, hScroll + (xScaled[i] + xScaled[i + 1]) / 2, (row + 2) * rowHeight, sf); } } } for (int i = 1; i < columns; i++) { g.DrawLine(penLines, xScaled[i] + hScroll, 2 * rowHeight, xScaled[i] + hScroll, ClientSize.Height); } // Border g.DrawLine(penBorder, 1, 2 * rowHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, 2 * rowHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Panel properties Paint /// </summary> private void PnlPropertiesPaint(object sender, PaintEventArgs e) { var pnl = (Panel)sender; Graphics g = e.Graphics; int iWidth = pnl.ClientSize.Width; Color colorCaptionBack = LayoutColors.ColorSlotCaptionBackAveraging; Color colorCaptionText = LayoutColors.ColorSlotCaptionText; Color colorBackground = LayoutColors.ColorSlotBackground; Color colorLogicText = LayoutColors.ColorSlotLogicText; Color colorDash = LayoutColors.ColorSlotDash; // Caption string stringCaptionText = Language.T("Strategy Properties"); var fontCaptionText = new Font(Font.FontFamily, 9); float fCaptionHeight = Math.Max(fontCaptionText.Height, 18); float fCaptionWidth = iWidth; Brush brushCaptionText = new SolidBrush(colorCaptionText); var stringFormatCaption = new StringFormat { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap, Alignment = StringAlignment.Center }; var rectfCaption = new RectangleF(0, 0, fCaptionWidth, fCaptionHeight); Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption); g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption); // Border var penBorder = new Pen(Data.ColorChanage(colorCaptionBack, -LayoutColors.DepthCaption), Border); g.DrawLine(penBorder, 1, fCaptionHeight, 1, pnl.Height); g.DrawLine(penBorder, pnl.Width - Border + 1, fCaptionHeight, pnl.Width - Border + 1, pnl.Height); g.DrawLine(penBorder, 0, pnl.Height - Border + 1, pnl.Width, pnl.Height - Border + 1); // Paint the panel's background var rectfPanel = new RectangleF(Border, fCaptionHeight, pnl.Width - 2 * Border, pnl.Height - fCaptionHeight - Border); Data.GradientPaint(g, rectfPanel, colorBackground, LayoutColors.DepthControl); int iVPosition = (int)fCaptionHeight + 2; var stringFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }; var fontParam = new Font(Font.FontFamily, 9f, FontStyle.Regular); var fontValue = new Font(Font.FontFamily, 9f, FontStyle.Regular); Brush brushParam = new SolidBrush(colorLogicText); Brush brushValue = new SolidBrush(colorLogicText); var penDash = new Pen(colorDash); string strPermaSL = strategy.UsePermanentSL ? (Data.Strategy.PermanentSLType == PermanentProtectionType.Absolute ? "(Abs) " : "") + strategy.PermanentSL.ToString(CultureInfo.InvariantCulture) : Language.T("None"); string strPermaTP = strategy.UsePermanentTP ? (Data.Strategy.PermanentTPType == PermanentProtectionType.Absolute ? "(Abs) " : "") + strategy.PermanentTP.ToString(CultureInfo.InvariantCulture) : Language.T("None"); string strBreakEven = strategy.UseBreakEven ? strategy.BreakEven.ToString(CultureInfo.InvariantCulture) : Language.T("None"); if (slotMinMidMax == SlotSizeMinMidMax.Min) { string sParam = Language.T(strategy.SameSignalAction.ToString()) + "; " + Language.T(strategy.OppSignalAction.ToString()) + "; " + "SL-" + strPermaSL + "; " + "TP-" + strPermaTP + "; " + "BE-" + strBreakEven; SizeF sizeParam = g.MeasureString(sParam, fontParam); float fMaxParamWidth = sizeParam.Width; // Padding Param Padding Dash Padding Value Padding float fPadding = Space; float fNecessaryWidth = 2 * fPadding + fMaxParamWidth; fPadding = iWidth > fNecessaryWidth?Math.Max((pnl.ClientSize.Width - fMaxParamWidth) / 2, fPadding) : 2; float fTabParam = fPadding; var pointParam = new PointF(fTabParam, iVPosition); g.DrawString(sParam, fontParam, brushParam, pointParam); } else { // Find Maximum width of the strings var asParams = new[] { Language.T("Same direction signal"), Language.T("Opposite direction signal"), Language.T("Permanent Stop Loss"), Language.T("Permanent Take Profit"), Language.T("Break Even") }; var asValues = new[] { Language.T(strategy.SameSignalAction.ToString()), Language.T(strategy.OppSignalAction.ToString()), strPermaSL, strPermaTP, strBreakEven }; float fMaxParamWidth = 0; foreach (string param in asParams) { if (g.MeasureString(param, fontParam).Width > fMaxParamWidth) { fMaxParamWidth = g.MeasureString(param, fontParam).Width; } } float fMaxValueWidth = 0; foreach (string value in asValues) { if (g.MeasureString(value, fontParam).Width > fMaxValueWidth) { fMaxValueWidth = g.MeasureString(value, fontParam).Width; } } // Padding Param Padding Dash Padding Value Padding float fPadding = Space; const float fDashWidth = 5; float fNecessaryWidth = 4 * fPadding + fMaxParamWidth + fMaxValueWidth + fDashWidth; if (iWidth > fNecessaryWidth) { // 2*Padding Param Padding Dash Padding Value 2*Padding fPadding = Math.Max((pnl.ClientSize.Width - fMaxParamWidth - fMaxValueWidth - fDashWidth) / 6, fPadding); } else { fPadding = 2; } float fTabParam = 2 * fPadding; float fTabDash = fTabParam + fMaxParamWidth + fPadding; float fTabValue = fTabDash + fDashWidth + fPadding; // Same direction string sParam = Language.T("Same direction signal"); string sValue = Language.T(strategy.SameSignalAction.ToString()); var pointParam = new PointF(fTabParam, iVPosition); var pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(fTabValue, iVPosition); var sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); var rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); iVPosition += fontValue.Height + 2; // Opposite direction sParam = Language.T("Opposite direction signal"); sValue = Language.T(strategy.OppSignalAction.ToString()); pointParam = new PointF(fTabParam, iVPosition); pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); pointValue = new PointF(fTabValue, iVPosition); sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); iVPosition += fontValue.Height + 2; // Permanent Stop Loss sParam = Language.T("Permanent Stop Loss"); sValue = strPermaSL; pointParam = new PointF(fTabParam, iVPosition); pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); pointValue = new PointF(fTabValue, iVPosition); sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); iVPosition += fontValue.Height + 2; // Permanent Take Profit sParam = Language.T("Permanent Take Profit"); sValue = strPermaTP; pointParam = new PointF(fTabParam, iVPosition); pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); pointValue = new PointF(fTabValue, iVPosition); sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); iVPosition += fontValue.Height; // Break Even sParam = Language.T("Break Even"); sValue = strBreakEven; pointParam = new PointF(fTabParam, iVPosition); pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); pointValue = new PointF(fTabValue, iVPosition); sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); } }
/// <summary> /// On Paint /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); // Caption Data.GradientPaint(g, rectCaption, colorCaptionBack, LayoutColors.DepthCaption); g.DrawString(captionText, fontCaption, brushCaption, rectCaption, stringFormatCaption); for (int i = 0; i *rowHeight + captionHeight < height; i++) { float fVerticalPosition = i * rowHeight + captionHeight; var pointFParam = new PointF(paramTab + 2, fVerticalPosition); var pointFValue = new PointF(valueTab + 2, fVerticalPosition); var rectRow = new RectangleF(Border, fVerticalPosition, width, rowHeight); // Row background if (i + vScrollBar.Value < rows && flagsList[i + vScrollBar.Value]) { g.FillRectangle(new SolidBrush(colorBackroundWarningRow), rectRow); } else if (Math.Abs(i % 2f - 0) > 0.001) { g.FillRectangle(new SolidBrush(colorBackroundEvenRows), rectRow); } else { g.FillRectangle(new SolidBrush(colorBackroundOddRows), rectRow); } if (i + vScrollBar.Value >= rows) { continue; } if (i + vScrollBar.Value < rows && flagsList[i + vScrollBar.Value]) { Brush brush = new SolidBrush(colorTextWarningRow); g.DrawString(paramsList[i + vScrollBar.Value], fontData, brush, pointFParam, stringFormatData); g.DrawString(valuesList[i + vScrollBar.Value], fontData, brush, pointFValue, stringFormatData); } else { g.DrawString(paramsList[i + vScrollBar.Value], fontData, brushParams, pointFParam, stringFormatData); g.DrawString(valuesList[i + vScrollBar.Value], fontData, brushData, pointFValue, stringFormatData); } } // Border g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Paints the chart /// </summary> protected override void OnPaint(PaintEventArgs e) { var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); try { g.Clear(LayoutColors.ColorChartBack); } catch (Exception exception) { Console.WriteLine(exception.Message); } // Caption bar Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); g.DrawString(chartTitle, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectfCaption, stringFormatCaption); // Border g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, captionHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); if (balanceData == null || balanceData.Length < 1 || equityData == null || equityData.Length < 1) { DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); return; } // Grid and Price labels for (int iLabel = minValue; iLabel <= maxValue; iLabel += stepLabels) { var iLabelY = (int)(yBottom - (iLabel - minValue) * scaleY); g.DrawString(iLabel.ToString(".00"), Font, brushFore, xRight, iLabelY - Font.Height / 2 - 1); g.DrawLine(penGrid, xLeft, iLabelY, xRight, iLabelY); } // Equity and Balance lines g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), apntEquity); g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), apntBalance); // Coordinate axes g.DrawLine(new Pen(LayoutColors.ColorChartFore), xLeft - 1, yTop - Space, xLeft - 1, yBottom + 1 + Font.Height); // Equity price label. var pntEquity = new Point(xRight - Space + 2, (int)(equityY - font.Height / 2.0 - 1)); var sizeEquity = new Size(labelWidth + Space, font.Height + 2); string equity = (netEquity.ToString("F2")); var halfEquity = (int)(sizeEquity.Height / 2.0); var apEquity = new[] { new PointF(xRight - Space - 8, equityY), new PointF(xRight - Space, equityY - halfEquity), new PointF(xRight - Space + sizeEquity.Width + 5, equityY - halfEquity), new PointF(xRight - Space + sizeEquity.Width + 5, equityY + halfEquity), new PointF(xRight - Space, equityY + halfEquity) }; g.FillPolygon(new SolidBrush(LayoutColors.ColorChartEquityLine), apEquity); g.DrawString(equity, font, new SolidBrush(LayoutColors.ColorChartBack), pntEquity); // Balance price label. var pntBalance = new Point(xRight - Space + 2, (int)(balanceY - font.Height / 2.0 - 1)); var sizeBalance = new Size(labelWidth + Space, font.Height + 2); var halfBalance = (int)(sizeBalance.Height / 2.0); string balance = (netBalance.ToString("F2")); var apBalance = new[] { new PointF(xRight - Space - 8, balanceY), new PointF(xRight - Space, balanceY - halfBalance), new PointF(xRight - Space + sizeBalance.Width + 5, balanceY - halfBalance), new PointF(xRight - Space + sizeBalance.Width + 5, balanceY + halfBalance), new PointF(xRight - Space, balanceY + halfBalance) }; g.FillPolygon(new SolidBrush(LayoutColors.ColorChartBalanceLine), apBalance); g.DrawString(balance, font, new SolidBrush(LayoutColors.ColorChartBack), pntBalance); // Chart Text string chartText = startTime.ToString(CultureInfo.InvariantCulture); g.DrawString(chartText, font, new SolidBrush(LayoutColors.ColorChartFore), xLeft, yBottom); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); }
/// <summary> /// Panel Slot Paint /// </summary> private void PnlSlotPaint(object sender, PaintEventArgs e) { var pnl = (Panel)sender; Graphics g = e.Graphics; var iSlot = (int)pnl.Tag; int iWidth = pnl.ClientSize.Width; SlotTypes slotType = strategy.GetSlotType(iSlot); Color colorBackground = LayoutColors.ColorSlotBackground; Color colorCaptionText = LayoutColors.ColorSlotCaptionText; Color colorCaptionBackOpen = LayoutColors.ColorSlotCaptionBackOpen; Color colorCaptionBackOpenFilter = LayoutColors.ColorSlotCaptionBackOpenFilter; Color colorCaptionBackClose = LayoutColors.ColorSlotCaptionBackClose; Color colorCaptionBackCloseFilter = LayoutColors.ColorSlotCaptionBackCloseFilter; Color colorIndicatorNameText = LayoutColors.ColorSlotIndicatorText; Color colorLogicText = LayoutColors.ColorSlotLogicText; Color colorParamText = LayoutColors.ColorSlotParamText; Color colorValueText = LayoutColors.ColorSlotValueText; Color colorDash = LayoutColors.ColorSlotDash; // Caption string stringCaptionText = string.Empty; Color colorCaptionBack = LayoutColors.ColorSignalRed; switch (slotType) { case SlotTypes.Open: stringCaptionText = Language.T("Opening Point of the Position"); colorCaptionBack = colorCaptionBackOpen; break; case SlotTypes.OpenFilter: stringCaptionText = Language.T("Opening Logic Condition"); colorCaptionBack = colorCaptionBackOpenFilter; break; case SlotTypes.Close: stringCaptionText = Language.T("Closing Point of the Position"); colorCaptionBack = colorCaptionBackClose; break; case SlotTypes.CloseFilter: stringCaptionText = Language.T("Closing Logic Condition"); colorCaptionBack = colorCaptionBackCloseFilter; break; } var penBorder = new Pen(Data.ColorChanage(colorCaptionBack, -LayoutColors.DepthCaption), Border); var fontCaptionText = new Font(Font.FontFamily, 9); float fCaptionHeight = Math.Max(fontCaptionText.Height, 18); float fCaptionWidth = iWidth; Brush brushCaptionText = new SolidBrush(colorCaptionText); var stringFormatCaption = new StringFormat { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap, Alignment = StringAlignment.Center }; var rectfCaption = new RectangleF(0, 0, fCaptionWidth, fCaptionHeight); Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption); if (iSlot != strategy.OpenSlot && iSlot != strategy.CloseSlot) { int iButtonDimentions = (int)fCaptionHeight - 2; int iButtonX = iWidth - iButtonDimentions - 1; AbtnRemoveSlot[iSlot].Size = new Size(iButtonDimentions, iButtonDimentions); AbtnRemoveSlot[iSlot].Location = new Point(iButtonX, 1); float fCaptionTextWidth = g.MeasureString(stringCaptionText, fontCaptionText).Width; float fCaptionTextX = Math.Max((fCaptionWidth - fCaptionTextWidth) / 2f, 0); var pfCaptionText = new PointF(fCaptionTextX, 0); var sfCaptionText = new SizeF(iButtonX - fCaptionTextX, fCaptionHeight); rectfCaption = new RectangleF(pfCaptionText, sfCaptionText); stringFormatCaption.Alignment = StringAlignment.Near; } g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption); // Border g.DrawLine(penBorder, 1, fCaptionHeight, 1, pnl.Height); g.DrawLine(penBorder, pnl.Width - Border + 1, fCaptionHeight, pnl.Width - Border + 1, pnl.Height); g.DrawLine(penBorder, 0, pnl.Height - Border + 1, pnl.Width, pnl.Height - Border + 1); // Paints the panel var rectfPanel = new RectangleF(Border, fCaptionHeight, pnl.Width - 2 * Border, pnl.Height - fCaptionHeight - Border); Data.GradientPaint(g, rectfPanel, colorBackground, LayoutColors.DepthControl); int iVPosition = (int)fCaptionHeight + 3; // Indicator name var stringFormatIndicatorName = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }; string sIndicatorName = strategy.Slot[iSlot].IndicatorName; var fontIndicator = new Font(Font.FontFamily, 11f, FontStyle.Regular); Brush brushIndName = new SolidBrush(colorIndicatorNameText); float fIndNameHeight = fontIndicator.Height; float fGroupWidth = 0; if (Configs.UseLogicalGroups && (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)) { string sLogicalGroup = "[" + strategy.Slot[iSlot].LogicalGroup + "]"; fGroupWidth = g.MeasureString(sLogicalGroup, fontIndicator).Width; var rectGroup = new RectangleF(0, iVPosition, fGroupWidth, fIndNameHeight); g.DrawString(sLogicalGroup, fontIndicator, brushIndName, rectGroup, stringFormatIndicatorName); } stringFormatIndicatorName.Trimming = StringTrimming.EllipsisCharacter; float fIndicatorWidth = g.MeasureString(sIndicatorName, fontIndicator).Width; RectangleF rectIndName = iWidth >= 2 * fGroupWidth + fIndicatorWidth ? new RectangleF(0, iVPosition, iWidth, fIndNameHeight) : new RectangleF(fGroupWidth, iVPosition, iWidth - fGroupWidth, fIndNameHeight); g.DrawString(sIndicatorName, fontIndicator, brushIndName, rectIndName, stringFormatIndicatorName); iVPosition += (int)fIndNameHeight; if (slotMinMidMax == SlotSizeMinMidMax.Min) { return; } // Logic var stringFormatLogic = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoClip }; float fPadding = Space; if (strategy.Slot[iSlot].IndParam.ListParam[0].Enabled) { string sValue = strategy.Slot[iSlot].IndParam.ListParam[0].Text; var fontLogic = new Font(Font.FontFamily, 10.5f, FontStyle.Regular); SizeF sizeValue = g.MeasureString(sValue, fontLogic, (int)(iWidth - 2 * fPadding), stringFormatLogic); var rectValue = new RectangleF(fPadding, iVPosition, iWidth - 2 * fPadding, sizeValue.Height); Brush brushLogic = new SolidBrush(colorLogicText); g.DrawString(sValue, fontLogic, brushLogic, rectValue, stringFormatLogic); iVPosition += (int)sizeValue.Height; } if (slotMinMidMax == SlotSizeMinMidMax.Mid) { return; } // Parameters var stringFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }; var fontParam = new Font(Font.FontFamily, 9f, FontStyle.Regular); var fontValue = new Font(Font.FontFamily, 9f, FontStyle.Regular); Brush brushParam = new SolidBrush(colorParamText); Brush brushValue = new SolidBrush(colorValueText); var penDash = new Pen(colorDash); // Find Maximum width of the strings float fMaxParamWidth = 0; float fMaxValueWidth = 0; for (int i = 1; i < 5; i++) { if (!strategy.Slot[iSlot].IndParam.ListParam[i].Enabled) { continue; } string sParam = strategy.Slot[iSlot].IndParam.ListParam[i].Caption; string sValue = strategy.Slot[iSlot].IndParam.ListParam[i].Text; SizeF sizeParam = g.MeasureString(sParam, fontParam); SizeF sizeValue = g.MeasureString(sValue, fontValue); if (fMaxParamWidth < sizeParam.Width) { fMaxParamWidth = sizeParam.Width; } if (fMaxValueWidth < sizeValue.Width) { fMaxValueWidth = sizeValue.Width; } } foreach (NumericParam numericParam in strategy.Slot[iSlot].IndParam.NumParam) { if (!numericParam.Enabled) { continue; } string sParam = numericParam.Caption; string sValue = numericParam.ValueToString; SizeF sizeParam = g.MeasureString(sParam, fontParam); SizeF sizeValue = g.MeasureString(sValue, fontValue); if (fMaxParamWidth < sizeParam.Width) { fMaxParamWidth = sizeParam.Width; } if (fMaxValueWidth < sizeValue.Width) { fMaxValueWidth = sizeValue.Width; } } foreach (CheckParam checkParam in strategy.Slot[iSlot].IndParam.CheckParam) { if (!checkParam.Enabled) { continue; } string sParam = checkParam.Caption; string sValue = checkParam.Checked ? "Yes" : "No"; SizeF sizeParam = g.MeasureString(sParam, fontParam); SizeF sizeValue = g.MeasureString(sValue, fontValue); if (fMaxParamWidth < sizeParam.Width) { fMaxParamWidth = sizeParam.Width; } if (fMaxValueWidth < sizeValue.Width) { fMaxValueWidth = sizeValue.Width; } } // Padding Param Padding Dash Padding Value Padding const float fDashWidth = 5; float fNecessaryWidth = 4 * fPadding + fMaxParamWidth + fMaxValueWidth + fDashWidth; fPadding = iWidth > fNecessaryWidth ? Math.Max((pnl.ClientSize.Width - fMaxParamWidth - fMaxValueWidth - fDashWidth) / 6, fPadding) : 2; float fTabParam = 2 * fPadding; float fTabDash = fTabParam + fMaxParamWidth + fPadding; float fTabValue = fTabDash + fDashWidth + fPadding; // List Params for (int i = 1; i < 5; i++) { if (!strategy.Slot[iSlot].IndParam.ListParam[i].Enabled) { continue; } string sParam = strategy.Slot[iSlot].IndParam.ListParam[i].Caption; string sValue = strategy.Slot[iSlot].IndParam.ListParam[i].Text; var pointParam = new PointF(fTabParam, iVPosition); var pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(fTabValue, iVPosition); var sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); var rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); iVPosition += fontValue.Height; } // Num Params foreach (NumericParam numericParam in strategy.Slot[iSlot].IndParam.NumParam) { if (!numericParam.Enabled) { continue; } string sParam = numericParam.Caption; string sValue = numericParam.ValueToString; var pointParam = new PointF(fTabParam, iVPosition); var pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(fTabValue, iVPosition); var sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); var rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); iVPosition += fontValue.Height; } // Check Params foreach (CheckParam checkParam in strategy.Slot[iSlot].IndParam.CheckParam) { if (!checkParam.Enabled) { continue; } string sParam = checkParam.Caption; string sValue = checkParam.Checked ? "Yes" : "No"; var pointParam = new PointF(fTabParam, iVPosition); var pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2); var pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2); var pointValue = new PointF(fTabValue, iVPosition); var sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2); var rectfValue = new RectangleF(pointValue, sizefValue); g.DrawString(sParam, fontParam, brushParam, pointParam); g.DrawLine(penDash, pointDash1, pointDash2); g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat); iVPosition += fontValue.Height; } }
/// <summary> /// Paints panel pnlInfo /// </summary> private void PnlInfoPaint(object sender, PaintEventArgs e) { // ---------------------------------------------------------------------+ // | Way points description | // |--------------------------------------------------------------------+ // | Number | Description | Price | Direction | Lots | Position | Order | // |--------------------------------------------------------------------+ //xp0 xp1 xp2 xp3 xp4 xp5 xp6 xp7 Graphics g = e.Graphics; g.Clear(LayoutColors.ColorControlBack); if (!Data.IsData || !Data.IsResult) { return; } var pnl = (Panel)sender; string ff = Data.Ff; // Format modifier to print the floats var size = new Size(aiX[columns] - aiX[0], infoRowHeight); var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near }; // Caption background var pntStart = new PointF(0, 0); SizeF szfCaption = new Size(pnl.ClientSize.Width, 2 * infoRowHeight); var rectCaption = new RectangleF(pntStart, szfCaption); Data.GradientPaint(g, rectCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); // Caption Text var stringFormat = new StringFormat { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap, Alignment = StringAlignment.Near }; string stringCaptionText = Language.T("Way Points Description"); float captionWidth = Math.Min(pnlInfo.ClientSize.Width, aiX[columns] - aiX[0]); float fCaptionTextWidth = g.MeasureString(stringCaptionText, fontInfo).Width; float fCaptionTextX = Math.Max((captionWidth - fCaptionTextWidth) / 2f, 0); var pfCaptionText = new PointF(fCaptionTextX, 0); var sfCaptionText = new SizeF(captionWidth - fCaptionTextX, infoRowHeight); rectCaption = new RectangleF(pfCaptionText, sfCaptionText); // First caption raw g.DrawString(stringCaptionText, fontInfo, brushCaptionText, rectCaption, stringFormat); // Second caption raw for (int i = 0; i < columns; i++) { g.DrawString(asTitles[i], fontInfo, brushCaptionText, (aiX[i] + aiX[i + 1]) / 2f, infoRowHeight, sf); } Brush brush = new SolidBrush(LayoutColors.ColorControlText); for (int pnt = 0; pnt < Backtester.WayPoints(barCurrent); pnt++) { int y = (pnt + 2) * infoRowHeight; var point = new Point(aiX[0], y); // Even row if (Math.Abs(pnt % 2f - 0) > 0.00001) { g.FillRectangle(brushEvenRow, new Rectangle(point, size)); } int positionNumber = Backtester.WayPoint(barCurrent, pnt).PosNumb; WayPointType wpType = Backtester.WayPoint(barCurrent, pnt).WpType; PosDirection posDirection = Backtester.PosFromNumb(positionNumber).PosDir; double posLots = Backtester.PosFromNumb(positionNumber).PosLots; int ordNumber = Backtester.WayPoint(barCurrent, pnt).OrdNumb; g.DrawString((pnt + 1).ToString(CultureInfo.InvariantCulture), fontInfo, brush, (aiX[0] + aiX[1]) / 2f, y, sf); g.DrawString(Language.T(WayPoint.WpTypeToString(wpType)), fontInfo, brush, aiX[1] + 2, y); g.DrawString(Backtester.WayPoint(barCurrent, pnt).Price.ToString(ff), fontInfo, brush, (aiX[3] + aiX[2]) / 2f, y, sf); if (positionNumber > -1) { g.DrawString(Language.T(posDirection.ToString()), fontInfo, brush, (aiX[4] + aiX[3]) / 2f, y, sf); g.DrawString(posLots.ToString(CultureInfo.InvariantCulture), fontInfo, brush, (aiX[5] + aiX[4]) / 2f, y, sf); g.DrawString((positionNumber + 1).ToString(CultureInfo.InvariantCulture), fontInfo, brush, (aiX[6] + aiX[5]) / 2f, y, sf); } if (ordNumber > -1) { g.DrawString((ordNumber + 1).ToString(CultureInfo.InvariantCulture), fontInfo, brush, (aiX[7] + aiX[6]) / 2f, y, sf); } } // Vertical lines var penLine = new Pen(LayoutColors.ColorJournalLines); for (int i = 1; i < columns; i++) { g.DrawLine(penLine, aiX[i], 2 * infoRowHeight, aiX[i], ClientSize.Height - Border); } // Border var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), Border); g.DrawLine(penBorder, 1, 2 * infoRowHeight, 1, pnl.ClientSize.Height); g.DrawLine(penBorder, pnl.ClientSize.Width - Border + 1, 2 * infoRowHeight, pnl.ClientSize.Width - Border + 1, pnl.ClientSize.Height); g.DrawLine(penBorder, 0, pnl.ClientSize.Height - Border + 1, pnl.ClientSize.Width, pnl.ClientSize.Height - Border + 1); }
/// <summary> /// Paints panel pnlChart /// </summary> private void PnlChartPaint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(LayoutColors.ColorChartBack); if (!Data.IsData || !Data.IsResult) { return; } var pnl = (Panel)sender; int width = pnl.ClientSize.Width; // Caption background var pntStart = new PointF(0, 0); SizeF szfCaption = new Size(width, infoRowHeight); var rectCaption = new RectangleF(pntStart, szfCaption); Data.GradientPaint(g, rectCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); // Caption Text var stringFormat = new StringFormat { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap, Alignment = StringAlignment.Center }; string stringCaptionText = Language.T("Price Route Inside the Bar"); rectCaption = new RectangleF(Border, 0, pnl.ClientSize.Width - 2 * Border, infoRowHeight); g.DrawString(stringCaptionText, fontInfo, brushCaptionText, rectCaption, stringFormat); // Paint the panel background var rectClient = new RectangleF(0, infoRowHeight, pnl.ClientSize.Width, pnl.Height - infoRowHeight); Data.GradientPaint(g, rectClient, LayoutColors.ColorChartBack, LayoutColors.DepthControl); // Paint bar info var rectBarInfo = new RectangleF(Border, infoRowHeight + 1, pnl.ClientSize.Width - 2 * Border, infoRowHeight); g.DrawString(barInfo, fontInfo, brushGridText, rectBarInfo, stringFormat); // Searching the min and the max price and volume width = pnl.ClientSize.Width - 2 * Border; double maxPrice = Data.High[barCurrent]; double minPrice = Data.Low[barCurrent]; const int space = 8; int spcRight = szPrice.Width + 4; const int xLeft = Border + space; int xRight = width - spcRight; int yTop = 2 * infoRowHeight + 6; int yBottom = pnl.ClientSize.Height - 22; int barPixels = maxWayPoints < 10 ? 28 : maxWayPoints < 15 ? 24 : 20; const int spcLeft = 3; int x = barPixels + spcLeft; int pointLeft = x + barPixels + 30; int pointRight = xRight - 20; int points = Backtester.WayPoints(barCurrent); const int pointRadius = 3; // Grid var iCntLabels = (int)Math.Max((yBottom - yTop) / 30d, 1); double deltaPoint = (Data.InstrProperties.Digits == 5 || Data.InstrProperties.Digits == 3) ? Data.InstrProperties.Point * 100 : Data.InstrProperties.Point * 10; double delta = Math.Max(Math.Round((maxPrice - minPrice) / iCntLabels, Data.InstrProperties.Point < 0.001 ? 3 : 1), deltaPoint); minPrice = Math.Round(minPrice, Data.InstrProperties.Point < 0.001f ? 3 : 1) - Data.InstrProperties.Point * 10; minPrice -= delta; maxPrice += delta; iCntLabels = (int)Math.Ceiling((maxPrice - minPrice) / delta); maxPrice = minPrice + iCntLabels * delta; double scaleY = (yBottom - yTop) / (iCntLabels * delta); var yOpen = (int)(yBottom - (Data.Open[barCurrent] - minPrice) * scaleY); var yHigh = (int)(yBottom - (Data.High[barCurrent] - minPrice) * scaleY); var yLow = (int)(yBottom - (Data.Low[barCurrent] - minPrice) * scaleY); var yClose = (int)(yBottom - (Data.Close[barCurrent] - minPrice) * scaleY); // Find the price distance double priceDistance = 0; for (int point = 1; point < points; point++) { priceDistance += Math.Abs(Backtester.WayPoint(barCurrent, point).Price - Backtester.WayPoint(barCurrent, point - 1).Price); } double dPriceForAPixel = (pointRight - pointLeft) / priceDistance; // Points X var aiPointX = new int[points]; aiPointX[0] = pointLeft; for (int point = 1; point < points - 1; point++) { var iDistance = (int) (Math.Abs(Backtester.WayPoint(barCurrent, point).Price - Backtester.WayPoint(barCurrent, point - 1).Price) * dPriceForAPixel); aiPointX[point] = aiPointX[point - 1] + iDistance; } aiPointX[points - 1] = pointRight; for (int point = 1; point < points - 1; point++) { if (aiPointX[point] - aiPointX[point - 1] < barPixels + 1) { aiPointX[point] = aiPointX[point - 1] + barPixels + 1; } } for (int point = points - 2; point > 0; point--) { if (aiPointX[point + 1] - aiPointX[point] < barPixels + 1) { aiPointX[point] = aiPointX[point + 1] - barPixels - 1; } } // Find coordinates of the Way Points var pntWay = new Point[points]; for (int point = 0; point < points; point++) { var pointY = (int)(yBottom - (Backtester.WayPoint(barCurrent, point).Price - minPrice) * scaleY); pntWay[point] = new Point(aiPointX[point], pointY); } // Horizontal grid and Price labels for (double label = minPrice; label <= maxPrice + Data.InstrProperties.Point; label += delta) { var labelY = (int)(yBottom - (label - minPrice) * scaleY); g.DrawString(label.ToString(Data.Ff), Font, brushGridText, xRight, labelY - Font.Height / 2 - 1); g.DrawLine(penGrid, Border + space, labelY, xRight, labelY); } // Vertical Grid g.DrawLine(penGrid, x + barPixels / 2 - 1, yTop, x + barPixels / 2 - 1, yBottom + 2); for (int point = 0; point < points; point++) { var pt1 = new Point(pntWay[point].X, yTop); var pt2 = new Point(pntWay[point].X, yBottom + 2); var pt3 = new Point(pntWay[point].X - 5, yBottom + 4); g.DrawLine(penGrid, pt1, pt2); g.DrawString((point + 1).ToString(CultureInfo.InvariantCulture), Font, brushGridText, pt3); } // Bar Number string barNumber = (barCurrent + 1).ToString(CultureInfo.InvariantCulture); int stringX = x + barPixels / 2 - 1 - g.MeasureString(barNumber, Font).ToSize().Width / 2; Brush barBrush = Backtester.BackTestEval(barCurrent) == BacktestEval.Ambiguous ? brushRed : brushGridText; g.DrawString(barNumber, Font, barBrush, stringX, yBottom + 4); // Draw the bar g.DrawLine(penBarBorder, x + barPixels / 2 - 1, yLow, x + barPixels / 2 - 1, yHigh); if (yClose < yOpen) // White bar { var rect = new Rectangle(x, yClose, barPixels - 2, yOpen - yClose); var lgBrush = new LinearGradientBrush(rect, colorBarWight1, colorBarWight2, 5f); g.FillRectangle(lgBrush, rect); g.DrawRectangle(penBarBorder, x, yClose, barPixels - 2, yOpen - yClose); } else if (yClose > yOpen) // Black bar { var rect = new Rectangle(x, yOpen, barPixels - 2, yClose - yOpen); var lgBrush = new LinearGradientBrush(rect, colorBarBlack1, colorBarBlack2, 5f); g.FillRectangle(lgBrush, rect); g.DrawRectangle(penBarBorder, x, yOpen, barPixels - 2, yClose - yOpen); } else // Cross { g.DrawLine(penBarBorder, x, yClose, x + barPixels - 2, yClose); } // Draw cancelled orders for (int orderIndex = 0; orderIndex < Backtester.Orders(barCurrent); orderIndex++) { int ordNumber = Backtester.OrdNumb(barCurrent, orderIndex); Order order = Backtester.OrdFromNumb(ordNumber); if (order.OrdStatus != OrderStatus.Cancelled) { continue; } if (order.OrdPrice > Data.High[barCurrent] || order.OrdPrice < Data.Low[barCurrent]) { continue; } int d = barPixels / 2 - 1; int x1 = x + d; int x2 = x + barPixels - 2; var yDeal = (int)(yBottom - (order.OrdPrice - minPrice) * scaleY); var pen = new Pen(LayoutColors.ColorChartGrid, 2); if (order.OrdDir == OrderDirection.Buy) { g.DrawLine(pen, x, yDeal, x1, yDeal); g.DrawLine(pen, x1, yDeal, x2, yDeal - d); g.DrawLine(pen, x2 + 1, yDeal - d + 1, x1 + d / 2 + 1, yDeal - d + 1); g.DrawLine(pen, x2, yDeal - d, x2, yDeal - d / 2); } else if (order.OrdDir == OrderDirection.Sell) { g.DrawLine(pen, x, yDeal + 1, x1 + 1, yDeal + 1); g.DrawLine(pen, x1, yDeal, x2, yDeal + d); g.DrawLine(pen, x1 + d / 2 + 1, yDeal + d, x2, yDeal + d); g.DrawLine(pen, x2, yDeal + d, x2, yDeal + d / 2 + 1); } } // Draw the deals on the bar for (int pos = 0; pos < Backtester.Positions(barCurrent); pos++) { if (Backtester.PosTransaction(barCurrent, pos) == Transaction.Transfer) { continue; } var yDeal = (int)(yBottom - (Backtester.PosOrdPrice(barCurrent, pos) - minPrice) * scaleY); if (Backtester.PosDir(barCurrent, pos) == PosDirection.Long || Backtester.PosDir(barCurrent, pos) == PosDirection.Short) { int d = barPixels / 2 - 1; int x1 = x + d; int x2 = x + barPixels - 2; if (Backtester.OrdFromNumb(Backtester.PosOrdNumb(barCurrent, pos)).OrdDir == OrderDirection.Buy) { // Buy var pen = new Pen(LayoutColors.ColorTradeLong, 2); g.DrawLine(pen, x, yDeal, x1, yDeal); g.DrawLine(pen, x1, yDeal, x2, yDeal - d); g.DrawLine(pen, x2 + 1, yDeal - d + 1, x1 + d / 2 + 1, yDeal - d + 1); g.DrawLine(pen, x2, yDeal - d, x2, yDeal - d / 2); } else { // Sell var pen = new Pen(LayoutColors.ColorTradeShort, 2); g.DrawLine(pen, x, yDeal + 1, x1 + 1, yDeal + 1); g.DrawLine(pen, x1, yDeal, x2, yDeal + d); g.DrawLine(pen, x1 + d / 2 + 1, yDeal + d, x2, yDeal + d); g.DrawLine(pen, x2, yDeal + d, x2, yDeal + d / 2 + 1); } } else if (Backtester.PosDir(barCurrent, pos) == PosDirection.Closed) { // Close position int d = barPixels / 2 - 1; int x1 = x + d; int x2 = x + barPixels - 3; var pen = new Pen(LayoutColors.ColorTradeClose, 2); g.DrawLine(pen, x, yDeal, x1, yDeal); g.DrawLine(pen, x1, yDeal + d / 2, x2, yDeal - d / 2); g.DrawLine(pen, x1, yDeal - d / 2, x2, yDeal + d / 2); } } // Draw position lots for (int point = 0; point < points; point++) { int posNumber = Backtester.WayPoint(barCurrent, point).PosNumb; if (posNumber == -1) { continue; } Position position = Backtester.PosFromNumb(posNumber); double posLots = position.PosLots; PosDirection posDirection = position.PosDir; WayPointType wpType = Backtester.WayPoint(barCurrent, point).WpType; var height = (int)(Math.Max(posLots * 2, 2)); int length = barPixels; int posX = pntWay[point].X - (barPixels - 1) / 2; int posY = yBottom - height; if (point < points - 1) { length = pntWay[point + 1].X - pntWay[point].X + 1; } if (posDirection == PosDirection.Long) { // Long var rect = new Rectangle(posX - 1, posY - 1, length, height + 2); var lgBrush = new LinearGradientBrush(rect, colorLongTrade1, colorLongTrade2, LinearGradientMode.Vertical); rect = new Rectangle(posX - 1, posY, length, height); g.FillRectangle(lgBrush, rect); } else if (posDirection == PosDirection.Short) { // Short var rect = new Rectangle(posX - 1, posY - 1, length, height + 2); var lgBrush = new LinearGradientBrush(rect, colorShortTrade1, colorShortTrade2, LinearGradientMode.Vertical); rect = new Rectangle(posX - 1, posY, length, height); g.FillRectangle(lgBrush, rect); } else if (posDirection == PosDirection.Closed && wpType == WayPointType.Exit) { // Closed var rect = new Rectangle(posX - 1, yBottom - 2, barPixels + 1, 2); var lgBrush = new LinearGradientBrush(rect, colorClosedTrade1, colorClosedTrade2, LinearGradientMode.Vertical); rect = new Rectangle(posX, yBottom - 2, barPixels - 1, 2); g.FillRectangle(lgBrush, rect); } } // Draw the Beziers for (int point = 1; point < points; point++) { Point ptKnot1 = pntWay[point - 1]; Point ptKnot2 = pntWay[point]; int ctrlX1 = (ptKnot1.X + ptKnot2.X) / 2; int ctrlX2 = (ptKnot1.X + ptKnot2.X) / 2; int ctrlY1 = ptKnot1.Y; int ctrlY2 = ptKnot2.Y; if (point > 1) { if (pntWay[point - 2].Y > pntWay[point - 1].Y && pntWay[point - 1].Y > pntWay[point].Y || pntWay[point - 2].Y < pntWay[point - 1].Y && pntWay[point - 1].Y < pntWay[point].Y) { ctrlY1 = (pntWay[point - 1].Y + pntWay[point].Y) / 2; } } if (point < points - 1) { if (pntWay[point - 1].Y > pntWay[point].Y && pntWay[point].Y > pntWay[point + 1].Y || pntWay[point - 1].Y < pntWay[point].Y && pntWay[point].Y < pntWay[point + 1].Y) { ctrlY2 = (pntWay[point - 1].Y + pntWay[point].Y) / 2; } } if (point == 1) { ctrlX1 = ptKnot1.X; ctrlY1 = ptKnot1.Y; } if (point == points - 1) { ctrlX2 = ptKnot2.X; ctrlY2 = ptKnot2.Y; } var ptControl1 = new Point(ctrlX1, ctrlY1); var ptControl2 = new Point(ctrlX2, ctrlY2); g.DrawBezier(penCross, ptKnot1, ptControl1, ptControl2, ptKnot2); } // Draw the WayPoints Brush brushWeyPnt = new SolidBrush(LayoutColors.ColorChartBack); for (int point = 0; point < points; point++) { g.FillEllipse(brushWeyPnt, pntWay[point].X - pointRadius, pntWay[point].Y - pointRadius, 2 * pointRadius, 2 * pointRadius); g.DrawEllipse(penCross, pntWay[point].X - pointRadius, pntWay[point].Y - pointRadius, 2 * pointRadius, 2 * pointRadius); } // Draw O, H, L, C labels for (int point = 0; point < points; point++) { WayPointType wpType = Backtester.WayPoint(barCurrent, point).WpType; if (wpType != WayPointType.Open && wpType != WayPointType.High && wpType != WayPointType.Low && wpType != WayPointType.Close) { continue; } string label = "?"; switch (wpType) { case WayPointType.Open: label = "O"; break; case WayPointType.High: label = "H"; break; case WayPointType.Low: label = "L"; break; case WayPointType.Close: label = "C"; break; } int xPoint = pntWay[point].X; int yPoint = pntWay[point].Y - Font.Height - 3; var stringFormatLabel = new StringFormat { Alignment = StringAlignment.Center }; g.DrawString(label, Font, brushGridText, xPoint, yPoint, stringFormatLabel); } // Draw the deals on the route for (int point = 0; point < points; point++) { int posNumber = Backtester.WayPoint(barCurrent, point).PosNumb; int ordNumber = Backtester.WayPoint(barCurrent, point).OrdNumb; if (posNumber < 0 || ordNumber < 0) { continue; } PosDirection posDirection = Backtester.PosFromNumb(posNumber).PosDir; OrderDirection ordDirection = Backtester.OrdFromNumb(ordNumber).OrdDir; WayPointType wpType = Backtester.WayPoint(barCurrent, point).WpType; if (wpType == WayPointType.None || wpType == WayPointType.Open || wpType == WayPointType.High || wpType == WayPointType.Low || wpType == WayPointType.Close) { continue; } int yDeal = pntWay[point].Y; if (posDirection == PosDirection.Long || posDirection == PosDirection.Short || wpType == WayPointType.Cancel) { int d = barPixels / 2 - 1; x = pntWay[point].X - d; int x1 = pntWay[point].X; int x2 = x + barPixels - 2; if (ordDirection == OrderDirection.Buy) { // Buy var pen = new Pen(LayoutColors.ColorTradeLong, 2); if (wpType == WayPointType.Cancel) { pen = new Pen(LayoutColors.ColorChartGrid, 2); } g.DrawLine(pen, x, yDeal, x1, yDeal); g.DrawLine(pen, x1, yDeal, x2, yDeal - d); g.DrawLine(pen, x2 + 1, yDeal - d + 1, x1 + d / 2 + 1, yDeal - d + 1); g.DrawLine(pen, x2, yDeal - d, x2, yDeal - d / 2); } else { // Sell var pen = new Pen(LayoutColors.ColorTradeShort, 2); if (wpType == WayPointType.Cancel) { pen = new Pen(LayoutColors.ColorChartGrid, 2); } g.DrawLine(pen, x, yDeal + 1, x1 + 1, yDeal + 1); g.DrawLine(pen, x1, yDeal, x2, yDeal + d); g.DrawLine(pen, x1 + d / 2 + 1, yDeal + d, x2, yDeal + d); g.DrawLine(pen, x2, yDeal + d, x2, yDeal + d / 2 + 1); } } if (posDirection == PosDirection.Closed) { // Close position int d = barPixels / 2 - 1; x = pntWay[point].X - d; int x1 = pntWay[point].X; int x2 = x + barPixels - 3; var pen = new Pen(LayoutColors.ColorTradeClose, 2); g.DrawLine(pen, x, yDeal, x1, yDeal); g.DrawLine(pen, x1, yDeal + d / 2, x2, yDeal - d / 2); g.DrawLine(pen, x1, yDeal - d / 2, x2, yDeal + d / 2); } } // Coordinate axes g.DrawLine(penAxes, xLeft, yTop - 4, xLeft, yBottom); // Vertical left line g.DrawLine(penAxes, xLeft, yBottom, xRight, yBottom); // Border var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), Border); g.DrawLine(penBorder, 1, infoRowHeight, 1, pnl.ClientSize.Height); g.DrawLine(penBorder, pnl.ClientSize.Width - Border + 1, infoRowHeight, pnl.ClientSize.Width - Border + 1, pnl.ClientSize.Height); g.DrawLine(penBorder, 0, pnl.ClientSize.Height - Border + 1, pnl.ClientSize.Width, pnl.ClientSize.Height - Border + 1); }
/// <summary> /// Paints the journal /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientSize.Width == 0 || ClientSize.Height == 0) { return; } var bitmap = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bitmap); int scroll = -hScrollBar.Value; var size = new Size(ClientSize.Width, rowHeight); var stringFormat = new StringFormat { Alignment = StringAlignment.Center }; // Caption background var rectCaption = new RectangleF(0, 0, ClientSize.Width, 2 * rowHeight); Data.GradientPaint(g, rectCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption); // Print the journal caption string stringCaptionText = Language.T("Journal by Positions") + (ShowTransfers ? "" : " " + Language.T("without Transfers")) + (Configs.AccountInMoney ? " [" + Configs.AccountCurrency + "]" : " [" + Language.T("points") + "]"); g.DrawString(stringCaptionText, font, brushCaptionText, new RectangleF(Point.Empty, size), stringFormat); g.SetClip(new RectangleF(Border, rowHeight, ClientSize.Width - 2 * Border, rowHeight)); if (Configs.AccountInMoney) { g.DrawString(titlesInMoney[0], font, brushCaptionText, scroll + (scaledX[0] + scaledX[1]) / 2, rowHeight, stringFormat); for (int i = 1; i < columns; i++) { g.DrawString(titlesInMoney[i], font, brushCaptionText, scroll + (scaledX[i] + scaledX[i + 1]) / 2, rowHeight, stringFormat); } } else { g.DrawString(titlesInPoints[0], font, brushCaptionText, scroll + (scaledX[0] + scaledX[1]) / 2, rowHeight, stringFormat); for (int i = 1; i < columns; i++) { g.DrawString(titlesInPoints[i], font, brushCaptionText, scroll + (scaledX[i] + scaledX[i + 1]) / 2, rowHeight, stringFormat); } } g.ResetClip(); // Paints the journal's data field var rectField = new RectangleF(Border, 2 * rowHeight, ClientSize.Width - 2 * Border, ClientSize.Height - 2 * rowHeight - Border); g.FillRectangle(new SolidBrush(colorBack), rectField); size = new Size(ClientSize.Width - vScrollBar.Width - 2 * Border, rowHeight); // Prints the journal data for (int pos = firstPos; pos < firstPos + shownPos; pos++) { int y = (pos - firstPos + 2) * rowHeight; var point = new Point(Border, y); // Even row if (Math.Abs((pos - firstPos) % 2f - 0) > 0.0001) { g.FillRectangle(brushEvenRowBack, new Rectangle(point, size)); } // Warning row bool isWarning = false; if (journalData[pos - firstPos, columns - 1] == Language.T("Ambiguous")) { g.FillRectangle(brushWarningBack, new Rectangle(point, size)); isWarning = true; } // Selected row Brush brush; if (pos - firstPos == selectedRow) { g.FillRectangle(brushSelectedRowBack, new Rectangle(point, size)); brush = brushSelectedRowText; } else { brush = isWarning ? brushWarningText : brushRowText; } // Draw the position icon int iImgY = y + (int)Math.Floor((rowHeight - 16) / 2.0); g.DrawImage(posIcons[pos - firstPos], scroll + 2, iImgY, 16, 16); // Prints the data g.DrawString(journalData[pos - firstPos, 0], font, brush, scroll + (16 + scaledX[1]) / 2, (pos - firstPos + 2) * rowHeight, stringFormat); for (int i = 1; i < columns; i++) { g.DrawString(journalData[pos - firstPos, i], font, brush, scroll + (scaledX[i] + scaledX[i + 1]) / 2, (pos - firstPos + 2) * rowHeight, stringFormat); } } //g.DrawLine(penLines, 0, iRowHeight, ClientSize.Width, iRowHeight); for (int i = 1; i < columns; i++) { g.DrawLine(penLines, scaledX[i] + scroll, 2 * rowHeight, scaledX[i] + scroll, ClientSize.Height); } // Border g.DrawLine(penBorder, 1, 2 * rowHeight, 1, ClientSize.Height); g.DrawLine(penBorder, ClientSize.Width - Border + 1, 2 * rowHeight, ClientSize.Width - Border + 1, ClientSize.Height); g.DrawLine(penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1); DIBSection.DrawOnPaint(e.Graphics, bitmap, Width, Height); OnSelectedBarChange(new EventArgs()); }