コード例 #1
0
        /// <summary>
        ///     Constructor
        /// </summary>
        public FancyPanel(string captionText, Color borderColor)
        {
            this.captionText = captionText;
            colorCaptionBack = borderColor;
            brushCaption     = new SolidBrush(LayoutColors.ColorCaptionText);
            penBorder        = new Pen(Data.GetGradientColor(borderColor, -LayoutColors.DepthCaption), Border);

            InitializeParameters();
        }
コード例 #2
0
        /// <summary>
        ///     Sets the panel colors
        /// </summary>
        public void SetColors()
        {
            colorCaptionBack         = LayoutColors.ColorCaptionBack;
            colorBackroundEvenRows   = LayoutColors.ColorEvenRowBack;
            colorBackroundWarningRow = LayoutColors.ColorWarningRowBack;
            colorTextWarningRow      = LayoutColors.ColorWarningRowText;
            colorBackroundOddRows    = LayoutColors.ColorOddRowBack;

            brushCaption = new SolidBrush(LayoutColors.ColorCaptionText);
            brushParams  = new SolidBrush(LayoutColors.ColorControlText);
            brushData    = new SolidBrush(LayoutColors.ColorControlText);

            penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), Border);
        }
コード例 #3
0
        /// <summary>
        ///     Sets the journal colors
        /// </summary>
        private void SetJournalColors()
        {
            colorBack        = LayoutColors.ColorControlBack;
            brushCaptionText = new SolidBrush(LayoutColors.ColorCaptionText);
            brushEvenRowBack = new SolidBrush(LayoutColors.ColorEvenRowBack);
            brushRowText     = new SolidBrush(LayoutColors.ColorControlText);
            penLines         = new Pen(LayoutColors.ColorJournalLines);
            penBorder        = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption),
                                       Border);

            ButtonsColorBack     = LayoutColors.ColorCaptionBack;
            ButtonColorFore      = LayoutColors.ColorCaptionText;
            ContextMenuColorBack = LayoutColors.ColorControlBack;
            ContextMenuColorFore = LayoutColors.ColorControlText;
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
        /// <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;
            }
        }
コード例 #6
0
        /// <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));
                }
            }
        }
コード例 #7
0
        /// <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++;
                }
            }
        }
コード例 #8
0
        /// <summary>
        ///     Initialize the form and controls
        /// </summary>
        public BarExplorer(int barNumber)
        {
            pnlChart = new Panel();
            pnlInfo  = new Panel();
            toolTip  = new ToolTip();

            barCurrent = barNumber < Data.FirstBar ? Data.FirstBar : barNumber;

            Text            = Language.T("Bar Explorer");
            BackColor       = LayoutColors.ColorFormBack;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            Icon            = Data.Icon;
            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;

            fontInfo      = new Font(Font.FontFamily, 9);
            infoRowHeight = Math.Max(fontInfo.Height, 18);

            barInfo = Language.T("Bar") + ": " + (barCurrent + 1) + " " +
                      Data.Time[barCurrent].ToString(Data.Df) + " " +
                      Data.Time[barCurrent].ToString("HH:mm") + "; " +
                      Language.T("Interpolation method") + ": " +
                      Backtester.InterpolationMethodToString();

            pnlChart.Parent = this;
            pnlChart.Paint += PnlChartPaint;

            pnlInfo.Parent = this;
            pnlInfo.Paint += PnlInfoPaint;

            buttonsNavigate = new Button[6];
            var btnNavigateText = new[] { "< !", "<<", "<", ">", ">>", "! >" };
            var btnNavigateTips = new[]
            {
                Language.T("Previous ambiguous bar."),
                Language.T("Previous deal."),
                Language.T("Previous bar."),
                Language.T("Next bar."),
                Language.T("Next deal."),
                Language.T("Next ambiguous bar.")
            };

            for (int i = 0; i < 6; i++)
            {
                buttonsNavigate[i] = new Button {
                    Parent = this, Text = btnNavigateText[i], Name = btnNavigateText[i]
                };
                buttonsNavigate[i].Click      += BtnNavigateClick;
                buttonsNavigate[i].MouseWheel += BarExplorerMouseWheel;
                buttonsNavigate[i].KeyUp      += BtnNavigateKeyUp;
                buttonsNavigate[i].UseVisualStyleBackColor = true;
                toolTip.SetToolTip(buttonsNavigate[i], btnNavigateTips[i]);
            }

            buttonsNavigate[0].Enabled = Backtester.AmbiguousBars > 0;
            buttonsNavigate[1].Enabled = Backtester.PositionsTotal > 0;
            buttonsNavigate[4].Enabled = Backtester.PositionsTotal > 0;
            buttonsNavigate[5].Enabled = Backtester.AmbiguousBars > 0;

            nudGo = new NumericUpDown {
                Parent = this, TextAlign = HorizontalAlignment.Center
            };
            nudGo.BeginInit();
            nudGo.Minimum   = Data.FirstBar + 1;
            nudGo.Maximum   = Data.Bars;
            nudGo.Increment = 1;
            nudGo.Value     = barCurrent + 1;
            nudGo.KeyUp    += BtnNavigateKeyUp;
            nudGo.EndInit();

            btnGo = new Button {
                Parent = this, Name = "Go", Text = Language.T("Go"), UseVisualStyleBackColor = true
            };
            btnGo.Click      += BtnNavigateClick;
            btnGo.MouseWheel += BarExplorerMouseWheel;
            btnGo.KeyUp      += BtnNavigateKeyUp;
            toolTip.SetToolTip(btnGo, Language.T("Go to the chosen bar."));

            //Button Close
            btnClose = new Button
            {
                Parent                  = this,
                Text                    = Language.T("Close"),
                DialogResult            = DialogResult.Cancel,
                UseVisualStyleBackColor = true
            };

            // Colors
            brushRed = new SolidBrush(LayoutColors.ColorSignalRed);

            brushCaptionText = new SolidBrush(LayoutColors.ColorCaptionText);
            brushEvenRow     = new SolidBrush(LayoutColors.ColorEvenRowBack);
            brushGridText    = new SolidBrush(LayoutColors.ColorChartFore);

            penGrid = new Pen(LayoutColors.ColorChartGrid)
            {
                DashStyle = DashStyle.Dash, DashPattern = new float[] { 4, 2 }
            };
            penAxes      = new Pen(LayoutColors.ColorChartFore);
            penCross     = new Pen(LayoutColors.ColorChartCross);
            penBarBorder = new Pen(LayoutColors.ColorBarBorder);

            colorBarWight1 = Data.GetGradientColor(LayoutColors.ColorBarWhite, 30);
            colorBarWight2 = Data.GetGradientColor(LayoutColors.ColorBarWhite, -30);
            colorBarBlack1 = Data.GetGradientColor(LayoutColors.ColorBarBlack, 30);
            colorBarBlack2 = Data.GetGradientColor(LayoutColors.ColorBarBlack, -30);

            colorLongTrade1   = Data.GetGradientColor(LayoutColors.ColorTradeLong, 30);
            colorLongTrade2   = Data.GetGradientColor(LayoutColors.ColorTradeLong, -30);
            colorShortTrade1  = Data.GetGradientColor(LayoutColors.ColorTradeShort, 30);
            colorShortTrade2  = Data.GetGradientColor(LayoutColors.ColorTradeShort, -30);
            colorClosedTrade1 = Data.GetGradientColor(LayoutColors.ColorTradeClose, 30);
            colorClosedTrade2 = Data.GetGradientColor(LayoutColors.ColorTradeClose, -30);

            SetJournalPoints();
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        /// <summary>
        ///     Prepare the parameters
        /// </summary>
        private void SetUpPaintData()
        {
            // Panel caption
            captionText         = Language.T("Indicator Chart");
            captionFont         = new Font(Font.FontFamily, 9);
            captionHeight       = Math.Max(captionFont.Height, 18);
            captionWidth        = ClientSize.Width;
            captionBrush        = new SolidBrush(LayoutColors.ColorCaptionText);
            captionRectangle    = new RectangleF(0, 0, captionWidth, captionHeight);
            captionStringFormat = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap
            };

            if (!Data.IsData || !Data.IsResult || Data.Bars <= StatsBuffer.FirstBar)
            {
                return;
            }

            xLeft                         = Space;
            xRight                        = ClientSize.Width - Space;
            yTop                          = (int)captionHeight + Space;
            yBottom                       = ClientSize.Height - scrollBar.Height - Space;
            yPriceBottom                  = yBottom;
            separateIndicatorsCount       = 0;
            separateIndicatorsChartHeight = 0;
            indicatorSlots                = new int[Configs.MaxEntryFilters + Configs.MaxExitFilters + 2];

            penFore   = new Pen(LayoutColors.ColorChartFore);
            penVolume = new Pen(LayoutColors.ColorVolume);
            penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption),
                                Border);

            for (int slot = StatsBuffer.Strategy.Slots - 1; slot >= 0; slot--)
            {
                if (StatsBuffer.Strategy.Slot[slot].SeparatedChart)
                {
                    indicatorSlots[separateIndicatorsCount++] = slot;
                }
            }

            if (separateIndicatorsCount > 0)
            {
                separateIndicatorsChartHeight = (yBottom - yTop) / (2 + separateIndicatorsCount);
                yPriceBottom = yBottom - separateIndicatorsCount * separateIndicatorsChartHeight;
            }

            maxPrice  = double.MinValue;
            minPrice  = double.MaxValue;
            maxVolume = int.MinValue;

            for (int bar = chartFirstBar; bar <= chartLastBar; bar++)
            {
                if (Data.High[bar] > maxPrice)
                {
                    maxPrice = Data.High[bar];
                }
                if (Data.Low[bar] < minPrice)
                {
                    minPrice = Data.Low[bar];
                }
                if (Data.Volume[bar] > maxVolume)
                {
                    maxVolume = Data.Volume[bar];
                }
            }
            minPrice = Math.Round(minPrice, Data.InstrProperties.Point < 0.001 ? 3 : 1) -
                       Data.InstrProperties.Point * 10;
            maxPrice = Math.Round(maxPrice, Data.InstrProperties.Point < 0.001 ? 3 : 1) +
                       Data.InstrProperties.Point * 10;
            scaleY    = (yPriceBottom - yTop) / (maxPrice - minPrice);
            scaleYVol = maxVolume > 0 ? ((yPriceBottom - yTop) / 8d) / maxVolume : 0d;

            // Volume, Lots and Price
            axisX         = new int[chartBars];
            yOpen         = new int[chartBars];
            yHigh         = new int[chartBars];
            yLow          = new int[chartBars];
            yClose        = new int[chartBars];
            yVolume       = new int[chartBars];
            rectPosition  = new Rectangle[chartBars];
            brushPosition = new Brush[chartBars];

            int index = 0;

            for (int bar = chartFirstBar; bar <= chartLastBar; bar++)
            {
                axisX[index]   = (bar - chartFirstBar) * chartBarWidth + xLeft;
                yOpen[index]   = (int)(yPriceBottom - (Data.Open[bar] - minPrice) * scaleY);
                yHigh[index]   = (int)(yPriceBottom - (Data.High[bar] - minPrice) * scaleY);
                yLow[index]    = (int)(yPriceBottom - (Data.Low[bar] - minPrice) * scaleY);
                yClose[index]  = (int)(yPriceBottom - (Data.Close[bar] - minPrice) * scaleY);
                yVolume[index] = (int)(yPriceBottom - Data.Volume[bar] * scaleYVol);

                // Draw position lots
                if (StatsBuffer.IsPos(bar))
                {
                    var posHeight = (int)(Math.Max(StatsBuffer.SummaryLots(bar) * 2, 2));
                    int yPos      = yPriceBottom - posHeight;

                    switch (StatsBuffer.SummaryDir(bar))
                    {
                    case PosDirection.Long:
                        rectPosition[index]  = new Rectangle(axisX[index], yPos, 1, posHeight);
                        brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeLong);
                        break;

                    case PosDirection.Short:
                        rectPosition[index]  = new Rectangle(axisX[index], yPos, 1, posHeight);
                        brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeShort);
                        break;

                    case PosDirection.Closed:
                        rectPosition[index]  = new Rectangle(axisX[index], yPos - 2, 1, 2);
                        brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeClose);
                        break;
                    }
                }
                else
                {
                    // There is no position
                    rectPosition[index]  = Rectangle.Empty;
                    brushPosition[index] = new SolidBrush(LayoutColors.ColorChartBack);
                }
                index++;
            }

            // Indicators in the chart
            int slots = StatsBuffer.Strategy.Slots;

            isSeparatedChart = new bool[slots];
            componentLength  = new int[slots];
            chartType        = new IndChartType[slots][];
            chartLine        = new Point[slots][][];
            chartDot         = new Rectangle[slots][][];
            chartLevel       = new Rectangle[slots][][];
            chartValue       = new double[slots][][];
            chartPen         = new Pen[slots][][];
            chartBrush       = new Brush[slots][];

            for (int slot = 0; slot < slots; slot++)
            {
                isSeparatedChart[slot] = StatsBuffer.Strategy.Slot[slot].SeparatedChart;
                int count = StatsBuffer.Strategy.Slot[slot].Component.Length;
                componentLength[slot] = count;
                chartType[slot]       = new IndChartType[count];
                chartLine[slot]       = new Point[count][];
                chartDot[slot]        = new Rectangle[count][];
                chartLevel[slot]      = new Rectangle[count][];
                chartValue[slot]      = new double[count][];
                chartPen[slot]        = new Pen[count][];
                chartBrush[slot]      = new Brush[count];
            }

            for (int slot = 0; slot < slots; slot++)
            {
                if (isSeparatedChart[slot])
                {
                    continue;
                }

                for (int comp = 0; comp < componentLength[slot]; comp++)
                {
                    chartType[slot][comp] = StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType;
                    switch (StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType)
                    {
                    case IndChartType.Line:
                    case IndChartType.CloudUp:
                    case IndChartType.CloudDown:
                        chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        chartLine[slot][comp] = new Point[chartLastBar - chartFirstBar + 1];
                        for (int bar = chartFirstBar; bar <= chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - chartFirstBar) * chartBarWidth + xLeft;
                            var    y     = (int)(yPriceBottom - (value - minPrice) * scaleY);

                            if (Math.Abs(value - 0) < 0.0001)
                            {
                                chartLine[slot][comp][bar - chartFirstBar] =
                                    chartLine[slot][comp][Math.Max(bar - chartFirstBar - 1, 0)];
                            }
                            else
                            {
                                chartLine[slot][comp][bar - chartFirstBar] = new Point(x, y);
                            }
                        }
                        break;

                    case IndChartType.Dot:
                        chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        chartDot[slot][comp] = new Rectangle[chartLastBar - chartFirstBar + 1];
                        for (int bar = chartFirstBar; bar <= chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - chartFirstBar) * chartBarWidth + xLeft;
                            var    y     = (int)(yPriceBottom - (value - minPrice) * scaleY);
                            chartDot[slot][comp][bar - chartFirstBar] = new Rectangle(x, y, 1, 1);
                        }
                        break;

                    case IndChartType.Level:
                        chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        chartLevel[slot][comp] = new Rectangle[chartLastBar - chartFirstBar + 1];
                        for (int bar = chartFirstBar; bar <= chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - chartFirstBar) * chartBarWidth + xLeft;
                            var    y     = (int)(yPriceBottom - (value - minPrice) * scaleY);
                            chartLevel[slot][comp][bar - chartFirstBar] = new Rectangle(x, y, chartBarWidth, 1);
                        }
                        break;
                    }
                }
            }

            // Separate indicators
            yIndTop    = new int[separateIndicatorsCount];
            yIndBottom = new int[separateIndicatorsCount];
            maxValues  = new double[separateIndicatorsCount];
            minValues  = new double[separateIndicatorsCount];
            scales     = new double[separateIndicatorsCount];

            for (int ind = 0; ind < separateIndicatorsCount; ind++)
            {
                yIndTop[ind]    = yBottom - (ind + 1) * separateIndicatorsChartHeight + 1;
                yIndBottom[ind] = yBottom - ind * separateIndicatorsChartHeight - 1;
                maxValues[ind]  = double.MinValue;
                minValues[ind]  = double.MaxValue;
                int slot = indicatorSlots[ind];

                for (int comp = 0; comp < componentLength[slot]; comp++)
                {
                    if (StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType != IndChartType.NoChart)
                    {
                        for (
                            int bar = Math.Max(chartFirstBar, StatsBuffer.Strategy.Slot[slot].Component[comp].FirstBar);
                            bar <= chartLastBar;
                            bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            if (value > maxValues[ind])
                            {
                                maxValues[ind] = value;
                            }
                            if (value < minValues[ind])
                            {
                                minValues[ind] = value;
                            }
                        }
                    }
                }

                maxValues[ind] = Math.Max(maxValues[ind], StatsBuffer.Strategy.Slot[slot].MaxValue);
                minValues[ind] = Math.Min(minValues[ind], StatsBuffer.Strategy.Slot[slot].MinValue);

                foreach (double specialValue in StatsBuffer.Strategy.Slot[slot].SpecValue)
                {
                    if (Math.Abs(specialValue - 0) < 0.0001)
                    {
                        maxValues[ind] = Math.Max(maxValues[ind], 0);
                        minValues[ind] = Math.Min(minValues[ind], 0);
                    }
                }

                scales[ind] = (yIndBottom[ind] - yIndTop[ind] - 2) / (Math.Max(maxValues[ind] - minValues[ind], 0.0001f));

                // Indicator chart
                for (int comp = 0; comp < StatsBuffer.Strategy.Slot[slot].Component.Length; comp++)
                {
                    chartType[slot][comp] = StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType;
                    switch (chartType[slot][comp])
                    {
                    case IndChartType.Line:
                        chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        chartLine[slot][comp] = new Point[chartLastBar - chartFirstBar + 1];
                        for (int bar = chartFirstBar; bar <= chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - chartFirstBar) * chartBarWidth + xLeft;
                            var    y     = (int)(yIndBottom[ind] - 1 - (value - minValues[ind]) * scales[ind]);
                            chartLine[slot][comp][bar - chartFirstBar] = new Point(x, y);
                        }
                        break;

                    case IndChartType.Histogram:
                        chartValue[slot][comp] = new double[chartLastBar - chartFirstBar + 1];
                        chartPen[slot][comp]   = new Pen[chartLastBar - chartFirstBar + 1];
                        for (int bar = chartFirstBar; bar <= chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            chartValue[slot][comp][bar - chartFirstBar] = value;
                            if (value > StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar - 1])
                            {
                                chartPen[slot][comp][bar - chartFirstBar] = penGreen;
                            }
                            else
                            {
                                chartPen[slot][comp][bar - chartFirstBar] = penRed;
                            }
                        }
                        break;
                    }
                }
            }
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        /// <summary>
        ///     Sets the chart parameters
        /// </summary>
        public void InitChart()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque,
                     true);

            // Chart Title
            strChartTitle = Language.T("Trade Distribution Chart");
            font          = new Font(Font.FontFamily, 9);
            captionHeight = Math.Max(font.Height, 18);
            rectCaption   = new RectangleF(0, 0, ClientSize.Width, captionHeight);
            rectSubHeader = new RectangleF(0, captionHeight, ClientSize.Width, captionHeight);

            sfCaption = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap
            };

            brushFore = new SolidBrush(LayoutColors.ColorChartFore);
            penGrid   = new Pen(LayoutColors.ColorChartGrid)
            {
                DashStyle   = DashStyle.Dash,
                DashPattern = new float[] { 4, 2 }
            };
            penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), Border);

            if (isNotPaint)
            {
                return;
            }

            yTop    = (int)(2 * captionHeight + Space + 1);
            yBottom = ClientSize.Height - 2 * Space - 1 - Border;
            xAxisY  = yBottom - 3 - font.Height;

            Graphics g = CreateGraphics();

            labelWidthY = (int)
                          Math.Max(g.MeasureString(yAxisMin.ToString(CultureInfo.InvariantCulture), Font).Width,
                                   g.MeasureString(yAxisMax.ToString(CultureInfo.InvariantCulture), Font).Width);
            labelWidthX = (int)
                          Math.Max(g.MeasureString(xAxisMin.ToString(CultureInfo.InvariantCulture), Font).Width,
                                   g.MeasureString(xAxisMax.ToString(CultureInfo.InvariantCulture), Font).Width);
            g.Dispose();
            labelWidthY  = Math.Max(labelWidthY, 30);
            labelWidthX += 3;

            xLeft  = Border + Space;
            xRight = ClientSize.Width - Border - Space - labelWidthY;
            xScale = (xRight - 2 * Space - Border) / (float)chartBars;

            countLabelsX = Math.Min((xRight - xLeft) / labelWidthX, 20);
            deltaX       = (float)Math.Max(Math.Round((xAxisMax - xAxisMin) / (float)countLabelsX), 10);
            stepX        = (int)Math.Ceiling(deltaX / 10) * 10;
            countLabelsX = (int)Math.Ceiling((xAxisMax - xAxisMin) / (float)stepX);
            xAxisMax     = xAxisMin + countLabelsX * stepX;

            // difference from Y Axis for SmallBalanceChart:
            // prefer minimums because histogram counts are usually small, less than 10
            countLabelsY = Math.Min((xAxisY - yTop) / 20, 20);
            deltaY       = (float)Math.Round((yAxisMax - yAxisMin) / (float)countLabelsY);
            // protect against deltaY infinity and stepY = Number.min
            stepY = (float.IsInfinity(deltaY)) ? 20 : (int)deltaY;
            // protect against dividing by zero in case of no counts
            stepY        = (stepY == 0) ? 1 : stepY;
            countLabelsY = (int)Math.Ceiling((yAxisMax - yAxisMin) / (float)stepY);
            // protect against dividing by zero in case of no counts
            countLabelsY = (countLabelsY == 0) ? 5 : countLabelsY;

            // protect against dividing by zero in case of no counts
            yAxisMax = (yAxisMax == 0) ? 5 : yAxisMax;
            yScale   = (xAxisY - yTop) / (countLabelsY * (float)stepY);

            // Context button colors.
            ButtonsColorBack     = LayoutColors.ColorCaptionBack;
            ButtonColorFore      = LayoutColors.ColorCaptionText;
            ContextMenuColorBack = LayoutColors.ColorControlBack;
            ContextMenuColorFore = LayoutColors.ColorControlText;
        }
コード例 #13
0
        /// <summary>
        ///     Sets the chart parameters
        /// </summary>
        public void InitChart()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque,
                     true);

            // Chart Title
            chartTitle = Language.T("Balance / Equity Chart") + " [" +
                         (Configs.AccountInMoney ? Configs.AccountCurrency + "]" : Language.T("points") + "]");
            font                = new Font(Font.FontFamily, 9);
            captionHeight       = Math.Max(font.Height, 18);
            rectfCaption        = new RectangleF(0, 0, ClientSize.Width, captionHeight);
            stringFormatCaption = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap
            };
            brushFore = new SolidBrush(LayoutColors.ColorChartFore);
            penGrid   = new Pen(LayoutColors.ColorChartGrid)
            {
                DashStyle   = DashStyle.Dash,
                DashPattern = new float[] { 4, 2 }
            };
            penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption),
                                Border);

            if (isNotPaint)
            {
                return;
            }

            yTop    = (int)captionHeight + 2 * Space + 1;
            yBottom = ClientSize.Height - 2 * Space - 1 - Border;

            Graphics g            = CreateGraphics();
            float    widthMinimum = g.MeasureString(data.Minimum.ToString(CultureInfo.InvariantCulture), Font).Width;
            float    widthMaximum = g.MeasureString(data.Maximum.ToString(CultureInfo.InvariantCulture), Font).Width;

            labelWidth = (int)Math.Max(widthMinimum, widthMaximum);
            labelWidth = Math.Max(labelWidth, 30);
            g.Dispose();

            xLeft  = Border + Space;
            xRight = ClientSize.Width - Border - Space - labelWidth;
            xScale = (xRight - 2 * Space - Border) / (float)chartBars;

            countLabels = (int)Math.Max((yBottom - yTop) / 20.0, 1);
            delta       = (float)Math.Max(Math.Round((data.Maximum - data.Minimum) / (float)countLabels), 10);
            labelStep   = (int)Math.Ceiling(delta / 10) * 10;
            countLabels = (int)Math.Ceiling((data.Maximum - data.Minimum) / (float)labelStep);
            yScale      = (yBottom - yTop) / (countLabels * (float)labelStep);

            balancePoints = new PointF[chartBars];
            equityPoints  = new PointF[chartBars];

            if (Configs.AdditionalStatistics)
            {
                longBalancePoints  = new PointF[chartBars];
                shortBalancePoints = new PointF[chartBars];
            }

            closePricePoints = new PointF[chartBars];

            // Close Price
            if (showPriceLine)
            {
                yPriceScale = (float)((yBottom - yTop) / (data.DataMaxPrice - data.DataMinPrice));
            }

            for (int bar = data.FirstBar; bar < data.Bars; bar++)
            {
                int index = bar - data.FirstBar;
                balancePoints[index].X = xLeft + index * xScale;
                equityPoints[index].X  = xLeft + index * xScale;
                if (Configs.AccountInMoney)
                {
                    balancePoints[index].Y = (float)(yBottom - (data.MoneyBalance[bar] - data.Minimum) * yScale);
                    equityPoints[index].Y  = (float)(yBottom - (data.MoneyEquity[bar] - data.Minimum) * yScale);
                }
                else
                {
                    balancePoints[index].Y = yBottom - (data.Balance[bar] - data.Minimum) * yScale;
                    equityPoints[index].Y  = yBottom - (data.Equity[bar] - data.Minimum) * yScale;
                }

                if (Configs.AdditionalStatistics)
                {
                    longBalancePoints[index].X  = xLeft + index * xScale;
                    shortBalancePoints[index].X = xLeft + index * xScale;
                    if (Configs.AccountInMoney)
                    {
                        longBalancePoints[index].Y =
                            (float)(yBottom - (data.LongMoneyBalance[bar] - data.Minimum) * yScale);
                        shortBalancePoints[index].Y =
                            (float)(yBottom - (data.ShortMoneyBalance[bar] - data.Minimum) * yScale);
                    }
                    else
                    {
                        longBalancePoints[index].Y  = yBottom - (data.LongBalance[bar] - data.Minimum) * yScale;
                        shortBalancePoints[index].Y = yBottom - (data.ShortBalance[bar] - data.Minimum) * yScale;
                    }
                }

                if (showPriceLine)
                {
                    closePricePoints[index].X = xLeft + index * xScale;
                    closePricePoints[index].Y = yBottom -
                                                (float)(data.ClosePrice[bar] - data.DataMinPrice) * yPriceScale;
                }
            }

            // Margin Call
            xMarginCallBar = data.MarginCallBar >= data.FirstBar
                                 ? xLeft + (data.MarginCallBar - data.FirstBar) * xScale
                                 : 0;

            //OOS
            if (IsOOS && OOSBar > data.FirstBar)
            {
                xOOSBar = xLeft + (OOSBar - data.FirstBar) * xScale;
            }
            else
            {
                xOOSBar = 0;
            }

            yBalance = yBottom - (data.NetBalance - data.Minimum) * yScale;

            isHideScanningLine    = false;
            data.ModellingQuolity = " MQ " + Data.ModellingQuality.ToString("N2") + "%";

            ButtonsColorBack     = LayoutColors.ColorCaptionBack;
            ButtonColorFore      = LayoutColors.ColorCaptionText;
            ContextMenuColorBack = LayoutColors.ColorControlBack;
            ContextMenuColorFore = LayoutColors.ColorControlText;
        }
コード例 #14
0
        /// <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());
        }
コード例 #15
0
 /// <summary>
 ///     Sets the panel colors
 /// </summary>
 private void SetColors()
 {
     colorCaptionBack = LayoutColors.ColorCaptionBack;
     brushCaption     = new SolidBrush(LayoutColors.ColorCaptionText);
     penBorder        = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), Border);
 }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
        /// <summary>
        ///     Sets the chart parameters
        /// </summary>
        private void InitChart(int width, int height)
        {
            try
            {
                Chart = new Bitmap(width, height);

                if (!Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar)
                {
                    return;
                }

                const int border = 1;
                const int space  = 2;

                int maximum;
                int minimum;

                int firstBar   = Data.FirstBar;
                int bars       = Data.Bars;
                int chartBars  = Data.Bars - firstBar;
                int maxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance;
                int minBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance;
                int maxEquity  = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity : Backtester.MaxEquity;
                int minEquity  = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity : Backtester.MinEquity;

                if (Configs.AdditionalStatistics)
                {
                    int maxLongBalance = Configs.AccountInMoney
                                             ? (int)Backtester.MaxLongMoneyBalance
                                             : Backtester.MaxLongBalance;
                    int minLongBalance = Configs.AccountInMoney
                                             ? (int)Backtester.MinLongMoneyBalance
                                             : Backtester.MinLongBalance;
                    int maxShortBalance = Configs.AccountInMoney
                                              ? (int)Backtester.MaxShortMoneyBalance
                                              : Backtester.MaxShortBalance;
                    int minShortBalance = Configs.AccountInMoney
                                              ? (int)Backtester.MinShortMoneyBalance
                                              : Backtester.MinShortBalance;
                    int maxLsBalance = Math.Max(maxLongBalance, maxShortBalance);
                    int minLsBalance = Math.Min(minLongBalance, minShortBalance);

                    maximum = Math.Max(Math.Max(maxBalance, maxEquity), maxLsBalance) + 1;
                    minimum = Math.Min(Math.Min(minBalance, minEquity), minLsBalance) - 1;
                }
                else
                {
                    maximum = Math.Max(maxBalance, maxEquity) + 1;
                    minimum = Math.Min(minBalance, minEquity) - 1;
                }

                const int yTop    = border + space;
                int       yBottom = height - border - space;
                const int xLeft   = border;
                int       xRight  = width - border - space;
                float     xScale  = (xRight - xLeft) / (float)chartBars;
                float     yScale  = (yBottom - yTop) / (float)(maximum - minimum);

                var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption),
                                        border);

                var balancePoints      = new PointF[chartBars];
                var equityPoints       = new PointF[chartBars];
                var longBalancePoints  = new PointF[chartBars];
                var shortBalancePoints = new PointF[chartBars];

                int index = 0;
                for (int bar = firstBar; bar < bars; bar++)
                {
                    balancePoints[index].X = xLeft + index * xScale;
                    equityPoints[index].X  = xLeft + index * xScale;
                    if (Configs.AccountInMoney)
                    {
                        balancePoints[index].Y = (float)(yBottom - (Backtester.MoneyBalance(bar) - minimum) * yScale);
                        equityPoints[index].Y  = (float)(yBottom - (Backtester.MoneyEquity(bar) - minimum) * yScale);
                    }
                    else
                    {
                        balancePoints[index].Y = yBottom - (Backtester.Balance(bar) - minimum) * yScale;
                        equityPoints[index].Y  = yBottom - (Backtester.Equity(bar) - minimum) * yScale;
                    }

                    if (Configs.AdditionalStatistics)
                    {
                        longBalancePoints[index].X  = xLeft + index * xScale;
                        shortBalancePoints[index].X = xLeft + index * xScale;
                        if (Configs.AccountInMoney)
                        {
                            longBalancePoints[index].Y =
                                (float)(yBottom - (Backtester.LongMoneyBalance(bar) - minimum) * yScale);
                            shortBalancePoints[index].Y =
                                (float)(yBottom - (Backtester.ShortMoneyBalance(bar) - minimum) * yScale);
                        }
                        else
                        {
                            longBalancePoints[index].Y  = yBottom - (Backtester.LongBalance(bar) - minimum) * yScale;
                            shortBalancePoints[index].Y = yBottom - (Backtester.ShortBalance(bar) - minimum) * yScale;
                        }
                    }

                    index++;
                }

                Graphics g = Graphics.FromImage(Chart);

                // Paints the background by gradient
                var rectField = new RectangleF(1, 1, width - 2, height - 2);
                g.FillRectangle(new SolidBrush(LayoutColors.ColorChartBack), rectField);

                // Border
                g.DrawRectangle(penBorder, 0, 0, width - 1, height - 1);

                // 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);
                }

                // Draw the balance line
                g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), balancePoints);
            } catch { }
        }
コード例 #18
0
        /// <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);
        }