GradientPaint() public static method

Paints a rectangle with gradient
public static GradientPaint ( Graphics g, RectangleF rect, Color color, int depth ) : void
g System.Drawing.Graphics
rect System.Drawing.RectangleF
color Color
depth int
return void
        /// <summary>
        /// On Paint
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption
            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(caption, fontCaption, brushCaption, rectfCaption, stringFormatCaption);

            float y = captionHeight;

            for (int i = 0; i *rowHeight + captionHeight < height; i++)
            {
                float      fVerticalPosition = i * rowHeight + captionHeight;
                PointF     pointFParam       = new PointF(paramTab + 2, fVerticalPosition);
                PointF     pointFValue       = new PointF(valueTab + 2, fVerticalPosition);
                RectangleF rectRow           = new RectangleF(border, fVerticalPosition, width, rowHeight);

                // Row background
                if (i + vScrollBar.Value < rows && abFlag[i + vScrollBar.Value])
                {
                    g.FillRectangle(new SolidBrush(colorBackroundWarningRow), rectRow);
                }
                else if (i % 2f != 0)
                {
                    g.FillRectangle(new SolidBrush(colorBackroundEvenRows), rectRow);
                }
                else
                {
                    g.FillRectangle(new SolidBrush(colorBackroundOddRows), rectRow);
                }

                if (i + vScrollBar.Value >= rows)
                {
                    continue;
                }

                if (i + vScrollBar.Value < rows && abFlag[i + vScrollBar.Value])
                {
                    Brush brush = new SolidBrush(colorTextWarningRow);
                    Pen   pen   = new Pen(colorTextWarningRow);
                    g.DrawString(asParam[i + vScrollBar.Value], fontData, brush, pointFParam, stringFormatData);
                    g.DrawString(asValue[i + vScrollBar.Value], fontData, brush, pointFValue, stringFormatData);
                }
                else
                {
                    g.DrawString(asParam[i + vScrollBar.Value], fontData, brushParams, pointFParam, stringFormatData);
                    g.DrawString(asValue[i + vScrollBar.Value], fontData, brushData, pointFValue, stringFormatData);
                }
            }

            // Border
            g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height);
            g.DrawLine(penBorder, ClientSize.Width - border + 1, captionHeight, ClientSize.Width - border + 1, ClientSize.Height);
            g.DrawLine(penBorder, 0, ClientSize.Height - border + 1, ClientSize.Width, ClientSize.Height - border + 1);

            return;
        }
Exemplo n.º 2
0
        /// <summary>
        /// On Paint
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption
            Data.GradientPaint(g, _rectfCaption, _colorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(_caption, _fontCaption, _brushCaption, _rectfCaption, _stringFormatCaption);

            for (int i = 0; i *_rowHeight + _captionHeight < _height; i++)
            {
                float fVerticalPosition = i * _rowHeight + _captionHeight;
                var   pointFParam       = new PointF(_paramTab + 2, fVerticalPosition);
                var   pointFValue       = new PointF(_valueTab + 2, fVerticalPosition);
                var   rectRow           = new RectangleF(Border, fVerticalPosition, _width, _rowHeight);

                // Row background
                if (i + _vScrollBar.Value < _rows && _flagsList[i + _vScrollBar.Value])
                {
                    g.FillRectangle(new SolidBrush(_colorBackroundWarningRow), rectRow);
                }
                else if (Math.Abs(i % 2f - 0) > 0.001)
                {
                    g.FillRectangle(new SolidBrush(_colorBackroundEvenRows), rectRow);
                }
                else
                {
                    g.FillRectangle(new SolidBrush(_colorBackroundOddRows), rectRow);
                }

                if (i + _vScrollBar.Value >= _rows)
                {
                    continue;
                }

                if (i + _vScrollBar.Value < _rows && _flagsList[i + _vScrollBar.Value])
                {
                    Brush brush = new SolidBrush(_colorTextWarningRow);
                    g.DrawString(_paramsList[i + _vScrollBar.Value], _fontData, brush, pointFParam, _stringFormatData);
                    g.DrawString(_valuesList[i + _vScrollBar.Value], _fontData, brush, pointFValue, _stringFormatData);
                }
                else
                {
                    g.DrawString(_paramsList[i + _vScrollBar.Value], _fontData, _brushParams, pointFParam,
                                 _stringFormatData);
                    g.DrawString(_valuesList[i + _vScrollBar.Value], _fontData, _brushData, pointFValue,
                                 _stringFormatData);
                }
            }

            // Border
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1,
                       ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);
        }
Exemplo n.º 3
0
        /// <summary>
        /// On Paint
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption
            Data.GradientPaint(g, _rectfCaption, _colorCaptionBack, LayoutColors.DepthCaption);
            if (_showCaption)
            {
                g.DrawString(_caption, _fontCaption, _brushCaption, _rectfCaption, _stringFormatCaption);
            }

            g.DrawLine(_penBorder, 1, CaptionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, CaptionHeight, ClientSize.Width - Border + 1,
                       ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);

            // Paint the panel background
            var rectClient = new RectangleF(Border, CaptionHeight, _width, _height);

            Data.GradientPaint(g, rectClient, LayoutColors.ColorControlBack, LayoutColors.DepthControl);
        }
        /// <summary>
        /// On Paint
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption
            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);
            if (showCaption)
            {
                g.DrawString(caption, fontCaption, brushCaption, rectfCaption, stringFormatCaption);
            }

            g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height);
            g.DrawLine(penBorder, ClientSize.Width - border + 1, captionHeight, ClientSize.Width - border + 1, ClientSize.Height);
            g.DrawLine(penBorder, 0, ClientSize.Height - border + 1, ClientSize.Width, ClientSize.Height - border + 1);

            // Paint the panel background
            RectangleF rectClient = new RectangleF(border, captionHeight, width, height);

            Data.GradientPaint(g, rectClient, LayoutColors.ColorControlBack, LayoutColors.DepthControl);

            return;
        }
Exemplo n.º 5
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("pips")) + "]";
            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;

            //
            // 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 fScaleX = (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 * fScaleX;
                    apntMinRandom[iBar].Y = yBottom - (_afMinRandom[iBar] - min) * scaleY;
                    apntMaxRandom[iBar].X = border + space + iBar * fScaleX;
                    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 * fScaleX;
                    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 * fScaleX;
                apntBalance[bar].Y = yBottom - (_afBalance[bar] - min) * scaleY;
            }
            g.DrawLines(_penBalance, apntBalance);

            // Coordinate axes
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), border + space - 1, yTop - space, border + space - 1,
                       yBottom);
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), border + space, yBottom, xRight, yBottom);

            // Balance label
            float fBalanceY = yBottom - (_afBalance[bars - 1] - min) * scaleY;

            g.DrawLine(new Pen(LayoutColors.ColorChartCross), border + space, 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, border + space, 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 (Data.IntraBars != null && Data.IsIntrabarData && Backtester.IsScanPerformed)
            {
                g.DrawLine(new Pen(LayoutColors.ColorChartFore), border + space - 1, yBottom, border + space - 1,
                           yBottom + 8);
                DataPeriods 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) * fScaleX) + border + space;
                        int xEnd   = (int)((bar - Data.FirstBar) * fScaleX) + border + space;
                        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]];
                    }
                }
            }
        }
        /// <summary>
        /// Paints panel pnlChart
        /// </summary>
        void PnlChart_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.Clear(LayoutColors.ColorChartBack);

            if (!Data.IsData || !Data.IsResult)
            {
                return;
            }

            Panel  pnl     = (Panel)sender;
            Pen    penFore = new Pen(LayoutColors.ColorControlText);
            string FF      = Data.FF;    // Format modifier to print the floats
            int    width   = pnl.ClientSize.Width;

            Size size = new Size(width, infoRowHeight);

            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Near;

            // Caption background
            PointF     pntStart     = new PointF(0, 0);
            SizeF      szfCaption   = new Size(width, infoRowHeight);
            RectangleF rectfCaption = new RectangleF(pntStart, szfCaption);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            // Caption Text
            StringFormat stringFormatCaption = new StringFormat();

            stringFormatCaption.LineAlignment = StringAlignment.Center;
            stringFormatCaption.Trimming      = StringTrimming.EllipsisCharacter;
            stringFormatCaption.FormatFlags   = StringFormatFlags.NoWrap;
            stringFormatCaption.Alignment     = StringAlignment.Center;
            string stringCaptionText = Language.T("Price Route Inside the Bar");

            rectfCaption = new RectangleF(border, 0, pnl.ClientSize.Width - 2 * border, infoRowHeight);
            g.DrawString(stringCaptionText, fontInfo, brushCaptionText, rectfCaption, stringFormatCaption);

            // Paint the panel background
            RectangleF rectClient = new RectangleF(0, infoRowHeight, pnl.ClientSize.Width, pnl.Height - infoRowHeight);

            Data.GradientPaint(g, rectClient, LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            // Paint bar info
            RectangleF rectBarInfo = new RectangleF(border, infoRowHeight + 1, pnl.ClientSize.Width - 2 * border, infoRowHeight);

            g.DrawString(barInfo, fontInfo, brushGridText, rectBarInfo, stringFormatCaption);

            // Searching the min and the max price and volume
            width = pnl.ClientSize.Width - 2 * border;
            double maxPrice   = Data.High[bar];
            double minPrice   = Data.Low[bar];
            int    space      = 8;
            int    spcRight   = szPrice.Width + 4;
            int    XLeft      = border + space;
            int    XRight     = width - spcRight;
            int    chartWidth = XRight - XLeft;
            int    YTop       = 2 * infoRowHeight + 6;
            int    YBottom    = pnl.ClientSize.Height - 22;
            int    barPixels  = 28;
            int    spcLeft    = 3;
            int    x          = barPixels + spcLeft;

            int pointLeft   = x + barPixels + 30;
            int pointX      = pointLeft;
            int pointRight  = XRight - 20;
            int points      = Backtester.WayPoints(bar);
            int pointRadius = 3;

            // Grid
            int    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);
            int    yOpen  = (int)(YBottom - (Data.Open[bar] - minPrice) * scaleY);
            int    yHigh  = (int)(YBottom - (Data.High[bar] - minPrice) * scaleY);
            int    yLow   = (int)(YBottom - (Data.Low[bar] - minPrice) * scaleY);
            int    yClose = (int)(YBottom - (Data.Close[bar] - minPrice) * scaleY);

            // Find the price distance
            double priceDistance = 0;

            for (int point = 1; point < points; point++)
            {
                priceDistance += Math.Abs(Backtester.WayPoint(bar, point).Price - Backtester.WayPoint(bar, point - 1).Price);
            }
            double dPriceForAPixel = (pointRight - pointLeft) / priceDistance;

            // Points X
            int[] aiPointX = new int[points];
            aiPointX[0] = pointLeft;
            for (int point = 1; point < points - 1; point++)
            {
                int iDistance = (int)(Math.Abs(Backtester.WayPoint(bar, point).Price - Backtester.WayPoint(bar, 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
            Point[] pntWay = new Point[points];
            for (int point = 0; point < points; point++)
            {
                int pointY = (int)(YBottom - (Backtester.WayPoint(bar, 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)
            {
                int 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++)
            {
                Point pt1 = new Point(pntWay[point].X, YTop);
                Point pt2 = new Point(pntWay[point].X, YBottom + 2);
                Point pt3 = new Point(pntWay[point].X - 5, YBottom + 4);
                g.DrawLine(penGrid, pt1, pt2);
                g.DrawString((point + 1).ToString(), Font, brushGridText, pt3);
            }

            // Bar Number
            string barNumber = (bar + 1).ToString();
            int    stringX   = x + barPixels / 2 - 1 - g.MeasureString(barNumber, Font).ToSize().Width / 2;

            if (Backtester.BackTestEval(bar) == "Ambiguous")
            {
                g.DrawString(barNumber, Font, brushRed, stringX, YBottom + 4);
            }
            else
            {
                g.DrawString(barNumber, Font, brushGridText, stringX, YBottom + 4);
            }

            // Draw the bar
            g.DrawLine(penBarBorder, x + barPixels / 2 - 1, yLow, x + barPixels / 2 - 1, yHigh);
            if (yClose < yOpen) // White bar
            {
                Rectangle           rect    = new Rectangle(x, yClose, barPixels - 2, yOpen - yClose);
                LinearGradientBrush 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
            {
                Rectangle           rect    = new Rectangle(x, yOpen, barPixels - 2, yClose - yOpen);
                LinearGradientBrush 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(bar); orderIndex++)
            {
                int   ordNumber = Backtester.OrdNumb(bar, orderIndex);
                Order order     = Backtester.OrdFromNumb(ordNumber);
                if (order.OrdStatus != OrderStatus.Cancelled)
                {
                    continue;
                }

                if (order.OrdPrice > Data.High[bar] || order.OrdPrice < Data.Low[bar])
                {
                    continue;
                }

                int d     = barPixels / 2 - 1;
                int x1    = x + d;
                int x2    = x + barPixels - 2;
                int yDeal = (int)(YBottom - (order.OrdPrice - minPrice) * scaleY);
                Pen 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(bar); pos++)
            {
                if (Backtester.PosTransaction(bar, pos) == Transaction.Transfer)
                {
                    continue;
                }

                int yDeal = (int)(YBottom - (Backtester.PosOrdPrice(bar, pos) - minPrice) * scaleY);

                if (Backtester.PosDir(bar, pos) == PosDirection.Long ||
                    Backtester.PosDir(bar, pos) == PosDirection.Short)
                {
                    int d  = barPixels / 2 - 1;
                    int x1 = x + d;
                    int x2 = x + barPixels - 2;
                    if (Backtester.OrdFromNumb(Backtester.PosOrdNumb(bar, pos)).OrdDir == OrderDirection.Buy)
                    {   // Buy
                        Pen 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
                        Pen 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(bar, pos) == PosDirection.Closed)
                {   // Close position
                    int d   = barPixels / 2 - 1;
                    int x1  = x + d;
                    int x2  = x + barPixels - 3;
                    Pen 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(bar, point).PosNumb;
                if (posNumber == -1)
                {
                    continue;
                }

                double       posLots      = Backtester.PosFromNumb(posNumber).PosLots;
                PosDirection posDirection = Backtester.PosFromNumb(posNumber).PosDir;
                WayPointType wpType       = Backtester.WayPoint(bar, point).WPType;

                int posHight = (int)(Math.Max(posLots * 2, 2));
                int posY     = YBottom - posHight;
                int d        = (barPixels - 1) / 2;
                x = pntWay[point].X - d;

                if (posDirection == PosDirection.Long)
                {    // Long
                    Rectangle           rect    = new Rectangle(x - 1, posY, barPixels + 1, posHight);
                    LinearGradientBrush lgBrush = new LinearGradientBrush(rect, colorLongTrade1, colorLongTrade2, 0f);
                    rect = new Rectangle(x, posY, barPixels - 1, posHight);
                    g.FillRectangle(lgBrush, rect);
                }
                else if (posDirection == PosDirection.Short)
                {   // Short
                    Rectangle           rect    = new Rectangle(x - 1, posY, barPixels + 1, posHight);
                    LinearGradientBrush lgBrush = new LinearGradientBrush(rect, colorShortTrade1, colorShortTrade2, 0f);
                    rect = new Rectangle(x, posY, barPixels - 1, posHight);
                    g.FillRectangle(lgBrush, rect);
                }
                else if (posDirection == PosDirection.Closed && wpType == WayPointType.Exit)
                {   // Closed
                    Rectangle           rect    = new Rectangle(x - 1, YBottom - 2, barPixels + 1, 2);
                    LinearGradientBrush lgBrush = new LinearGradientBrush(rect, colorClosedTrade1, colorClosedTrade2, 0f);
                    rect = new Rectangle(x, 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;
                }

                Point ptControl1 = new Point(ctrlX1, ctrlY1);
                Point 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 the deals on the route
            for (int point = 0; point < points; point++)
            {
                int posNumber = Backtester.WayPoint(bar, point).PosNumb;
                int ordNumber = Backtester.WayPoint(bar, point).OrdNumb;

                if (posNumber < 0 || ordNumber < 0)
                {
                    continue;
                }

                PosDirection   posDirection = Backtester.PosFromNumb(posNumber).PosDir;
                OrderDirection ordDirection = Backtester.OrdFromNumb(ordNumber).OrdDir;
                WayPointType   wpType       = Backtester.WayPoint(bar, point).WPType;

                if (Backtester.PosFromNumb(posNumber).Transaction == Transaction.Transfer ||
                    wpType == WayPointType.Cancel || 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)
                {
                    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
                        Pen 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
                        Pen 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 (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;
                    Pen 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
            Pen penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border);

            g.DrawLine(penBorder, 1, infoRowHeight, 1, pnl.ClientSize.Height);
            g.DrawLine(penBorder, pnl.ClientSize.Width - border + 1, infoRowHeight, pnl.ClientSize.Width - border + 1, pnl.ClientSize.Height);
            g.DrawLine(penBorder, 0, pnl.ClientSize.Height - border + 1, pnl.ClientSize.Width, pnl.ClientSize.Height - border + 1);
        }
 /// <summary>
 /// Paints the base panel
 /// </summary>
 void PanelBase_Paint(object sender, PaintEventArgs e)
 {
     Data.GradientPaint(e.Graphics, ((Panel)sender).ClientRectangle, LayoutColors.ColorControlBack, LayoutColors.DepthControl);
 }
        /// <summary>
        /// Panel Slot Paint
        /// </summary>
        void PnlSlot_Paint(object sender, PaintEventArgs e)
        {
            Panel     pnl      = (Panel)sender;
            Graphics  g        = e.Graphics;
            int       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;

            default:
                break;
            }

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

            Font         fontCaptionText     = new Font(Font.FontFamily, 9);
            float        fCaptionHeight      = (float)Math.Max(fontCaptionText.Height, 18);
            float        fCaptionWidth       = width;
            Brush        brushCaptionText    = new SolidBrush(colorCaptionText);
            StringFormat stringFormatCaption = new StringFormat();

            stringFormatCaption.LineAlignment = StringAlignment.Center;
            stringFormatCaption.Trimming      = StringTrimming.EllipsisCharacter;
            stringFormatCaption.FormatFlags   = StringFormatFlags.NoWrap;
            stringFormatCaption.Alignment     = StringAlignment.Center;

            RectangleF rectfCaption = new RectangleF(0, 0, fCaptionWidth, fCaptionHeight);

            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);

            if (showRemoveSlotButtons && slot != strategy.OpenSlot && slot != strategy.CloseSlot)
            {
                int iButtonDimentions = (int)fCaptionHeight - 2;
                int iButtonX          = width - iButtonDimentions - 1;
                abtnRemoveSlot[slot].Size     = new Size(iButtonDimentions, iButtonDimentions);
                abtnRemoveSlot[slot].Location = new Point(iButtonX, 1);

                float  fCaptionTextWidth = g.MeasureString(stringCaptionText, fontCaptionText).Width;
                float  fCaptionTextX     = (float)Math.Max((fCaptionWidth - fCaptionTextWidth) / 2f, 0);
                PointF pfCaptionText     = new PointF(fCaptionTextX, 0);
                SizeF  sfCaptionText     = new SizeF(iButtonX - fCaptionTextX, fCaptionHeight);
                rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);
                stringFormatCaption.Alignment = StringAlignment.Near;
            }
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption);

            // Border
            g.DrawLine(penBorder, 1, fCaptionHeight, 1, pnl.Height);
            g.DrawLine(penBorder, pnl.Width - border + 1, fCaptionHeight, pnl.Width - border + 1, pnl.Height);
            g.DrawLine(penBorder, 0, pnl.Height - border + 1, pnl.Width, pnl.Height - border + 1);

            // Paints the panel
            RectangleF rectfPanel = new RectangleF(border, fCaptionHeight, pnl.Width - 2 * border, pnl.Height - fCaptionHeight - border);

            Data.GradientPaint(g, rectfPanel, colorBackground, LayoutColors.DepthControl);

            int iVPosition = (int)fCaptionHeight + 3;

            // Padlock image
            if (showPadlockImg)
            {
                if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Locked)
                {
                    g.DrawImage(Properties.Resources.padlock_img, 1, 1, 16, 16);
                }
                else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Open)
                {
                    g.DrawImage(Properties.Resources.open_padlock, 1, 1, 16, 16);
                }
                else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked)
                {
                    g.DrawImage(Properties.Resources.linked, 1, 1, 16, 16);
                }
            }

            // Indicator name
            StringFormat stringFormatIndicatorName = new StringFormat();

            stringFormatIndicatorName.Alignment     = StringAlignment.Center;
            stringFormatIndicatorName.LineAlignment = StringAlignment.Center;

            stringFormatIndicatorName.FormatFlags = StringFormatFlags.NoWrap;

            Font  fontIndicator  = new Font(Font.FontFamily, 11f, FontStyle.Regular);
            Brush brushIndName   = new SolidBrush(colorIndicatorNameText);
            float fIndNameHeight = fontIndicator.Height;
            float fGroupWidth    = 0;

            if (Configs.UseLogicalGroups && (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter))
            {
                string sLogicalGroup = "[" + strategy.Slot[slot].LogicalGroup + "]";
                fGroupWidth = g.MeasureString(sLogicalGroup, fontIndicator).Width;
                RectangleF rectGroup = new RectangleF(0, iVPosition, fGroupWidth, fIndNameHeight);
                g.DrawString(sLogicalGroup, fontIndicator, brushIndName, rectGroup, stringFormatIndicatorName);
            }
            stringFormatIndicatorName.Trimming = StringTrimming.EllipsisCharacter;
            string sIndicatorName  = strategy.Slot[slot].IndicatorName;
            float  fIndicatorWidth = g.MeasureString(sIndicatorName, fontIndicator).Width;

            RectangleF rectIndName;

            if (width >= 2 * fGroupWidth + fIndicatorWidth)
            {
                rectIndName = new RectangleF(0, iVPosition, width, fIndNameHeight);
            }
            else
            {
                rectIndName = new RectangleF(fGroupWidth, iVPosition, width - fGroupWidth, fIndNameHeight);
            }

            g.DrawString(sIndicatorName, fontIndicator, brushIndName, rectIndName, stringFormatIndicatorName);
            iVPosition += (int)fIndNameHeight;

            if (slotMinMidMax == SlotSizeMinMidMax.min)
            {
                return;
            }

            // Logic
            StringFormat stringFormatLogic = new StringFormat();

            stringFormatLogic.Alignment     = StringAlignment.Center;
            stringFormatLogic.LineAlignment = StringAlignment.Center;
            stringFormatLogic.Trimming      = StringTrimming.EllipsisCharacter;
            stringFormatLogic.FormatFlags   = StringFormatFlags.NoClip;

            float padding = space;

            if (strategy.Slot[slot].IndParam.ListParam[0].Enabled)
            {
                string     sValue     = strategy.Slot[slot].IndParam.ListParam[0].Text;
                Font       fontLogic  = new Font(Font.FontFamily, 10.5f, FontStyle.Regular);
                SizeF      sizeValue  = g.MeasureString(sValue, fontLogic, (int)(width - 2 * padding), stringFormatLogic);
                RectangleF rectValue  = new RectangleF(padding, iVPosition, width - 2 * padding, sizeValue.Height);
                Brush      brushLogic = new SolidBrush(colorLogicText);

                g.DrawString(sValue, fontLogic, brushLogic, rectValue, stringFormatLogic);
                iVPosition += (int)sizeValue.Height;
            }

            if (slotMinMidMax == SlotSizeMinMidMax.mid)
            {
                return;
            }

            // Parameters
            StringFormat stringFormat = new StringFormat();

            stringFormat.Trimming    = StringTrimming.EllipsisCharacter;
            stringFormat.FormatFlags = StringFormatFlags.NoWrap;

            Font  fontParam  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Font  fontValue  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Brush brushParam = new SolidBrush(colorParamText);
            Brush brushValue = new SolidBrush(colorValueText);
            Pen   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 sParam    = strategy.Slot[slot].IndParam.ListParam[i].Caption;
                string sValue    = strategy.Slot[slot].IndParam.ListParam[i].Text;
                SizeF  sizeParam = g.MeasureString(sParam, fontParam);
                SizeF  sizeValue = g.MeasureString(sValue, 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 sParam    = numericParam.Caption;
                string sValue    = numericParam.ValueToString;
                SizeF  sizeParam = g.MeasureString(sParam, fontParam);
                SizeF  sizeValue = g.MeasureString(sValue, 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 Param Padding Dash Padding Value Padding
            float dashWidth      = 5;
            float necessaryWidth = 4 * padding + maxParamWidth + maxValueWidth + dashWidth;

            if (width > necessaryWidth)
            {   // 2*Padding Param Padding Dash Padding Value 2*Padding
                padding = (float)Math.Max((pnl.ClientSize.Width - maxParamWidth - maxValueWidth - dashWidth) / 6, padding);
            }
            else
            {
                padding = 2;
            }

            float tabParam = 2 * padding;
            float tabDash  = tabParam + maxParamWidth + padding;
            float tabValue = tabDash + dashWidth + padding;

            // List Params
            for (int i = 1; i < 5; i++)
            {
                if (!strategy.Slot[slot].IndParam.ListParam[i].Enabled)
                {
                    continue;
                }

                string     sParam     = strategy.Slot[slot].IndParam.ListParam[i].Caption;
                string     sValue     = strategy.Slot[slot].IndParam.ListParam[i].Text;
                PointF     pointParam = new PointF(tabParam, iVPosition);
                PointF     pointDash1 = new PointF(tabDash, iVPosition + fontParam.Height / 2 + 2);
                PointF     pointDash2 = new PointF(tabDash + dashWidth, iVPosition + fontParam.Height / 2 + 2);
                PointF     pointValue = new PointF(tabValue, iVPosition);
                SizeF      sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                RectangleF rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height;
            }

            // Num Params
            foreach (NumericParam numericParam in strategy.Slot[slot].IndParam.NumParam)
            {
                if (!numericParam.Enabled)
                {
                    continue;
                }

                string     sParam     = numericParam.Caption;
                string     sValue     = numericParam.ValueToString;
                PointF     pointParam = new PointF(tabParam, iVPosition);
                PointF     pointDash1 = new PointF(tabDash, iVPosition + fontParam.Height / 2 + 2);
                PointF     pointDash2 = new PointF(tabDash + dashWidth, iVPosition + fontParam.Height / 2 + 2);
                PointF     pointValue = new PointF(tabValue, iVPosition);
                SizeF      sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                RectangleF rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height;
            }

            // Check Params
            foreach (CheckParam checkParam in strategy.Slot[slot].IndParam.CheckParam)
            {
                if (!checkParam.Enabled)
                {
                    continue;
                }

                string     param      = checkParam.Caption;
                string     salue      = checkParam.Checked ? "Yes" : "No";
                PointF     pointParam = new PointF(tabParam, iVPosition);
                PointF     pointDash1 = new PointF(tabDash, iVPosition + fontParam.Height / 2 + 2);
                PointF     pointDash2 = new PointF(tabDash + dashWidth, iVPosition + fontParam.Height / 2 + 2);
                PointF     pointValue = new PointF(tabValue, iVPosition);
                SizeF      sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                RectangleF rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(param, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(salue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height;
            }

            return;
        }
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g       = e.Graphics;
            int      iHScrll = -HScrollBar.Value;
            var      sf      = new StringFormat {
                Alignment = StringAlignment.Center
            };

            // Caption background
            var rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * _rowHeight);

            Data.GradientPaint(g, rectfCaption, 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("pips") + "]";
            string accUnit = " [" + Configs.AccountCurrency + "]";

            g.SetClip(new RectangleF(Border, 0, ClientSize.Width - 2 * Border, 2 * _rowHeight));
            g.DrawString(Language.T("Market Data"), font, brushCaptionText, iHScrll + (_xScaled[8] + _xScaled[0]) / 2, 0,
                         sf);
            g.DrawString(Language.T("Summary") + unit, font, brushCaptionText, iHScrll + (_xScaled[14] + _xScaled[8]) / 2,
                         0, sf);
            g.DrawString(Language.T("Account") + unit, font, brushCaptionText, iHScrll + (_xScaled[16] + _xScaled[14]) / 2,
                         0, sf);
            g.DrawString(Language.T("Margin") + accUnit, font, brushCaptionText,
                         iHScrll + (_xScaled[18] + _xScaled[16]) / 2, 0, sf);
            g.DrawString(Language.T("Backtest"), font, brushCaptionText, iHScrll + (_xScaled[19] + _xScaled[18]) / 2, 0,
                         sf);
            if (Configs.AccountInMoney)
            {
                for (int i = 0; i < _columns; i++)
                {
                    g.DrawString(_titlesInMoney[i], font, brushCaptionText, iHScrll + (_xScaled[i] + _xScaled[i + 1]) / 2,
                                 _rowHeight, sf);
                }
            }
            else
            {
                for (int i = 0; i < _columns; i++)
                {
                    g.DrawString(_titlesInPips[i], font, brushCaptionText, iHScrll + (_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], iHScrll + 2, imgY, 16, 16);

                // Prints the data
                g.DrawString(_journalData[index, 0], font, brush, iHScrll + (16 + _xScaled[1]) / 2, (index + 2) * _rowHeight,
                             sf);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_journalData[index, i], font, brush, iHScrll + (_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 rectfSeparator = new RectangleF(_xScaled[i] + iHScrll, (float)(_rowHeight / 2.0), 1,
                                                        (float)(3 * _rowHeight / 2.0));
                    Data.GradientPaint(g, rectfSeparator, LayoutColors.ColorCaptionBack, -2 * LayoutColors.DepthCaption);
                }
                g.DrawLine(penLines, _xScaled[i] + iHScrll, 2 * _rowHeight, _xScaled[i] + iHScrll, 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);

            OnSelectedBarChange(new EventArgs());
        }
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            int   scrll     = -hScrollBar.Value;
            bool  isWarning = false;
            Brush brush     = Brushes.Red;
            Size  size      = new Size(ClientSize.Width, rowHeight);

            StringFormat sf = new StringFormat();

            sf.Alignment = StringAlignment.Center;

            // Caption background
            RectangleF rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * rowHeight);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            // Print the journal caption
            string stringCaptionText = Language.T("Journal by Positions") +
                                       (showTransfers ? "" : " " + Language.T("without Transfers")) +
                                       (Configs.AccountInMoney ? " [" + Configs.AccountCurrency + "]" : " [" + Language.T("pips") + "]");

            g.DrawString(stringCaptionText, font, brushCaptionText, new RectangleF(Point.Empty, size), sf);
            g.SetClip(new RectangleF(border, rowHeight, ClientSize.Width - 2 * border, rowHeight));
            if (Configs.AccountInMoney)
            {
                g.DrawString(asTitlesMoney[0], font, brushCaptionText, scrll + (aiX[0] + aiX[1]) / 2, rowHeight, sf);
                for (int i = 1; i < columns; i++)
                {
                    g.DrawString(asTitlesMoney[i], font, brushCaptionText, scrll + (aiX[i] + aiX[i + 1]) / 2, rowHeight, sf);
                }
            }
            else
            {
                g.DrawString(asTitlesPips[0], font, brushCaptionText, scrll + (aiX[0] + aiX[1]) / 2, rowHeight, sf);
                for (int i = 1; i < columns; i++)
                {
                    g.DrawString(asTitlesPips[i], font, brushCaptionText, scrll + (aiX[i] + aiX[i + 1]) / 2, rowHeight, sf);
                }
            }
            g.ResetClip();

            // Paints the journal's data field
            RectangleF rectField = new RectangleF(border, 2 * rowHeight, ClientSize.Width - 2 * border, ClientSize.Height - 2 * rowHeight - border);

            g.FillRectangle(new SolidBrush(colorBack), rectField);

            size = new Size(ClientSize.Width - vScrollBar.Width - 2 * border, rowHeight);

            // Prints the journal data
            for (int pos = firstPos; pos < firstPos + shownPos; pos++)
            {
                int   y     = (pos - firstPos + 2) * rowHeight;
                Point point = new Point(border, y);

                // Even row
                if ((pos - firstPos) % 2f != 0)
                {
                    g.FillRectangle(brushEvenRowBack, new Rectangle(point, size));
                }

                // Warning row
                if (asJournalData[pos - firstPos, columns - 1] == Language.T("Ambiguous"))
                {
                    g.FillRectangle(brushWarningBack, new Rectangle(point, size));
                    isWarning = true;
                }
                else
                {
                    isWarning = false;
                }

                // Selected row
                if (pos - firstPos == selectedRow)
                {
                    g.FillRectangle(brushSelectedRowBack, new Rectangle(point, size));
                    brush = brushSelectedRowText;
                }
                else
                {
                    brush = isWarning ? brushWarningText : brushRowText;
                }

                // Draw the position icon
                int iImgY = y + (int)Math.Floor((rowHeight - 16) / 2.0);
                g.DrawImage(aiPositionIcons[pos - firstPos], scrll + 2, iImgY, 16, 16);

                // Prints the data
                g.DrawString(asJournalData[pos - firstPos, 0], font, brush, scrll + (16 + aiX[1]) / 2, (pos - firstPos + 2) * rowHeight, sf);
                for (int i = 1; i < columns; i++)
                {
                    g.DrawString(asJournalData[pos - firstPos, i], font, brush, scrll + (aiX[i] + aiX[i + 1]) / 2, (pos - firstPos + 2) * rowHeight, sf);
                }
            }

            //g.DrawLine(penLines, 0, iRowHeight, ClientSize.Width, iRowHeight);
            for (int i = 1; i < columns; i++)
            {
                g.DrawLine(penLines, aiX[i] + scrll, 2 * rowHeight, aiX[i] + scrll, 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);

            OnSelectedBarChange(new EventArgs());

            return;
        }
Exemplo n.º 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(DataPeriods)).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[DataPeriods.min1], 60);
                    rectf = new RectangleF(xp6 + 10, y + 7, xp7 - xp6 - 20, 3);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.day], 60);
                }
            }

            for (int prd = 0; prd < allPeriods; prd++)
            {
                int startY = _isTickDataFile ? 3 : 2;
                int y      = (prd + startY) * _infoRowHeight;

                var    period      = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).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);
        }
Exemplo n.º 12
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 rectfCaption = new RectangleF(0, 0, captionWidth, captionHeight);

            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, 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 rectfPanel = new RectangleF(Border, captionHeight, pnl.Width - 2 * Border,
                                            pnl.Height - captionHeight - Border);

            Data.GradientPaint(g, rectfPanel, 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    sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(parameter, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(text, fontValue, brushValue, rectfValue, 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);
                sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(parameter, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(text, fontValue, brushValue, rectfValue, 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);
                sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(parameter, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(text, fontValue, brushValue, rectfValue, 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);
                sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(parameter, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(text, fontValue, brushValue, rectfValue, 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);
                sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(parameter, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(text, fontValue, brushValue, rectfValue, stringFormat);
            }
        }
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g         = e.Graphics;
            var      chartArea = new Rectangle(Border, (int)_captionHeight, ClientSize.Width - 2 * Border, ClientSize.Height - (int)_captionHeight - Border);

            Data.GradientPaint(g, chartArea, LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            // Panel caption
            Data.GradientPaint(g, _captionRectangle, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(_captionText, _captionFont, _captionBrush, _captionRectangle, _captionStringFormat);

            // Border
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1, ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);

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

            // Limits the drawing into the chart area only
            g.SetClip(new Rectangle(_xLeft, _yTop, _xRight - _xLeft, _yPriceBottom - _yTop));

            // Draws Volume, Lots and Price
            int index = 0;

            for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
            {
                // Draw the volume
                if (_yVolume[index] != _yPriceBottom)
                {
                    g.DrawLine(_penVolume, _x[index], _yVolume[index], _x[index], _yPriceBottom - 1);
                }

                // Draw position lots
                if (_rectPosition[index] != Rectangle.Empty)
                {
                    g.FillRectangle(_brushPosition[index], _rectPosition[index]);
                }

                // Draw the bar
                var penBar = new Pen(LayoutColors.ColorBarBorder);
                g.DrawLine(penBar, _x[index], _yLow[index], _x[index], _yHigh[index]);
                g.DrawLine(penBar, _x[index], _yClose[index], _x[index] + 1, _yClose[index]);
                index++;
            }

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

            for (int slot = 0; slot < slots; slot++)
            {
                if (_isSeparatedChart[slot])
                {
                    continue;
                }
                for (int comp = 0; comp < _componentLenght[slot]; comp++)
                {
                    switch (_chartType[slot][comp])
                    {
                    case IndChartType.Line:
                        g.DrawLines(new Pen(_chartBrush[slot][comp]), _chartLine[slot][comp]);
                        break;

                    case IndChartType.Dot:
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            g.FillRectangle(_chartBrush[slot][comp], _chartDot[slot][comp][bar - _chartFirstBar]);
                        }
                        break;

                    case IndChartType.Level:
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            g.FillRectangle(_chartBrush[slot][comp], _chartLevel[slot][comp][bar - _chartFirstBar]);
                        }
                        break;

                    case IndChartType.CloudUp:
                        g.DrawLines(new Pen(_chartBrush[slot][comp])
                        {
                            DashStyle = DashStyle.Dash
                        }, _chartLine[slot][comp]);
                        break;

                    case IndChartType.CloudDown:
                        g.DrawLines(new Pen(_chartBrush[slot][comp])
                        {
                            DashStyle = DashStyle.Dash
                        }, _chartLine[slot][comp]);
                        break;
                    }
                }
            }
            g.ResetClip();

            // Separate indicators
            for (int ind = 0; ind < _separateIndicatorsCount; ind++)
            {
                int slot = _indicatorSlots[ind];

                for (int comp = 0; comp < _componentLenght[slot]; comp++)
                {
                    switch (_chartType[slot][comp])
                    {
                    case IndChartType.Line:
                        g.DrawLines(new Pen(_chartBrush[slot][comp]), _chartLine[slot][comp]);
                        break;

                    case IndChartType.Histogram:
                        double zero = 0;
                        if (zero < _minValues[ind])
                        {
                            zero = _minValues[ind];
                        }
                        if (zero > _maxValues[ind])
                        {
                            zero = _maxValues[ind];
                        }
                        var y0 = (int)(_yIndBottom[ind] - (zero - _minValues[ind]) * _scales[ind]);
                        g.DrawLine(_penDarkGray, _xLeft, y0, _xRight, y0);
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double val = _chartValue[slot][comp][bar - _chartFirstBar];
                            int    x   = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y   = (int)(_yIndBottom[ind] - (val - _minValues[ind]) * _scales[ind]);
                            g.DrawLine(_chartPen[slot][comp][bar - _chartFirstBar], x, y0, x, y);
                        }
                        break;
                    }
                }
            }

            // Lines
            for (int ind = 0; ind < _separateIndicatorsCount; ind++)
            {
                int y = _yBottom - (ind + 1) * _separateIndicatorsChartHeight;
                g.DrawLine(_penFore, _xLeft, y, _xRight, y);
            }
            g.DrawLine(_penFore, _xLeft, _yBottom, _xRight, _yBottom);
            g.DrawLine(_penFore, _xLeft, _yTop, _xLeft, _yBottom);
        }
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            int scrll        = -_hScrollBar.Value;
            var size         = new Size(ClientSize.Width, _rowHeight);
            var stringFormat = new StringFormat {
                Alignment = StringAlignment.Center
            };

            // Caption background
            var rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * _rowHeight);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            // Print the journal caption
            string stringCaptionText = Language.T("Journal by Positions") +
                                       (ShowTransfers ? "" : " " + Language.T("without Transfers")) +
                                       (Configs.AccountInMoney
                                            ? " [" + Configs.AccountCurrency + "]"
                                            : " [" + Language.T("pips") + "]");

            g.DrawString(stringCaptionText, _font, _brushCaptionText, new RectangleF(Point.Empty, size), stringFormat);
            g.SetClip(new RectangleF(Border, _rowHeight, ClientSize.Width - 2 * Border, _rowHeight));
            if (Configs.AccountInMoney)
            {
                g.DrawString(_titlesInMoney[0], _font, _brushCaptionText, scrll + (_scaledX[0] + _scaledX[1]) / 2,
                             _rowHeight, stringFormat);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_titlesInMoney[i], _font, _brushCaptionText, scrll + (_scaledX[i] + _scaledX[i + 1]) / 2,
                                 _rowHeight, stringFormat);
                }
            }
            else
            {
                g.DrawString(_titlesInPips[0], _font, _brushCaptionText, scrll + (_scaledX[0] + _scaledX[1]) / 2,
                             _rowHeight, stringFormat);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_titlesInPips[i], _font, _brushCaptionText, scrll + (_scaledX[i] + _scaledX[i + 1]) / 2,
                                 _rowHeight, stringFormat);
                }
            }
            g.ResetClip();

            // Paints the journal's data field
            var rectField = new RectangleF(Border, 2 * _rowHeight, ClientSize.Width - 2 * Border,
                                           ClientSize.Height - 2 * _rowHeight - Border);

            g.FillRectangle(new SolidBrush(_colorBack), rectField);

            size = new Size(ClientSize.Width - _vScrollBar.Width - 2 * Border, _rowHeight);

            // Prints the journal data
            for (int pos = _firstPos; pos < _firstPos + _shownPos; pos++)
            {
                int y     = (pos - _firstPos + 2) * _rowHeight;
                var point = new Point(Border, y);

                // Even row
                if (Math.Abs((pos - _firstPos) % 2f - 0) > 0.0001)
                {
                    g.FillRectangle(_brushEvenRowBack, new Rectangle(point, size));
                }

                // Warning row
                bool isWarning = false;
                if (_journalData[pos - _firstPos, _columns - 1] == Language.T("Ambiguous"))
                {
                    g.FillRectangle(_brushWarningBack, new Rectangle(point, size));
                    isWarning = true;
                }

                // Selected row
                Brush brush;
                if (pos - _firstPos == _selectedRow)
                {
                    g.FillRectangle(_brushSelectedRowBack, new Rectangle(point, size));
                    brush = _brushSelectedRowText;
                }
                else
                {
                    brush = isWarning ? _brushWarningText : _brushRowText;
                }

                // Draw the position icon
                int iImgY = y + (int)Math.Floor((_rowHeight - 16) / 2.0);
                g.DrawImage(_posIcons[pos - _firstPos], scrll + 2, iImgY, 16, 16);

                // Prints the data
                g.DrawString(_journalData[pos - _firstPos, 0], _font, brush, scrll + (16 + _scaledX[1]) / 2,
                             (pos - _firstPos + 2) * _rowHeight, stringFormat);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_journalData[pos - _firstPos, i], _font, brush,
                                 scrll + (_scaledX[i] + _scaledX[i + 1]) / 2, (pos - _firstPos + 2) * _rowHeight,
                                 stringFormat);
                }
            }

            //g.DrawLine(penLines, 0, iRowHeight, ClientSize.Width, iRowHeight);
            for (int i = 1; i < _columns; i++)
            {
                g.DrawLine(_penLines, _scaledX[i] + scrll, 2 * _rowHeight, _scaledX[i] + scrll, 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);

            OnSelectedBarChange(new EventArgs());
        }
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            int   iHScrll  = -hScrollBar.Value;
            bool  bWarning = false;
            Brush brush    = Brushes.Red;
            Size  size     = new Size(ClientSize.Width - vScrollBar.Width, rowHeight);

            StringFormat sf = new StringFormat();

            sf.Alignment = StringAlignment.Center;

            // Caption background
            RectangleF rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * rowHeight);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            // Print the journal caption
            string unit    = Configs.AccountInMoney ? " [" + Configs.AccountCurrency + "]" : " [" + Language.T("pips") + "]";
            string accUnit = " [" + Configs.AccountCurrency + "]";

            g.SetClip(new RectangleF(border, 0, ClientSize.Width - 2 * border, 2 * rowHeight));
            g.DrawString(Language.T("Market Data"), font, brushCaptionText, iHScrll + (aiX[8] + aiX[0]) / 2, 0, sf);
            g.DrawString(Language.T("Summary") + unit, font, brushCaptionText, iHScrll + (aiX[14] + aiX[8]) / 2, 0, sf);
            g.DrawString(Language.T("Account") + unit, font, brushCaptionText, iHScrll + (aiX[16] + aiX[14]) / 2, 0, sf);
            g.DrawString(Language.T("Margin") + accUnit, font, brushCaptionText, iHScrll + (aiX[18] + aiX[16]) / 2, 0, sf);
            g.DrawString(Language.T("Backtest"), font, brushCaptionText, iHScrll + (aiX[19] + aiX[18]) / 2, 0, sf);
            if (Configs.AccountInMoney)
            {
                for (int i = 0; i < columns; i++)
                {
                    g.DrawString(asTitlesMoney[i], font, brushCaptionText, iHScrll + (aiX[i] + aiX[i + 1]) / 2, rowHeight, sf);
                }
            }
            else
            {
                for (int i = 0; i < columns; i++)
                {
                    g.DrawString(asTitlesPips[i], font, brushCaptionText, iHScrll + (aiX[i] + aiX[i + 1]) / 2, rowHeight, sf);
                }
            }
            g.ResetClip();

            RectangleF 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 bar = firstBar; bar < firstBar + shownBars; bar++)
            {
                int   y     = (bar - firstBar + 2) * rowHeight;
                Point point = new Point(border, y);

                // Even row
                if ((bar - firstBar) % 2f != 0)
                {
                    g.FillRectangle(brushEvenRowBack, new Rectangle(point, size));
                }

                // Warning row
                if (asJournalData[bar - firstBar, columns - 1] == Language.T("Ambiguous"))
                {
                    g.FillRectangle(brushWarningBack, new Rectangle(point, size));
                    bWarning = true;
                }
                else
                {
                    bWarning = false;
                }

                // Selected row
                if (bar - firstBar == selectedRow)
                {
                    g.FillRectangle(brushSelectedRowBack, new Rectangle(point, size));
                    brush = brushSelectedRowText;
                }
                else
                {
                    brush = bWarning ? brushWarningText : brushRowText;
                }

                // Draw the position icon
                int imgY = y + (int)Math.Floor((rowHeight - 16) / 2.0);
                g.DrawImage(aiPositionIcons[bar - firstBar], iHScrll + 2, imgY, 16, 16);

                // Prints the data
                g.DrawString(asJournalData[bar - firstBar, 0], font, brush, iHScrll + (16 + aiX[1]) / 2, (bar - firstBar + 2) * rowHeight, sf);
                for (int i = 1; i < columns; i++)
                {
                    g.DrawString(asJournalData[bar - firstBar, i], font, brush, iHScrll + (aiX[i] + aiX[i + 1]) / 2, (bar - firstBar + 2) * rowHeight, sf);
                }
            }

            // Horizontal line in the title
            //g.DrawLine(penLines, 0, iRowHeight, ClientSize.Width, iRowHeight);

            // Vertical lines
            for (int i = 1; i < columns; i++)
            {
                if (i == 8 || i == 14 || i == 16 || i == 18)
                {
                    RectangleF rectfSeparator = new RectangleF(aiX[i] + iHScrll, rowHeight / 2, 1, 3 * rowHeight / 2);
                    Data.GradientPaint(g, rectfSeparator, LayoutColors.ColorCaptionBack, -2 * LayoutColors.DepthCaption);
                    g.DrawLine(penLines, aiX[i] + iHScrll, 2 * rowHeight, aiX[i] + iHScrll, ClientSize.Height);
                }
                else
                {
                    g.DrawLine(penLines, aiX[i] + iHScrll, 2 * rowHeight, aiX[i] + iHScrll, 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);

            OnSelectedBarChange(new EventArgs());

            return;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption background
            var rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * _rowHeight);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            int hScrll = -HScrollBar.Value;
            //var size = new Size(ContextButtonLocation.X, _rowHeight);
            var size = new Size(ClientSize.Width, _rowHeight);
            var sf   = new StringFormat {
                Alignment = StringAlignment.Center
            };

            // Print the journal caption
            string stringCaptionText = Language.T("Orders During the Bar") +
                                       (Configs.AccountInMoney
                                            ? " [" + Configs.AccountCurrency + "]"
                                            : " [" + Language.T("pips") + "]");

            g.DrawString(stringCaptionText, _font, _brushCaptionText, new RectangleF(Point.Empty, size), sf);
            g.SetClip(new RectangleF(Border, _rowHeight, ClientSize.Width - 2 * Border, _rowHeight));
            if (Configs.AccountInMoney)
            {
                for (int i = 0; i < _columns; i++)
                {
                    g.DrawString(_titlesMoney[i], _font, _brushCaptionText, hScrll + (_xScaled[i] + _xScaled[i + 1]) / 2,
                                 _rowHeight, sf);
                }
            }
            else
            {
                for (int i = 0; i < _columns; i++)
                {
                    g.DrawString(_titlesPips[i], _font, _brushCaptionText, hScrll + (_xScaled[i] + _xScaled[i + 1]) / 2,
                                 _rowHeight, sf);
                }
            }
            g.ResetClip();

            // Paints the journal's data field
            var rectField = new RectangleF(Border, 2 * _rowHeight, ClientSize.Width - 2 * Border,
                                           ClientSize.Height - 2 * _rowHeight - Border);

            g.FillRectangle(new SolidBrush(_colorBack), rectField);

            size = new Size(ClientSize.Width - VScrollBar.Width - 2 * Border, _rowHeight);

            // Prints the journal data
            for (int ord = _firstOrd; ord < _firstOrd + _shownOrd; ord++)
            {
                int row = ord - _firstOrd;
                if (_journalData == null || _journalData[row, 0] == null)
                {
                    Console.WriteLine("Break");
                    break;
                }

                int y     = (row + 2) * _rowHeight;
                var point = new Point(Border, y);

                // Even row
                if (Math.Abs(row % 2f - 0) > 0.0001)
                {
                    g.FillRectangle(_brushEvenRowBack, new Rectangle(point, size));
                }

                // Draw the position icon
                int iImgY = y + (int)Math.Floor((_rowHeight - 16) / 2.0);
                g.DrawImage(_orderIcons[row], hScrll + 2, iImgY, 16, 16);

                // Prints the data
                g.DrawString(_journalData[row, 0], _font, _brushRowText, hScrll + (16 + _xScaled[1]) / 2,
                             (row + 2) * _rowHeight, sf);
                for (int i = 1; i < _columns; i++)
                {
                    if (i == _columns - 1)
                    {
                        g.DrawString(_journalData[row, i], _font, _brushRowText, hScrll + _xScaled[i],
                                     (row + 2) * _rowHeight);
                    }
                    else
                    {
                        g.DrawString(_journalData[row, i], _font, _brushRowText,
                                     hScrll + (_xScaled[i] + _xScaled[i + 1]) / 2, (row + 2) * _rowHeight, sf);
                    }
                }
            }

            for (int i = 1; i < _columns; i++)
            {
                g.DrawLine(_penLines, _xScaled[i] + hScrll, 2 * _rowHeight, _xScaled[i] + hScrll, 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);
        }
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption bar
            Data.GradientPaint(g, _rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(_chartTitle, Font, new SolidBrush(LayoutColors.ColorCaptionText), _rectfCaption, _stringFormatCaption);

            // Border
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1, ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);

            // Paints the background by gradient
            var rectChartField = new RectangleF(Border, _captionHeight, ClientSize.Width - 2 * Border, ClientSize.Height - _captionHeight - Border);

            Data.GradientPaint(g, rectChartField, LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            if (_isNotPaint)
            {
                return;
            }

            // Grid and Price labels
            for (int labelPrice = _data.Minimum; labelPrice <= _data.Minimum + _countLabels * _labelStep; labelPrice += _labelStep)
            {
                var labelY = (int)(_yBottom - (labelPrice - _data.Minimum) * _yScale);
                g.DrawString(labelPrice.ToString(CultureInfo.InvariantCulture), Font, _brushFore, _xRight,
                             labelY - Font.Height / 2 - 1);
                g.DrawLine(_penGrid, _xLeft, labelY, _xRight, labelY);
            }

            // Price close
            if (_showPriceLine)
            {
                g.DrawLines(new Pen(LayoutColors.ColorChartGrid), _closePricePoints);
            }

            // Equity line
            g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), _equityPoints);

            // Draw Long and Short balance
            if (Configs.AdditionalStatistics)
            {
                g.DrawLines(new Pen(Color.Red), _shortBalancePoints);
                g.DrawLines(new Pen(Color.Green), _longBalancePoints);
            }

            // Out of Sample
            if (IsOOS && OOSBar > 0)
            {
                g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xOOSBar, _yTop, _xOOSBar, _yBottom);
                Brush brushOOS = new Pen(LayoutColors.ColorChartFore).Brush;
                g.DrawString("OOS", Font, brushOOS, _xOOSBar, _yBottom - Font.Height);
                float widthOOSBarDate = g.MeasureString(_data.DataTimeBarOOS.ToShortDateString(), Font).Width;
                g.DrawString(_data.DataTimeBarOOS.ToShortDateString(), Font, brushOOS, _xOOSBar - widthOOSBarDate, _yBottom - Font.Height);
            }

            // Draw Balance Line
            if (_data.MarginCallBar > 0) // In case of Margin Call
            {
                // Draw balance line up to Margin Call
                var balancePoints = new PointF[_data.MarginCallBar - _data.FirstBar];
                for (int i = 0; i < balancePoints.Length; i++)
                {
                    balancePoints[i] = _balancePoints[i];
                }
                if (balancePoints.Length > 1)
                {
                    g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), balancePoints);
                }

                // Draw balance line after Margin Call
                var redBalancePoints = new PointF[_data.Bars - _data.MarginCallBar];
                for (int i = 0; i < redBalancePoints.Length; i++)
                {
                    redBalancePoints[i] = _balancePoints[i + _data.MarginCallBar - _data.FirstBar];
                }
                g.DrawLines(new Pen(LayoutColors.ColorSignalRed), redBalancePoints);

                // Margin Call line
                g.DrawLine(new Pen(LayoutColors.ColorChartCross), _xMarginCallBar, _yTop, _xMarginCallBar, _yBottom);

                // Margin Call label
                float widthMarginCallLabel = g.MeasureString(Language.T("Margin Call"), Font).Width;
                if (_xMarginCallBar < _xRight - widthMarginCallLabel)
                {
                    g.DrawString(Language.T("Margin Call"), Font, _brushFore, _xMarginCallBar, _yTop);
                }
                else if (_xMarginCallBar > Space + widthMarginCallLabel)
                {
                    g.DrawString(Language.T("Margin Call"), Font, _brushFore, _xMarginCallBar - widthMarginCallLabel, _yTop);
                }
                else
                {
                    g.DrawString("MC", Font, _brushFore, _xMarginCallBar, _yTop);
                }
            }
            else
            {
                // Draw the balance line
                g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), _balancePoints);
            }

            // Scanning note
            var fontNote = new Font(Font.FontFamily, Font.Size - 1);

            if (Data.Period != DataPeriods.min1 && Configs.Autoscan && !Data.IsIntrabarData)
            {
                g.DrawString(Language.T("Load intrabar data"), fontNote, Brushes.Red, _xLeft, _captionHeight - 2);
            }
            else if (Data.Period != DataPeriods.min1 && _isScanPerformed)
            {
                g.DrawString(Language.T("Scanned") + _data.ModellingQuolity, fontNote, Brushes.LimeGreen, _xLeft, _captionHeight - 2);
            }

            // Scanned bars
            if (_isScanPerformed && !_isHideScanningLine &&
                (Data.IntraBars != null && Data.IsIntrabarData ||
                 Data.Period == DataPeriods.min1 && Data.IsTickData && Configs.UseTickData))
            {
                DataPeriods dataPeriod = Data.Period;
                Color       color      = Data.PeriodColor[Data.Period];
                int         fromBar    = _data.FirstBar;
                for (int bar = _data.FirstBar; bar < _data.Bars; bar++)
                {
                    if (Data.IntraBarsPeriods[bar] == dataPeriod && bar != _data.Bars - 1)
                    {
                        continue;
                    }
                    int xStart = (int)((fromBar - _data.FirstBar) * _xScale) + _xLeft;
                    int xEnd   = (int)((bar - _data.FirstBar) * _xScale) + _xLeft;
                    fromBar    = bar;
                    dataPeriod = Data.IntraBarsPeriods[bar];
                    Data.GradientPaint(g, new RectangleF(xStart, _yBottom + 4, xEnd - xStart + 2, 5), color, 60);
                    color = Data.PeriodColor[Data.IntraBarsPeriods[bar]];
                }

                // Tick Data
                if (Data.IsTickData && Configs.UseTickData)
                {
                    int firstBarWithTicks = -1;
                    int lastBarWithTicks  = -1;
                    for (int b = 0; b < _data.Bars; b++)
                    {
                        if (firstBarWithTicks == -1 && Data.TickData[b] != null)
                        {
                            firstBarWithTicks = b;
                        }
                        if (Data.TickData[b] != null)
                        {
                            lastBarWithTicks = b;
                        }
                    }
                    int xStart = (int)((firstBarWithTicks - _data.FirstBar) * _xScale) + _xLeft;
                    int xEnd   = (int)((lastBarWithTicks - _data.FirstBar) * _xScale) + _xLeft;
                    Data.GradientPaint(g, new RectangleF(xStart, _yBottom + 4, xEnd - xStart + 2, 5), color, 60);

                    var rectf = new RectangleF(xStart, _yBottom + 4, xEnd - xStart + 2, 5);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.min1], 60);
                    rectf = new RectangleF(xStart, _yBottom + 6, xEnd - xStart + 2, 1);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.day], 60);
                }

                // Vertical coordinate axes
                g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xLeft - 1, _yBottom, _xLeft - 1, _yBottom + 9);
            }

            // Coordinate axes
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xLeft - 1, _yTop - Space, _xLeft - 1, _yBottom + 1);
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xLeft - 1, _yBottom + 1, _xRight, _yBottom + 1);

            // Balance level
            g.DrawLine(new Pen(LayoutColors.ColorChartCross), _xLeft, _yBalance, _xRight - Space + 1, _yBalance);

            // Balance label
            var labelSize  = new Size(_labelWidth + Space, Font.Height + 2);
            var labelPoint = new Point(_xRight - Space + 2, (int)(_yBalance - Font.Height / 2.0 - 1));
            var labelRect  = new Rectangle(labelPoint, labelSize);

            g.FillRectangle(new SolidBrush(LayoutColors.ColorLabelBack), labelRect);
            g.DrawRectangle(new Pen(LayoutColors.ColorChartCross), labelRect);
            g.DrawString((Math.Round(_data.NetBalance)).ToString(CultureInfo.InvariantCulture), Font,
                         new SolidBrush(LayoutColors.ColorLabelText), labelRect, _stringFormatCaption);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Paints panel pnlInfo
        /// </summary>
        void PnlInfo_Paint(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;
            }

            Panel  pnl   = (Panel)sender;
            Brush  brush = Brushes.White;
            string FF    = Data.FF;   // Format modifier to print the floats

            Size size = new Size(aiX[columns] - aiX[0], infoRowHeight);

            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Near;

            // Caption background
            PointF     pntStart     = new PointF(0, 0);
            SizeF      szfCaption   = new Size(pnl.ClientSize.Width, 2 * infoRowHeight);
            RectangleF rectfCaption = new RectangleF(pntStart, szfCaption);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            // Caption Text
            StringFormat stringFormatCaption = new StringFormat();

            stringFormatCaption.LineAlignment = StringAlignment.Center;
            stringFormatCaption.Trimming      = StringTrimming.EllipsisCharacter;
            stringFormatCaption.FormatFlags   = StringFormatFlags.NoWrap;
            stringFormatCaption.Alignment     = StringAlignment.Near;
            string stringCaptionText = Language.T("Way Points Description");
            float  fCaptionWidth     = (float)Math.Min(pnlInfo.ClientSize.Width, aiX[columns] - aiX[0]);
            float  fCaptionTextWidth = g.MeasureString(stringCaptionText, fontInfo).Width;
            float  fCaptionTextX     = (float)Math.Max((fCaptionWidth - fCaptionTextWidth) / 2f, 0);
            PointF pfCaptionText     = new PointF(fCaptionTextX, 0);
            SizeF  sfCaptionText     = new SizeF(fCaptionWidth - fCaptionTextX, infoRowHeight);

            rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);

            // First caption raw
            g.DrawString(stringCaptionText, fontInfo, brushCaptionText, rectfCaption, stringFormatCaption);

            // Second caption raw
            for (int i = 0; i < columns; i++)
            {
                g.DrawString(asTitles[i], fontInfo, brushCaptionText, (aiX[i] + aiX[i + 1]) / 2, infoRowHeight, sf);
            }

            brush = new SolidBrush(LayoutColors.ColorControlText);

            for (int pnt = 0; pnt < Backtester.WayPoints(bar); pnt++)
            {
                int   y     = (pnt + 2) * infoRowHeight;
                Point point = new Point(aiX[0], y);

                // Even row
                if (pnt % 2f != 0)
                {
                    g.FillRectangle(brushEvenRow, new Rectangle(point, size));
                }

                int          positionNumber = Backtester.WayPoint(bar, pnt).PosNumb;
                WayPointType wpType         = Backtester.WayPoint(bar, pnt).WPType;
                PosDirection posDirection   = Backtester.PosFromNumb(positionNumber).PosDir;
                double       posLots        = Backtester.PosFromNumb(positionNumber).PosLots;
                int          ordNumber      = Backtester.WayPoint(bar, pnt).OrdNumb;

                g.DrawString((pnt + 1).ToString(), fontInfo, brush, (aiX[0] + aiX[1]) / 2, y, sf);
                g.DrawString(Language.T(Way_Point.WPTypeToString(wpType)), fontInfo, brush, aiX[1] + 2, y);
                g.DrawString(Backtester.WayPoint(bar, pnt).Price.ToString(FF), fontInfo, brush, (aiX[3] + aiX[2]) / 2, y, sf);

                if (positionNumber > -1)
                {
                    g.DrawString(Language.T(posDirection.ToString()), fontInfo, brush, (aiX[4] + aiX[3]) / 2, y, sf);
                    g.DrawString(posLots.ToString(), fontInfo, brush, (aiX[5] + aiX[4]) / 2, y, sf);
                    g.DrawString((positionNumber + 1).ToString(), fontInfo, brush, (aiX[6] + aiX[5]) / 2, y, sf);
                }

                if (ordNumber > -1)
                {
                    g.DrawString((ordNumber + 1).ToString(), fontInfo, brush, (aiX[7] + aiX[6]) / 2, y, sf);
                }
            }

            // Vertical lines
            Pen 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
            Pen 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);

            return;
        }
Exemplo n.º 19
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   rectfCaption = new RectangleF(pntStart, szfCaption);

            Data.GradientPaint(g, rectfCaption, 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);

            rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);

            // First caption raw
            g.DrawString(stringCaptionText, _fontInfo, _brushCaptionText, rectfCaption, 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);
        }
Exemplo n.º 20
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 rectfCaption = new RectangleF(0, 0, captionWidth, captionHeight);

            Data.GradientPaint(g, rectfCaption, 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);
                rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);
                stringFormatCaption.Alignment = StringAlignment.Near;
            }
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, 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 rectfPanel = new RectangleF(Border, captionHeight, pnl.Width - 2 * Border,
                                            pnl.Height - captionHeight - Border);

            Data.GradientPaint(g, rectfPanel, 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    sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(caption, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(value, fontValue, brushValue, rectfValue, 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    sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(caption, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(value, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height;
            }

            // Check Parameters
            foreach (CheckParam checkParam in _strategy.Slot[slot].IndParam.CheckParam)
            {
                if (!checkParam.Enabled)
                {
                    continue;
                }

                string param      = checkParam.Caption;
                string salue      = 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    sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(param, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(salue, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height;
            }
        }
Exemplo n.º 21
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   rectfCaption = new RectangleF(pntStart, szfCaption);

            Data.GradientPaint(g, rectfCaption, 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");

            rectfCaption = new RectangleF(Border, 0, pnl.ClientSize.Width - 2 * Border, _infoRowHeight);
            g.DrawString(stringCaptionText, _fontInfo, _brushCaptionText, rectfCaption, 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 hight  = (int)(Math.Max(posLots * 2, 2));
                int lenght = barPixels;
                int posX   = pntWay[point].X - (barPixels - 1) / 2;
                int posY   = yBottom - hight;

                if (point < points - 1)
                {
                    lenght = pntWay[point + 1].X - pntWay[point].X + 1;
                }

                if (posDirection == PosDirection.Long)
                {
                    // Long
                    var rect    = new Rectangle(posX - 1, posY - 1, lenght, hight + 2);
                    var lgBrush = new LinearGradientBrush(rect, _colorLongTrade1, _colorLongTrade2,
                                                          LinearGradientMode.Vertical);
                    rect = new Rectangle(posX - 1, posY, lenght, hight);
                    g.FillRectangle(lgBrush, rect);
                }
                else if (posDirection == PosDirection.Short)
                {
                    // Short
                    var rect    = new Rectangle(posX - 1, posY - 1, lenght, hight + 2);
                    var lgBrush = new LinearGradientBrush(rect, _colorShortTrade1, _colorShortTrade2,
                                                          LinearGradientMode.Vertical);
                    rect = new Rectangle(posX - 1, posY, lenght, hight);
                    g.FillRectangle(lgBrush, rect);
                }
                else if (posDirection == PosDirection.Closed && wpType == WayPointType.Exit)
                {
                    // Closed
                    var rect    = new Rectangle(posX - 1, yBottom - 2, barPixels + 1, 2);
                    var lgBrush = new LinearGradientBrush(rect, _colorClosedTrade1, _colorClosedTrade2,
                                                          LinearGradientMode.Vertical);
                    rect = new Rectangle(posX, yBottom - 2, barPixels - 1, 2);
                    g.FillRectangle(lgBrush, rect);
                }
            }

            // Draw the Beziers
            for (int point = 1; point < points; point++)
            {
                Point ptKnot1 = pntWay[point - 1];
                Point ptKnot2 = pntWay[point];

                int ctrlX1 = (ptKnot1.X + ptKnot2.X) / 2;
                int ctrlX2 = (ptKnot1.X + ptKnot2.X) / 2;

                int ctrlY1 = ptKnot1.Y;
                int ctrlY2 = ptKnot2.Y;

                if (point > 1)
                {
                    if (pntWay[point - 2].Y > pntWay[point - 1].Y && pntWay[point - 1].Y > pntWay[point].Y ||
                        pntWay[point - 2].Y < pntWay[point - 1].Y && pntWay[point - 1].Y < pntWay[point].Y)
                    {
                        ctrlY1 = (pntWay[point - 1].Y + pntWay[point].Y) / 2;
                    }
                }
                if (point < points - 1)
                {
                    if (pntWay[point - 1].Y > pntWay[point].Y && pntWay[point].Y > pntWay[point + 1].Y ||
                        pntWay[point - 1].Y < pntWay[point].Y && pntWay[point].Y < pntWay[point + 1].Y)
                    {
                        ctrlY2 = (pntWay[point - 1].Y + pntWay[point].Y) / 2;
                    }
                }

                if (point == 1)
                {
                    ctrlX1 = ptKnot1.X;
                    ctrlY1 = ptKnot1.Y;
                }
                if (point == points - 1)
                {
                    ctrlX2 = ptKnot2.X;
                    ctrlY2 = ptKnot2.Y;
                }

                var ptControl1 = new Point(ctrlX1, ctrlY1);
                var ptControl2 = new Point(ctrlX2, ctrlY2);

                g.DrawBezier(_penCross, ptKnot1, ptControl1, ptControl2, ptKnot2);
            }

            // Draw the WayPoints
            Brush brushWeyPnt = new SolidBrush(LayoutColors.ColorChartBack);

            for (int point = 0; point < points; point++)
            {
                g.FillEllipse(brushWeyPnt, pntWay[point].X - pointRadius, pntWay[point].Y - pointRadius, 2 * pointRadius,
                              2 * pointRadius);
                g.DrawEllipse(_penCross, pntWay[point].X - pointRadius, pntWay[point].Y - pointRadius, 2 * pointRadius,
                              2 * pointRadius);
            }

            // Draw O, H, L, C labels
            for (int point = 0; point < points; point++)
            {
                WayPointType wpType = Backtester.WayPoint(_barCurrent, point).WPType;
                if (wpType != WayPointType.Open && wpType != WayPointType.High &&
                    wpType != WayPointType.Low && wpType != WayPointType.Close)
                {
                    continue;
                }

                string label = "?";
                switch (wpType)
                {
                case WayPointType.Open:
                    label = "O";
                    break;

                case WayPointType.High:
                    label = "H";
                    break;

                case WayPointType.Low:
                    label = "L";
                    break;

                case WayPointType.Close:
                    label = "C";
                    break;
                }

                int xPoint = pntWay[point].X;
                int yPoint = pntWay[point].Y - Font.Height - 3;

                var stringFormatLabel = new StringFormat {
                    Alignment = StringAlignment.Center
                };
                g.DrawString(label, Font, _brushGridText, xPoint, yPoint, stringFormatLabel);
            }

            // Draw the deals on the route
            for (int point = 0; point < points; point++)
            {
                int posNumber = Backtester.WayPoint(_barCurrent, point).PosNumb;
                int ordNumber = Backtester.WayPoint(_barCurrent, point).OrdNumb;

                if (posNumber < 0 || ordNumber < 0)
                {
                    continue;
                }

                PosDirection   posDirection = Backtester.PosFromNumb(posNumber).PosDir;
                OrderDirection ordDirection = Backtester.OrdFromNumb(ordNumber).OrdDir;
                WayPointType   wpType       = Backtester.WayPoint(_barCurrent, point).WPType;

                if (wpType == WayPointType.None || wpType == WayPointType.Open || wpType == WayPointType.High ||
                    wpType == WayPointType.Low || wpType == WayPointType.Close)
                {
                    continue;
                }

                int yDeal = pntWay[point].Y;

                if (posDirection == PosDirection.Long || posDirection == PosDirection.Short ||
                    wpType == WayPointType.Cancel)
                {
                    int d = barPixels / 2 - 1;
                    x = pntWay[point].X - d;
                    int x1 = pntWay[point].X;
                    int x2 = x + barPixels - 2;
                    if (ordDirection == OrderDirection.Buy)
                    {
                        // Buy
                        var pen = new Pen(LayoutColors.ColorTradeLong, 2);
                        if (wpType == WayPointType.Cancel)
                        {
                            pen = new Pen(LayoutColors.ColorChartGrid, 2);
                        }
                        g.DrawLine(pen, x, yDeal, x1, yDeal);
                        g.DrawLine(pen, x1, yDeal, x2, yDeal - d);
                        g.DrawLine(pen, x2 + 1, yDeal - d + 1, x1 + d / 2 + 1, yDeal - d + 1);
                        g.DrawLine(pen, x2, yDeal - d, x2, yDeal - d / 2);
                    }
                    else
                    {
                        // Sell
                        var pen = new Pen(LayoutColors.ColorTradeShort, 2);
                        if (wpType == WayPointType.Cancel)
                        {
                            pen = new Pen(LayoutColors.ColorChartGrid, 2);
                        }
                        g.DrawLine(pen, x, yDeal + 1, x1 + 1, yDeal + 1);
                        g.DrawLine(pen, x1, yDeal, x2, yDeal + d);
                        g.DrawLine(pen, x1 + d / 2 + 1, yDeal + d, x2, yDeal + d);
                        g.DrawLine(pen, x2, yDeal + d, x2, yDeal + d / 2 + 1);
                    }
                }

                if (posDirection == PosDirection.Closed)
                {
                    // Close position
                    int d = barPixels / 2 - 1;
                    x = pntWay[point].X - d;
                    int x1  = pntWay[point].X;
                    int x2  = x + barPixels - 3;
                    var pen = new Pen(LayoutColors.ColorTradeClose, 2);
                    g.DrawLine(pen, x, yDeal, x1, yDeal);
                    g.DrawLine(pen, x1, yDeal + d / 2, x2, yDeal - d / 2);
                    g.DrawLine(pen, x1, yDeal - d / 2, x2, yDeal + d / 2);
                }
            }

            // Coordinate axes
            g.DrawLine(_penAxes, xLeft, yTop - 4, xLeft, yBottom); // Vertical left line
            g.DrawLine(_penAxes, xLeft, yBottom, xRight, yBottom);

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

            g.DrawLine(penBorder, 1, _infoRowHeight, 1, pnl.ClientSize.Height);
            g.DrawLine(penBorder, pnl.ClientSize.Width - Border + 1, _infoRowHeight, pnl.ClientSize.Width - Border + 1,
                       pnl.ClientSize.Height);
            g.DrawLine(penBorder, 0, pnl.ClientSize.Height - Border + 1, pnl.ClientSize.Width,
                       pnl.ClientSize.Height - Border + 1);
        }
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            int hScrll = -HScrollBar.Value;
            var size   = new Size(_visibalWidth, _rowHeight);
            var sf     = new StringFormat {
                Alignment = StringAlignment.Center
            };

            // Caption background
            var rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * _rowHeight);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            var 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("pips") + "]");

            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, hScrll + (_xScaled[i] + _xScaled[i + 1]) / 2, _rowHeight, sf);
                }
            }
            else
            {
                for (int i = 0; i < _columns; i++)
                {
                    g.DrawString(_titlesPips[i], font, brushCaptionText, hScrll + (_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], hScrll + 2, iImgY, 16, 16);

                // Prints the data
                g.DrawString(_journalData[row, 0], font, brushRowText, hScrll + (16 + _xScaled[1]) / 2, (row + 2) * _rowHeight, sf);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_journalData[row, i], font, brushRowText, hScrll + (_xScaled[i] + _xScaled[i + 1]) / 2, (row + 2) * _rowHeight, sf);
                }
            }

            for (int i = 1; i < _columns; i++)
            {
                g.DrawLine(penLines, _xScaled[i] + hScrll, 2 * _rowHeight, _xScaled[i] + hScrll, 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);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption bar
            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(strChartTitle, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectfCaption, stringFormatCaption);

            // Border
            g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height);
            g.DrawLine(penBorder, ClientSize.Width - border + 1, captionHeight, ClientSize.Width - border + 1, ClientSize.Height);
            g.DrawLine(penBorder, 0, ClientSize.Height - border + 1, ClientSize.Width, ClientSize.Height - border + 1);

            // Paints the background by gradient
            RectangleF rectField = new RectangleF(border, captionHeight, ClientSize.Width - 2 * border, ClientSize.Height - captionHeight - border);

            Data.GradientPaint(g, rectField, LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            if (isNotPaint)
            {
                return;
            }

            // Grid and Price labels
            for (int label = minimum; label <= maximum; label += step)
            {
                int labelY = (int)(YBottom - (label - minimum) * YScale);
                g.DrawString(label.ToString(), Font, brushFore, XRight, labelY - Font.Height / 2 - 1);
                g.DrawLine(penGrid, XLeft, labelY, XRight, labelY);
            }

            // Price close
            if (showPriceLine)
            {
                g.DrawLines(new Pen(LayoutColors.ColorChartGrid), apntClosePrice);
            }

            // Equity line
            g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), apntEquity);

            // Draw Long and Short balance
            if (Configs.AdditionalStatistics)
            {
                g.DrawLines(new Pen(Color.Red), apntShortBalance);
                g.DrawLines(new Pen(Color.Green), apntLongBalance);
            }

            // Out of Sample
            if (isOOS && barOOS > 0)
            {
                g.DrawLine(new Pen(LayoutColors.ColorChartFore), XOOSBar, YTop, XOOSBar, YBottom);
                Brush brushOOS = new Pen(LayoutColors.ColorChartFore).Brush;
                g.DrawString("OOS", Font, brushOOS, XOOSBar, YBottom - Font.Height);
                float OOSBarDateWidth = g.MeasureString(dataTimeBarOOS.ToShortDateString(), Font).Width;
                g.DrawString(dataTimeBarOOS.ToShortDateString(), Font, brushOOS, XOOSBar - OOSBarDateWidth, YBottom - Font.Height);
            }

            // In case of Margin Call
            if (marginCallBar > 0)
            {
                PointF[] apntfGreenBalance = new PointF[marginCallBar - firstBar];
                for (int i = 0; i < apntfGreenBalance.Length; i++)
                {
                    apntfGreenBalance[i] = apntBalance[i];
                }

                PointF[] apntfRedBalance = new PointF[bars - marginCallBar];
                for (int i = 0; i < apntfRedBalance.Length; i++)
                {
                    apntfRedBalance[i] = apntBalance[i + marginCallBar - firstBar];
                }

                if (apntfGreenBalance.Length > 1)
                {
                    g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), apntfGreenBalance);
                }
                g.DrawLines(new Pen(LayoutColors.ColorSignalRed), apntfRedBalance);

                // Margin Call line
                g.DrawLine(new Pen(LayoutColors.ColorChartCross), XMarginCallBar, YTop, XMarginCallBar, YBottom);
                Brush brushBancrupcy   = new Pen(LayoutColors.ColorChartBalanceLine).Brush;
                float fMarginCallWidht = g.MeasureString(Language.T("Margin Call"), Font).Width;
                if (XMarginCallBar < XRight - fMarginCallWidht)
                {
                    g.DrawString(Language.T("Margin Call"), Font, brushFore, XMarginCallBar, YTop);
                }
                else if (XMarginCallBar > space + fMarginCallWidht)
                {
                    g.DrawString(Language.T("Margin Call"), Font, brushFore, XMarginCallBar - fMarginCallWidht, YTop);
                }
                else
                {
                    g.DrawString("MC", Font, brushFore, XMarginCallBar, YTop);
                }
            }
            else
            {   // Draw the balance line
                g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), apntBalance);
            }

            // Balance level
            g.DrawLine(new Pen(LayoutColors.ColorChartCross), XLeft, YBalance, XRight - space + 1, YBalance);

            // Scanning note
            Font fontNote = new Font(Font.FontFamily, Font.Size - 1);

            if (Data.Period != DataPeriods.min1 && Configs.Autoscan && !Data.IsIntrabarData)
            {
                g.DrawString(Language.T("Load intrabar data"), fontNote, Brushes.Red, XLeft, captionHeight - 2);
            }
            else if (Data.Period != DataPeriods.min1 && isScanPerformed)
            {
                g.DrawString(Language.T("Scanned") + modellingQuolity, fontNote, Brushes.LimeGreen, XLeft, captionHeight - 2);
            }

            // Scanned bars
            if (isScanPerformed && !isHideScanningLine &&
                (Data.IntraBars != null && Data.IsIntrabarData ||
                 Data.Period == DataPeriods.min1 && Data.IsTickData && Configs.UseTickData))
            {
                DataPeriods dataPeriod = Data.Period;
                Color       color      = Data.PeriodColor[Data.Period];
                int         fromBar    = firstBar;
                for (int bar = firstBar; bar < bars; bar++)
                {
                    if (Data.IntraBarsPeriods[bar] != dataPeriod || bar == bars - 1)
                    {
                        int xStart = (int)((fromBar - firstBar) * XScale) + XLeft;
                        int xEnd   = (int)((bar - firstBar) * XScale) + XLeft;
                        fromBar    = bar;
                        dataPeriod = Data.IntraBarsPeriods[bar];
                        Data.GradientPaint(g, new RectangleF(xStart, YBottom + 4, xEnd - xStart + 2, 5), color, 60);
                        color = Data.PeriodColor[Data.IntraBarsPeriods[bar]];
                    }
                }

                // Tick Data
                if (Data.IsTickData && Configs.UseTickData)
                {
                    int firstBarWithTicks = -1;
                    int lastBarWithTicks  = -1;
                    for (int b = 0; b < bars; b++)
                    {
                        if (firstBarWithTicks == -1 && Data.TickData[b] != null)
                        {
                            firstBarWithTicks = b;
                        }
                        if (Data.TickData[b] != null)
                        {
                            lastBarWithTicks = b;
                        }
                    }
                    int xStart = (int)((firstBarWithTicks - firstBar) * XScale) + XLeft;
                    int xEnd   = (int)((lastBarWithTicks - firstBar) * XScale) + XLeft;
                    Data.GradientPaint(g, new RectangleF(xStart, YBottom + 4, xEnd - xStart + 2, 5), color, 60);

                    RectangleF rectf = new RectangleF(xStart, YBottom + 4, xEnd - xStart + 2, 5);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.min1], 60);
                    rectf = new RectangleF(xStart, YBottom + 6, xEnd - xStart + 2, 1);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.day], 60);
                }

                // Vertical coordinate axes
                g.DrawLine(new Pen(LayoutColors.ColorChartFore), XLeft - 1, YBottom, XLeft - 1, YBottom + 9);
            }

            // Coordinate axes
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), XLeft - 1, YTop - space, XLeft - 1, YBottom + 1);
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), XLeft - 1, YBottom + 1, XRight, YBottom + 1);

            // Balance label
            Size      szBalance = new Size(labelWidth + space, Font.Height + 2);
            Point     point     = new Point(XRight - space + 2, (int)(YBalance - Font.Height / 2 - 1));
            Rectangle rec       = new Rectangle(point, szBalance);

            g.FillRectangle(new SolidBrush(LayoutColors.ColorLabelBack), rec);
            g.DrawRectangle(new Pen(LayoutColors.ColorChartCross), rec);
            g.DrawString((Math.Round(balance)).ToString(), Font, new SolidBrush(LayoutColors.ColorLabelText), rec, stringFormatCaption);

            return;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption background
            RectangleF rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * rowHeight);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            StringFormat sf = new StringFormat();

            sf.Alignment = StringAlignment.Center;
            int  iHScrll = -hScrollBar.Value;
            Size size    = new Size(btnToggleJournal.Left, rowHeight);

            // Print the journal caption
            string stringCaptionText = Language.T("Orders During the Bar") + (Configs.AccountInMoney ? " [" + Configs.AccountCurrency + "]" : " [" + Language.T("pips") + "]");

            g.DrawString(stringCaptionText, font, brushCaptionText, new RectangleF(Point.Empty, size), sf);
            g.SetClip(new RectangleF(border, rowHeight, ClientSize.Width - 2 * border, rowHeight));
            if (Configs.AccountInMoney)
            {
                for (int i = 0; i < columns; i++)
                {
                    g.DrawString(asTitlesMoney[i], font, brushCaptionText, iHScrll + (aiX[i] + aiX[i + 1]) / 2, rowHeight, sf);
                }
            }
            else
            {
                for (int i = 0; i < columns; i++)
                {
                    g.DrawString(asTitlesPips[i], font, brushCaptionText, iHScrll + (aiX[i] + aiX[i + 1]) / 2, rowHeight, sf);
                }
            }
            g.ResetClip();

            // Paints the journal's data field
            RectangleF rectField = new RectangleF(border, 2 * rowHeight, ClientSize.Width - 2 * border, ClientSize.Height - 2 * rowHeight - border);

            g.FillRectangle(new SolidBrush(colorBack), rectField);

            size = new Size(ClientSize.Width - vScrollBar.Width - 2 * border, rowHeight);

            // Prints the journal data
            for (int ord = firstOrd; ord < firstOrd + shownOrd; ord++)
            {
                int   row   = ord - firstOrd;
                int   y     = (row + 2) * rowHeight;
                Point point = new Point(border, y);

                // Even row
                if (row % 2f != 0)
                {
                    g.FillRectangle(brushEvenRowBack, new Rectangle(point, size));
                }

                // Draw the position icon
                int iImgY = y + (int)Math.Floor((rowHeight - 16) / 2.0);
                g.DrawImage(aiOrderIcons[row], iHScrll + 2, iImgY, 16, 16);

                // Prints the data
                g.DrawString(asJournalData[row, 0], font, brushRowText, iHScrll + (16 + aiX[1]) / 2, (row + 2) * rowHeight, sf);
                for (int i = 1; i < columns; i++)
                {
                    if (i == columns - 1)
                    {
                        g.DrawString(asJournalData[row, i], font, brushRowText, iHScrll + aiX[i], (row + 2) * rowHeight);
                    }
                    else
                    {
                        g.DrawString(asJournalData[row, i], font, brushRowText, iHScrll + (aiX[i] + aiX[i + 1]) / 2, (row + 2) * rowHeight, sf);
                    }
                }
            }

            //g.DrawLine(penLines, 0, iRowHeight, ClientSize.Width, iRowHeight);
            for (int i = 1; i < columns; i++)
            {
                g.DrawLine(penLines, aiX[i] + iHScrll, 2 * rowHeight, aiX[i] + iHScrll, 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);

            return;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            Data.GradientPaint(g, new Rectangle(border, (int)captionHeight, ClientSize.Width - 2 * border, ClientSize.Height - (int)captionHeight - border),
                               LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            // Panel caption
            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption);

            // Border
            g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height);
            g.DrawLine(penBorder, ClientSize.Width - border + 1, captionHeight, ClientSize.Width - border + 1, ClientSize.Height);
            g.DrawLine(penBorder, 0, ClientSize.Height - border + 1, ClientSize.Width, ClientSize.Height - border + 1);

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

            // Limits the drawing into the chart area only
            g.SetClip(new Rectangle(xLeft, yTop, xRight - xLeft, yPrcBottom - yTop));

            // Draws Volume, Lots and Price
            int index  = 0;
            Pen penBar = new Pen(LayoutColors.ColorBarBorder);

            for (bar = firstBar; bar <= lastBar; bar++)
            {
                // Draw the volume
                if (yVolume[index] != yPrcBottom)
                {
                    g.DrawLine(penVolume, x[index], yVolume[index], x[index], yPrcBottom - 1);
                }

                // Draw position lots
                if (rectPosition[index] != Rectangle.Empty)
                {
                    g.FillRectangle(brushPosition[index], rectPosition[index]);
                }

                // Draw the bar
                g.DrawLine(penBar, x[index], yLow[index], x[index], yHigh[index]);
                g.DrawLine(penBar, x[index], yClose[index], x[index] + 1, yClose[index]);
                index++;
            }

            // Drawing the indicators in the chart
            for (int slot = 0; slot < slots; slot++)
            {
                if (bIsSeparatedChart[slot])
                {
                    continue;
                }
                for (int iComp = 0; iComp < iComponentLenght[slot]; iComp++)
                {
                    if (chartType[slot][iComp] == IndChartType.Line)
                    {   // Line
                        g.DrawLines(new Pen(chartBrush[slot][iComp]), chartLine[slot][iComp]);
                    }
                    else if (chartType[slot][iComp] == IndChartType.Dot)
                    {   // Dots
                        for (bar = firstBar; bar <= lastBar; bar++)
                        {
                            g.FillRectangle(chartBrush[slot][iComp], chartDot[slot][iComp][bar - firstBar]);
                        }
                    }
                    else if (chartType[slot][iComp] == IndChartType.Level)
                    {   // Level
                        for (bar = firstBar; bar <= lastBar; bar++)
                        {
                            g.FillRectangle(chartBrush[slot][iComp], chartLevel[slot][iComp][bar - firstBar]);
                        }
                    }
                    else if (chartType[slot][iComp] == IndChartType.CloudUp)
                    {   // CloudUp
                        Pen pen = new Pen(chartBrush[slot][iComp]);
                        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                        g.DrawLines(pen, chartLine[slot][iComp]);
                    }
                    else if (chartType[slot][iComp] == IndChartType.CloudDown)
                    {   // CloudDown
                        Pen pen = new Pen(chartBrush[slot][iComp]);
                        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                        g.DrawLines(pen, chartLine[slot][iComp]);
                    }
                }
            }
            g.ResetClip();

            // Separate indicators
            for (int ind = 0; ind < inds; ind++)
            {
                int slot = aiIndSlot[ind];

                for (int comp = 0; comp < iComponentLenght[slot]; comp++)
                {
                    if (chartType[slot][comp] == IndChartType.Line)
                    {   // Line
                        g.DrawLines(new Pen(chartBrush[slot][comp]), chartLine[slot][comp]);
                    }
                    else if (chartType[slot][comp] == IndChartType.Histogram)
                    {   // Histogram
                        double zero = 0;
                        if (zero < dMinValue[ind])
                        {
                            zero = dMinValue[ind];
                        }
                        if (zero > dMaxValue[ind])
                        {
                            zero = dMaxValue[ind];
                        }
                        int y0 = (int)(yIndBottom[ind] - (zero - dMinValue[ind]) * dScale[ind]);
                        g.DrawLine(penDarkGray, xLeft, y0, xRight, y0);
                        for (bar = firstBar; bar <= lastBar; bar++)
                        {
                            double val = chartValue[slot][comp][bar - firstBar];
                            int    x   = (bar - firstBar) * barPixels + xLeft;
                            int    y   = (int)(yIndBottom[ind] - (val - dMinValue[ind]) * dScale[ind]);
                            g.DrawLine(chartPen[slot][comp][bar - firstBar], x, y0, x, y);
                        }
                    }
                }
            }

            // Lines
            for (int ind = 0; ind < inds; ind++)
            {
                int y = yBottom - (ind + 1) * indHeight;
                g.DrawLine(penFore, xLeft, y, xRight, y);
            }
            g.DrawLine(penFore, xLeft, yBottom, xRight, yBottom);
            g.DrawLine(penFore, xLeft, yTop, xLeft, yBottom);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption bar
            Data.GradientPaint(g, _rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(_strChartTitle, Font, new SolidBrush(LayoutColors.ColorCaptionText), _rectfCaption, _sfCaption);

            // Border
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1, ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);

            // Paints the background by gradient
            var rectField = new RectangleF(Border, _captionHeight, ClientSize.Width - 2 * Border, ClientSize.Height - _captionHeight - Border);

            Data.GradientPaint(g, rectField, LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            if (_isNotPaint)
            {
                return;
            }

            string subHeader = _isCounts ? Language.T("Count of Trades") : Language.T("Accumulated Amount");

            g.DrawString(subHeader, Font, new SolidBrush(LayoutColors.ColorChartFore), _rectSubHeader, _sfCaption);

            // Grid and Price labels
            for (int label = _xAxisMin10; label <= _xAxisMax; label += _stepX)
            {
                float xPoint = _xLeft + ((_xAxisMin10 - _xAxisMin) + (label - _xAxisMin10)) * _xScale;
                float yPoint = _yBottom - Font.Height;
                if (xPoint < _xRight - _labelWidthX)
                {
                    g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, _brushFore, xPoint, yPoint);
                }
            }

            for (int label = _yAxisMin; label <= _yAxisMax; label += _stepY)
            {
                var labelY = (int)(_xAxisY - (label - _yAxisMin) * _yScale);
                if (label > -1)
                {
                    g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, _brushFore, _xRight, labelY - Font.Height / 2 - 1);
                }
                g.DrawLine(_penGrid, _xLeft, labelY, _xRight, labelY);
            }

            int lastXPt = -1;
            int lastYPt = -1;

            for (int i = 0; i < _tradeCounts.Length; i++)
            {
                float xPt       = _xLeft + (i + 1) * _xScale;
                float yPtBottom = _xAxisY;
                int   val       = _isCounts ? _tradeCounts[i] : Math.Abs(_tradeCumulatives[i]);
                float yPtTop    = (_xAxisY - (val - _yAxisMin) * _yScale);

                if ((int)yPtTop == (int)yPtBottom)
                {
                    continue;
                }

                if (lastXPt == (int)xPt && lastYPt == (int)yPtTop)
                {
                    continue;
                }

                Color color = _isCounts ? Color.Blue : _tradeIndexes[i] < 0 ? Color.Red : Color.Green;
                g.DrawLine(new Pen(color), xPt, yPtBottom, xPt, yPtTop);

                lastXPt = (int)xPt;
                lastYPt = (int)yPtTop;
            }

            // Coordinate axes
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xLeft - 1, _yTop - Space, _xLeft - 1, _xAxisY);
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xLeft - 1, _xAxisY, _xRight, _xAxisY);
        }
Exemplo n.º 27
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++;
                }
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Form OnPaint.
 /// </summary>
 protected override void OnPaint(PaintEventArgs e)
 {
     Data.GradientPaint(e.Graphics, ClientRectangle, LayoutColors.ColorFormBack, LayoutColors.DepthControl);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Caption bar
            Data.GradientPaint(g, _rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(_strChartTitle, Font, new SolidBrush(LayoutColors.ColorCaptionText), _rectfCaption, _sfCaption);

            // Border
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1, ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);

            // Paints the background by gradient
            var rectField = new RectangleF(Border, _captionHeight, ClientSize.Width - 2 * Border, ClientSize.Height - _captionHeight - Border);

            Data.GradientPaint(g, rectField, LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            if (_isNotPaint)
            {
                return;
            }

            string unit      = " [" + (Configs.AccountInMoney ? Configs.AccountCurrency : Language.T("pips")) + "]";
            string subHeader = _isCounts ? Language.T("Count of Trades") : Language.T("Accumulated Amount") + unit;

            g.DrawString(subHeader, Font, new SolidBrush(LayoutColors.ColorChartFore), _rectSubHeader, _sfCaption);
            var formatCenter = new StringFormat {
                Alignment = StringAlignment.Center
            };

            // Grid and Price labels
            for (int label = _xAxisMin10; label <= _xAxisMax; label += _stepX)
            {
                float xPoint = _xLeft + ((_xAxisMin10 - _xAxisMin) + (label - _xAxisMin10)) * _xScale;
                float yPoint = _yBottom - Font.Height;
                if (xPoint <= _xRight - _labelWidthX / 2)
                {
                    g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, _brushFore, xPoint, yPoint, formatCenter);
                }
            }

            for (int label = _yAxisMin; label <= _yAxisMax; label += _stepY)
            {
                var labelY = (int)(_xAxisY - (label - _yAxisMin) * _yScale);
                if (label > -1)
                {
                    g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, _brushFore, _xRight, labelY - Font.Height / 2 - 1);
                }
                g.DrawLine(_penGrid, _xLeft, labelY, _xRight, labelY);
            }

            foreach (var data in _chartData)
            {
                double val       = _isCounts ? data.Value.TradesCount : Math.Abs(data.Value.TotalResult);
                float  xPt       = _xLeft + (data.Key - _minIndex + 1) * _xScale;
                float  yPtBottom = _xAxisY;
                var    yPtTop    = (float)(_xAxisY - (val - _yAxisMin) * _yScale);

                Color color = _isCounts ? Color.Blue : data.Value.TotalResult < 0 ? Color.Red : Color.Green;
                g.DrawLine(new Pen(color), xPt, yPtBottom, xPt, yPtTop);
            }

            // Coordinate axes
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xLeft - 1, _yTop - Space, _xLeft - 1, _xAxisY);
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), _xLeft - 1, _xAxisY, _xRight, _xAxisY);
        }