/// <summary>
        /// Sets the chart params
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            try { g.Clear(LayoutColors.ColorChartBack); }
            catch { }

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(caption, fontCaption, brushCaption, rectfCaption, stringFormatCaption);
            g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height);
            g.DrawLine(penBorder, ClientSize.Width - border + 1, captionHeight, ClientSize.Width - border + 1, ClientSize.Height);
            g.DrawLine(penBorder, 0, ClientSize.Height - border + 1, ClientSize.Width, ClientSize.Height - border + 1);

            if (tickData == null || tickData.Length < 2)
            {
                string text = Language.T("Waiting for ticks...");
                g.DrawString(text, fontCaption, penChart.Brush, chartArea);
                return;
            }

            int    ticks   = tickData.Length;
            double maximum = double.MinValue;
            double minimum = double.MaxValue;

            foreach (double tick in tickData)
            {
                if (maximum < tick)
                {
                    maximum = tick;
                }
                if (minimum > tick)
                {
                    minimum = tick;
                }
            }

            maximum += point;
            minimum -= point;

            int    space  = border + 2;
            int    XLeft  = space;
            int    XRight = ClientSize.Width - space;
            double scaleX = (XRight - XLeft) / ((double)ticks - 1);

            int    YTop    = (int)captionHeight + space;
            int    YBottom = ClientSize.Height - space;
            double scaleY  = (YBottom - YTop) / (maximum - minimum);

            int index = 0;

            PointF[] apntTick = new PointF[ticks];
            foreach (double tick in tickData)
            {
                apntTick[index].X = (float)(XLeft + index * scaleX);
                apntTick[index].Y = (float)(YBottom - (tick - minimum) * scaleY);
                index++;
            }

            g.DrawLines(penChart, apntTick);
        }
Exemple #2
0
        private void PnlDataInfoButtons_Paint(object sender, PaintEventArgs e)
        {
            var      pnl = (Panel)sender;
            Graphics g   = e.Graphics;

            // Paint the panel background
            Data.GradientPaint(g, pnl.ClientRectangle, LayoutColors.ColorControlBack, LayoutColors.DepthCaption);
        }
Exemple #3
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(sCaption, fontCaption, brushCaption, rectfCaption, stringFormatCaption);

            float y = fCaptionHeight;

            for (int i = 0; i *fRowHeight + fCaptionHeight < fHeight; i++)
            {
                float      fVerticalPosition = i * fRowHeight + fCaptionHeight;
                PointF     pointFParam       = new PointF(fParamTab + 2, fVerticalPosition);
                PointF     pointFValue       = new PointF(fValueTab + 2, fVerticalPosition);
                RectangleF rectRow           = new RectangleF(iBorder, fVerticalPosition, fWidth, fRowHeight);

                // Row background
                if (i % 2f != 0)
                {
                    g.FillRectangle(new SolidBrush(colorBackroundEvenRows), rectRow);
                }
                else
                {
                    g.FillRectangle(new SolidBrush(colorBackroundOddRows), rectRow);
                }

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

                g.DrawString(asParam[i + vScrollBar.Value], fontData, brushParams, pointFParam, stringFormatData);
                g.DrawString(asValue[i + vScrollBar.Value], fontData, brushData, pointFValue, stringFormatData);
            }

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

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

            // Caption
            Data.GradientPaint(g, _rectfCaption, _colorCaptionBack, LayoutColors.DepthCaption);
            if (_isShowCaption)
            {
                g.DrawString(_caption, _fontCaption, _brushCaption, _rectfCaption, _stringFormatCaption);
            }
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1,
                       ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);

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

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

            // Caption
            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);
            if (isShowCaption)
            {
                g.DrawString(caption, fontCaption, brushCaption, rectfCaption, stringFormatCaption);
            }
            g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height);
            g.DrawLine(penBorder, ClientSize.Width - border + 1, captionHeight, ClientSize.Width - border + 1, ClientSize.Height);
            g.DrawLine(penBorder, 0, ClientSize.Height - border + 1, ClientSize.Width, ClientSize.Height - border + 1);

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

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

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

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

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

                // Row background
                g.FillRectangle(
                    Math.Abs(i % 2f - 0) > 0.01
                        ? new SolidBrush(_colorBackroundEvenRows)
                        : new SolidBrush(_colorBackroundOddRows), rectRow);

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

                g.DrawString(_asParam[i + _vScrollBar.Value], _fontData, _brushParams, pointFParam, _stringFormatData);
                g.DrawString(_asValue[i + _vScrollBar.Value], _fontData, _brushData, pointFValue, _stringFormatData);
            }

            // Border
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1,
                       ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);
        }
        /// <summary>
        /// Sets the chart params
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            try
            {
                g.Clear(LayoutColors.ColorChartBack);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            Data.GradientPaint(g, _rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(_caption, _fontCaption, _brushCaption, _rectfCaption, _stringFormatCaption);
            g.DrawLine(_penBorder, 1, _captionHeight, 1, ClientSize.Height);
            g.DrawLine(_penBorder, ClientSize.Width - Border + 1, _captionHeight, ClientSize.Width - Border + 1,
                       ClientSize.Height);
            g.DrawLine(_penBorder, 0, ClientSize.Height - Border + 1, ClientSize.Width, ClientSize.Height - Border + 1);

            if (_tickData == null || _tickData.Length < 2)
            {
                string text = Language.T("Waiting for ticks...");
                g.DrawString(text, _fontCaption, _penChart.Brush, _chartArea);
                return;
            }

            int    ticks   = _tickData.Length;
            double maximum = double.MinValue;
            double minimum = double.MaxValue;

            foreach (double tick in _tickData)
            {
                if (maximum < tick)
                {
                    maximum = tick;
                }
                if (minimum > tick)
                {
                    minimum = tick;
                }
            }

            maximum += _point;
            minimum -= _point;

            const int space  = Border + 2;
            const int xLeft  = space;
            int       xRight = ClientSize.Width - space;
            double    scaleX = (xRight - xLeft) / ((double)ticks - 1);

            int    yTop    = (int)_captionHeight + space;
            int    yBottom = ClientSize.Height - space;
            double scaleY  = (yBottom - yTop) / (maximum - minimum);

            int index    = 0;
            var apntTick = new PointF[ticks];

            foreach (double tick in _tickData)
            {
                apntTick[index].X = (float)(xLeft + index * scaleX);
                apntTick[index].Y = (float)(yBottom - (tick - minimum) * scaleY);
                index++;
            }

            g.DrawLines(_penChart, apntTick);
        }
 /// <summary>
 /// Form On Paint
 /// </summary>
 protected override void OnPaint(PaintEventArgs e)
 {
     Data.GradientPaint(e.Graphics, ClientRectangle, LayoutColors.ColorFormBack, LayoutColors.DepthControl);
 }
Exemple #9
0
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            try
            {
                g.Clear(LayoutColors.ColorChartBack);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

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

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

            if (_balanceData == null || _balanceData.Length < 1 ||
                _equityData == null || _equityData.Length < 1)
            {
                return;
            }

            // Grid and Price labels
            for (int iLabel = _minValue; iLabel <= _maxValue; iLabel += _stepLabels)
            {
                var iLabelY = (int)(_yBottom - (iLabel - _minValue) * _scaleY);
                g.DrawString(iLabel.ToString(".00"), Font, _brushFore, _xRight, iLabelY - Font.Height / 2 - 1);
                g.DrawLine(_penGrid, _xLeft, iLabelY, _xRight, iLabelY);
            }

            // Equity and Balance lines
            g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), _apntEquity);
            g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), _apntBalance);

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

            // Equity price label.
            var    pntEquity  = new Point(_xRight - Space + 2, (int)(_equityY - _font.Height / 2.0 - 1));
            var    sizeEquity = new Size(_labelWidth + Space, _font.Height + 2);
            string equity     = (_netEquity.ToString("F2"));
            var    apEquity   = new[]
            {
                new PointF(_xRight - Space - 8, _equityY),
                new PointF(_xRight - Space, _equityY - sizeEquity.Height / 2),
                new PointF(_xRight - Space + sizeEquity.Width + 5, _equityY - sizeEquity.Height / 2),
                new PointF(_xRight - Space + sizeEquity.Width + 5, _equityY + sizeEquity.Height / 2),
                new PointF(_xRight - Space, _equityY + sizeEquity.Height / 2),
            };

            g.FillPolygon(new SolidBrush(LayoutColors.ColorChartEquityLine), apEquity);
            g.DrawString(equity, _font, new SolidBrush(LayoutColors.ColorChartBack), pntEquity);

            // Balance price label.
            var    pntBalance  = new Point(_xRight - Space + 2, (int)(_balanceY - _font.Height / 2.0 - 1));
            var    sizeBalance = new Size(_labelWidth + Space, _font.Height + 2);
            string balance     = (_netBalance.ToString("F2"));
            var    apBalance   = new[]
            {
                new PointF(_xRight - Space - 8, _balanceY),
                new PointF(_xRight - Space, _balanceY - sizeBalance.Height / 2),
                new PointF(_xRight - Space + sizeBalance.Width + 5, _balanceY - sizeBalance.Height / 2),
                new PointF(_xRight - Space + sizeBalance.Width + 5, _balanceY + sizeBalance.Height / 2),
                new PointF(_xRight - Space, _balanceY + sizeBalance.Height / 2),
            };

            g.FillPolygon(new SolidBrush(LayoutColors.ColorChartBalanceLine), apBalance);
            g.DrawString(balance, _font, new SolidBrush(LayoutColors.ColorChartBack), pntBalance);

            // Chart Text
            string chartText = _startTime.ToString(CultureInfo.InvariantCulture);

            g.DrawString(chartText, _font, new SolidBrush(LayoutColors.ColorChartFore), _xLeft, _yBottom);
        }
Exemple #10
0
        /// <summary>
        /// Panel properties Paint
        /// </summary>
        private void PnlPropertiesPaint(object sender, PaintEventArgs e)
        {
            var      pnl    = (Panel)sender;
            Graphics g      = e.Graphics;
            int      iWidth = pnl.ClientSize.Width;

            Color colorCaptionBack = LayoutColors.ColorSlotCaptionBackAveraging;
            Color colorCaptionText = LayoutColors.ColorSlotCaptionText;
            Color colorBackground  = LayoutColors.ColorSlotBackground;
            Color colorLogicText   = LayoutColors.ColorSlotLogicText;
            Color colorDash        = LayoutColors.ColorSlotDash;

            // Caption
            string stringCaptionText   = Language.T("Strategy Properties");
            var    fontCaptionText     = new Font(Font.FontFamily, 9);
            float  fCaptionHeight      = Math.Max(fontCaptionText.Height, 18);
            float  fCaptionWidth       = iWidth;
            Brush  brushCaptionText    = new SolidBrush(colorCaptionText);
            var    stringFormatCaption = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Center
            };

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

            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption);

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

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

            // Paint the panel's background
            var rectfPanel = new RectangleF(Border, fCaptionHeight, pnl.Width - 2 * Border,
                                            pnl.Height - fCaptionHeight - Border);

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

            int iVPosition = (int)fCaptionHeight + 2;

            var stringFormat = new StringFormat
            {
                Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap
            };

            var   fontParam  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            var   fontValue  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Brush brushParam = new SolidBrush(colorLogicText);
            Brush brushValue = new SolidBrush(colorLogicText);
            var   penDash    = new Pen(colorDash);

            string strPermaSL = _strategy.UsePermanentSL
                                    ? (Data.Strategy.PermanentSLType == PermanentProtectionType.Absolute ? "(Abs) " : "") +
                                _strategy.PermanentSL.ToString(CultureInfo.InvariantCulture)
                                    : Language.T("None");
            string strPermaTP = _strategy.UsePermanentTP
                                    ? (Data.Strategy.PermanentTPType == PermanentProtectionType.Absolute ? "(Abs) " : "") +
                                _strategy.PermanentTP.ToString(CultureInfo.InvariantCulture)
                                    : Language.T("None");
            string strBreakEven = _strategy.UseBreakEven
                                      ? _strategy.BreakEven.ToString(CultureInfo.InvariantCulture)
                                      : Language.T("None");

            if (_slotMinMidMax == SlotSizeMinMidMax.Min)
            {
                string sParam = Language.T(_strategy.SameSignalAction.ToString()) + "; " +
                                Language.T(_strategy.OppSignalAction.ToString()) + "; " +
                                "SL-" + strPermaSL + "; " +
                                "TP-" + strPermaTP + "; " +
                                "BE-" + strBreakEven;

                SizeF sizeParam      = g.MeasureString(sParam, fontParam);
                float fMaxParamWidth = sizeParam.Width;

                // Padding Param Padding Dash Padding Value Padding
                float fPadding        = Space;
                float fNecessaryWidth = 2 * fPadding + fMaxParamWidth;

                fPadding = iWidth > fNecessaryWidth?Math.Max((pnl.ClientSize.Width - fMaxParamWidth) / 2, fPadding) : 2;

                float fTabParam = fPadding;

                var pointParam = new PointF(fTabParam, iVPosition);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
            }
            else
            {
                // Find Maximum width of the strings
                var asParams = new[]
                {
                    Language.T("Same direction signal"),
                    Language.T("Opposite direction signal"),
                    Language.T("Permanent Stop Loss"),
                    Language.T("Permanent Take Profit"),
                    Language.T("Break Even")
                };

                var asValues = new[]
                {
                    Language.T(_strategy.SameSignalAction.ToString()),
                    Language.T(_strategy.OppSignalAction.ToString()),
                    strPermaSL,
                    strPermaTP,
                    strBreakEven
                };

                float fMaxParamWidth = 0;
                foreach (string param in asParams)
                {
                    if (g.MeasureString(param, fontParam).Width > fMaxParamWidth)
                    {
                        fMaxParamWidth = g.MeasureString(param, fontParam).Width;
                    }
                }

                float fMaxValueWidth = 0;
                foreach (string value in asValues)
                {
                    if (g.MeasureString(value, fontParam).Width > fMaxValueWidth)
                    {
                        fMaxValueWidth = g.MeasureString(value, fontParam).Width;
                    }
                }

                // Padding Param Padding Dash Padding Value Padding
                float       fPadding        = Space;
                const float fDashWidth      = 5;
                float       fNecessaryWidth = 4 * fPadding + fMaxParamWidth + fMaxValueWidth + fDashWidth;

                if (iWidth > fNecessaryWidth)
                {
                    // 2*Padding Param Padding Dash Padding Value 2*Padding
                    fPadding = Math.Max((pnl.ClientSize.Width - fMaxParamWidth - fMaxValueWidth - fDashWidth) / 6,
                                        fPadding);
                }
                else
                {
                    fPadding = 2;
                }

                float fTabParam = 2 * fPadding;
                float fTabDash  = fTabParam + fMaxParamWidth + fPadding;
                float fTabValue = fTabDash + fDashWidth + fPadding;

                // Same direction
                string sParam     = Language.T("Same direction signal");
                string sValue     = Language.T(_strategy.SameSignalAction.ToString());
                var    pointParam = new PointF(fTabParam, iVPosition);
                var    pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(fTabValue, iVPosition);
                var    sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height + 2;

                // Opposite direction
                sParam     = Language.T("Opposite direction signal");
                sValue     = Language.T(_strategy.OppSignalAction.ToString());
                pointParam = new PointF(fTabParam, iVPosition);
                pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                pointValue = new PointF(fTabValue, iVPosition);
                sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height + 2;

                // Permanent Stop Loss
                sParam     = Language.T("Permanent Stop Loss");
                sValue     = strPermaSL;
                pointParam = new PointF(fTabParam, iVPosition);
                pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                pointValue = new PointF(fTabValue, iVPosition);
                sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height + 2;

                // Permanent Take Profit
                sParam     = Language.T("Permanent Take Profit");
                sValue     = strPermaTP;
                pointParam = new PointF(fTabParam, iVPosition);
                pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                pointValue = new PointF(fTabValue, iVPosition);
                sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height;

                // Break Even
                sParam     = Language.T("Break Even");
                sValue     = strBreakEven;
                pointParam = new PointF(fTabParam, iVPosition);
                pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                pointValue = new PointF(fTabValue, iVPosition);
                sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
            }
        }
Exemple #11
0
        /// <summary>
        /// Panel Slot Paint
        /// </summary>
        private void PnlSlotPaint(object sender, PaintEventArgs e)
        {
            var       pnl      = (Panel)sender;
            Graphics  g        = e.Graphics;
            var       iSlot    = (int)pnl.Tag;
            int       iWidth   = pnl.ClientSize.Width;
            SlotTypes slotType = _strategy.GetSlotType(iSlot);

            Color colorBackground             = LayoutColors.ColorSlotBackground;
            Color colorCaptionText            = LayoutColors.ColorSlotCaptionText;
            Color colorCaptionBackOpen        = LayoutColors.ColorSlotCaptionBackOpen;
            Color colorCaptionBackOpenFilter  = LayoutColors.ColorSlotCaptionBackOpenFilter;
            Color colorCaptionBackClose       = LayoutColors.ColorSlotCaptionBackClose;
            Color colorCaptionBackCloseFilter = LayoutColors.ColorSlotCaptionBackCloseFilter;
            Color colorIndicatorNameText      = LayoutColors.ColorSlotIndicatorText;
            Color colorLogicText = LayoutColors.ColorSlotLogicText;
            Color colorParamText = LayoutColors.ColorSlotParamText;
            Color colorValueText = LayoutColors.ColorSlotValueText;
            Color colorDash      = LayoutColors.ColorSlotDash;

            // Caption
            string stringCaptionText = string.Empty;
            Color  colorCaptionBack  = LayoutColors.ColorSignalRed;

            switch (slotType)
            {
            case SlotTypes.Open:
                stringCaptionText = Language.T("Opening Point of the Position");
                colorCaptionBack  = colorCaptionBackOpen;
                break;

            case SlotTypes.OpenFilter:
                stringCaptionText = Language.T("Opening Logic Condition");
                colorCaptionBack  = colorCaptionBackOpenFilter;
                break;

            case SlotTypes.Close:
                stringCaptionText = Language.T("Closing Point of the Position");
                colorCaptionBack  = colorCaptionBackClose;
                break;

            case SlotTypes.CloseFilter:
                stringCaptionText = Language.T("Closing Logic Condition");
                colorCaptionBack  = colorCaptionBackCloseFilter;
                break;
            }

            var penBorder = new Pen(Data.ColorChanage(colorCaptionBack, -LayoutColors.DepthCaption), Border);

            var   fontCaptionText     = new Font(Font.FontFamily, 9);
            float fCaptionHeight      = Math.Max(fontCaptionText.Height, 18);
            float fCaptionWidth       = iWidth;
            Brush brushCaptionText    = new SolidBrush(colorCaptionText);
            var   stringFormatCaption = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Center
            };

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

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

            if (iSlot != _strategy.OpenSlot && iSlot != _strategy.CloseSlot)
            {
                int iButtonDimentions = (int)fCaptionHeight - 2;
                int iButtonX          = iWidth - iButtonDimentions - 1;
                AbtnRemoveSlot[iSlot].Size     = new Size(iButtonDimentions, iButtonDimentions);
                AbtnRemoveSlot[iSlot].Location = new Point(iButtonX, 1);

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

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

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

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

            int iVPosition = (int)fCaptionHeight + 3;

            // Indicator name
            var stringFormatIndicatorName = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap
            };
            string sIndicatorName = _strategy.Slot[iSlot].IndicatorName;
            var    fontIndicator  = new Font(Font.FontFamily, 11f, FontStyle.Regular);
            Brush  brushIndName   = new SolidBrush(colorIndicatorNameText);
            float  fIndNameHeight = fontIndicator.Height;
            float  fGroupWidth    = 0;

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

            RectangleF rectIndName = iWidth >= 2 * fGroupWidth + fIndicatorWidth
                                         ? new RectangleF(0, iVPosition, iWidth, fIndNameHeight)
                                         : new RectangleF(fGroupWidth, iVPosition, iWidth - fGroupWidth, fIndNameHeight);

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

            if (_slotMinMidMax == SlotSizeMinMidMax.Min)
            {
                return;
            }

            // Logic
            var stringFormatLogic = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoClip
            };

            float fPadding = Space;

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

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

            if (_slotMinMidMax == SlotSizeMinMidMax.Mid)
            {
                return;
            }

            // Parameters
            var stringFormat = new StringFormat
            {
                Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap
            };

            var   fontParam  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            var   fontValue  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Brush brushParam = new SolidBrush(colorParamText);
            Brush brushValue = new SolidBrush(colorValueText);
            var   penDash    = new Pen(colorDash);

            // Find Maximum width of the strings
            float fMaxParamWidth = 0;
            float fMaxValueWidth = 0;

            for (int i = 1; i < 5; i++)
            {
                if (!_strategy.Slot[iSlot].IndParam.ListParam[i].Enabled)
                {
                    continue;
                }

                string sParam    = _strategy.Slot[iSlot].IndParam.ListParam[i].Caption;
                string sValue    = _strategy.Slot[iSlot].IndParam.ListParam[i].Text;
                SizeF  sizeParam = g.MeasureString(sParam, fontParam);
                SizeF  sizeValue = g.MeasureString(sValue, fontValue);

                if (fMaxParamWidth < sizeParam.Width)
                {
                    fMaxParamWidth = sizeParam.Width;
                }

                if (fMaxValueWidth < sizeValue.Width)
                {
                    fMaxValueWidth = sizeValue.Width;
                }
            }

            foreach (NumericParam numericParam in _strategy.Slot[iSlot].IndParam.NumParam)
            {
                if (!numericParam.Enabled)
                {
                    continue;
                }

                string sParam    = numericParam.Caption;
                string sValue    = numericParam.ValueToString;
                SizeF  sizeParam = g.MeasureString(sParam, fontParam);
                SizeF  sizeValue = g.MeasureString(sValue, fontValue);

                if (fMaxParamWidth < sizeParam.Width)
                {
                    fMaxParamWidth = sizeParam.Width;
                }

                if (fMaxValueWidth < sizeValue.Width)
                {
                    fMaxValueWidth = sizeValue.Width;
                }
            }

            foreach (CheckParam checkParam in _strategy.Slot[iSlot].IndParam.CheckParam)
            {
                if (!checkParam.Enabled)
                {
                    continue;
                }

                string sParam    = checkParam.Caption;
                string sValue    = checkParam.Checked ? "Yes" : "No";
                SizeF  sizeParam = g.MeasureString(sParam, fontParam);
                SizeF  sizeValue = g.MeasureString(sValue, fontValue);

                if (fMaxParamWidth < sizeParam.Width)
                {
                    fMaxParamWidth = sizeParam.Width;
                }

                if (fMaxValueWidth < sizeValue.Width)
                {
                    fMaxValueWidth = sizeValue.Width;
                }
            }

            // Padding Param Padding Dash Padding Value Padding
            const float fDashWidth      = 5;
            float       fNecessaryWidth = 4 * fPadding + fMaxParamWidth + fMaxValueWidth + fDashWidth;

            fPadding = iWidth > fNecessaryWidth
                           ? Math.Max((pnl.ClientSize.Width - fMaxParamWidth - fMaxValueWidth - fDashWidth) / 6, fPadding)
                           : 2;

            float fTabParam = 2 * fPadding;
            float fTabDash  = fTabParam + fMaxParamWidth + fPadding;
            float fTabValue = fTabDash + fDashWidth + fPadding;

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

                string sParam     = _strategy.Slot[iSlot].IndParam.ListParam[i].Caption;
                string sValue     = _strategy.Slot[iSlot].IndParam.ListParam[i].Text;
                var    pointParam = new PointF(fTabParam, iVPosition);
                var    pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(fTabValue, iVPosition);
                var    sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

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

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

                string sParam     = numericParam.Caption;
                string sValue     = numericParam.ValueToString;
                var    pointParam = new PointF(fTabParam, iVPosition);
                var    pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(fTabValue, iVPosition);
                var    sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

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

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

                string sParam     = checkParam.Caption;
                string sValue     = checkParam.Checked ? "Yes" : "No";
                var    pointParam = new PointF(fTabParam, iVPosition);
                var    pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(fTabValue, iVPosition);
                var    sizefValue = new SizeF(Math.Max(iWidth - fTabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                iVPosition += fontValue.Height;
            }
        }
        /// <summary>
        /// Paints the chart
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            try { g.Clear(LayoutColors.ColorChartBack); }
            catch { }

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

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

            if (balanceData == null || balanceData.Length < 1 ||
                equityData == null || equityData.Length < 1)
            {
                return;
            }

            // Grid and Price labels
            for (int iLabel = minValue; iLabel <= maxValue; iLabel += stepLabels)
            {
                int iLabelY = (int)(YBottom - (iLabel - minValue) * scaleY);
                g.DrawString(iLabel.ToString(".00"), Font, brushFore, XRight, iLabelY - Font.Height / 2 - 1);
                g.DrawLine(penGrid, XLeft, iLabelY, XRight, iLabelY);
            }

            // Equity and Balance lines
            g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), apntEquity);
            g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), apntBalance);

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

            // Equity price label.
            Point  pntEquity  = new Point(XRight - space + 2, (int)(equityY - font.Height / 2 - 1));
            Size   sizeEquity = new Size(labelWidth + space, font.Height + 2);
            string equity     = (netEquity.ToString("F2"));

            PointF[] apEquity = new PointF[] {
                new PointF(XRight - space - 8, equityY),
                new PointF(XRight - space, equityY - sizeEquity.Height / 2),
                new PointF(XRight - space + sizeEquity.Width + 5, equityY - sizeEquity.Height / 2),
                new PointF(XRight - space + sizeEquity.Width + 5, equityY + sizeEquity.Height / 2),
                new PointF(XRight - space, equityY + sizeEquity.Height / 2),
            };
            g.FillPolygon(new SolidBrush(LayoutColors.ColorChartEquityLine), apEquity);
            g.DrawString(equity, font, new SolidBrush(LayoutColors.ColorChartBack), pntEquity);

            // Balance price label.
            Point  pntBalance  = new Point(XRight - space + 2, (int)(balanceY - font.Height / 2 - 1));
            Size   sizeBalance = new Size(labelWidth + space, font.Height + 2);
            string balance     = (netBalance.ToString("F2"));

            PointF[] apBalance = new PointF[] {
                new PointF(XRight - space - 8, balanceY),
                new PointF(XRight - space, balanceY - sizeBalance.Height / 2),
                new PointF(XRight - space + sizeBalance.Width + 5, balanceY - sizeBalance.Height / 2),
                new PointF(XRight - space + sizeBalance.Width + 5, balanceY + sizeBalance.Height / 2),
                new PointF(XRight - space, balanceY + sizeBalance.Height / 2),
            };
            g.FillPolygon(new SolidBrush(LayoutColors.ColorChartBalanceLine), apBalance);
            g.DrawString(balance, font, new SolidBrush(LayoutColors.ColorChartBack), pntBalance);

            // Chart Text
            string chartText = startTime.ToString();

            g.DrawString(chartText, font, new SolidBrush(LayoutColors.ColorChartFore), XLeft, YBottom);

            return;
        }
        /// <summary>
        /// Paints the base panel
        /// </summary>
        void PanelBase_Paint(object sender, PaintEventArgs e)
        {
            Data.GradientPaint(e.Graphics, ((Panel)sender).ClientRectangle, LayoutColors.ColorControlBack, LayoutColors.DepthControl);

            return;
        }