Forex_Strategy_Builder.Small_Balance_Chart.InitChart C# (CSharp) Method

InitChart() public method

Sets the chart params
public InitChart ( ) : void
return void
        public void InitChart()
        {
            // Chart Title
            strChartTitle = Language.T("Balance / Equity Chart") + " [" + (Configs.AccountInMoney ? Configs.AccountCurrency + "]" : Language.T("pips") + "]");
            font          = new Font(Font.FontFamily, 9);
            captionHeight = (float)Math.Max(font.Height, 18);
            rectfCaption  = new RectangleF(0, 0, ClientSize.Width, captionHeight);
            stringFormatCaption               = new StringFormat();
            stringFormatCaption.Alignment     = StringAlignment.Center;
            stringFormatCaption.LineAlignment = StringAlignment.Center;
            stringFormatCaption.Trimming      = StringTrimming.EllipsisCharacter;
            stringFormatCaption.FormatFlags   = StringFormatFlags.NoWrap;

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

            if (isNotPaint) return;

            YTop    = (int)captionHeight + 2 * space + 1;
            YBottom = ClientSize.Height  - 2 * space - 1 - border;

            Graphics  g = CreateGraphics();
            labelWidth = (int)Math.Max(g.MeasureString(minimum.ToString(), Font).Width, g.MeasureString(maximum.ToString(), Font).Width);
            g.Dispose();

            labelWidth = Math.Max(labelWidth, 30);
            XLeft  = border + space;
            XRight = ClientSize.Width - border - space - labelWidth;
            XScale = (XRight - 2 * space - border) / (float)chartBars;

            countLabels = (int)Math.Max((YBottom - YTop) / 20, 1);
            delta       = (float)Math.Max(Math.Round((maximum - minimum) / (float)countLabels), 10);
            step        = (int)Math.Ceiling(delta / 10) * 10;
            countLabels = (int)Math.Ceiling((maximum - minimum) / (float)step);
            maximum     = minimum + countLabels * step;
            YScale      = (YBottom - YTop) / (countLabels * (float)step);

            apntBalance = new PointF[chartBars];
            apntEquity  = new PointF[chartBars];

            if (Configs.AdditionalStatistics)
            {
                apntLongBalance  = new PointF[chartBars];
                apntShortBalance = new PointF[chartBars];
            }

            apntClosePrice = new PointF[chartBars];

            // Close Price
            if (showPriceLine)
                YPriceScale = (float)((YBottom - YTop) / (dataMaxPrice - dataMinPrice));

            int index = 0;
            for (int bar = firstBar; bar < bars; bar++)
            {
                apntBalance[index].X = XLeft + index * XScale;
                apntEquity[index].X  = XLeft + index * XScale;
                if (Configs.AccountInMoney)
                {
                    apntBalance[index].Y = (float)(YBottom - (backtesterMoneyBalance[bar] - minimum) * YScale);
                    apntEquity[index].Y  = (float)(YBottom - (backtesterMoneyEquity[bar]  - minimum) * YScale);
                }
                else
                {
                    apntBalance[index].Y = YBottom -  (backtesterBalance[bar] - minimum) * YScale;
                    apntEquity[index].Y  = YBottom -  (backtesterEquity[bar]  - minimum) * YScale;
                }

                if (Configs.AdditionalStatistics)
                {
                    apntLongBalance[index].X  = XLeft + index * XScale;
                    apntShortBalance[index].X = XLeft + index * XScale;
                    if (Configs.AccountInMoney)
                    {
                        apntLongBalance[index].Y  = (float)(YBottom - (backtesterLongMoneyBalance[bar]  - minimum) * YScale);
                        apntShortBalance[index].Y = (float)(YBottom - (backtesterShortMoneyBalance[bar] - minimum) * YScale);
                    }
                    else
                    {
                        apntLongBalance[index].Y  = YBottom - (backtesterLongBalance[bar]  - minimum) * YScale;
                        apntShortBalance[index].Y = YBottom - (backtesterShortBalance[bar] - minimum) * YScale;
                    }
                }

                if (showPriceLine)
                {
                    apntClosePrice[index].X = XLeft + index * XScale;
                    apntClosePrice[index].Y = YBottom - (float)(dataClose[bar] - dataMinPrice) * YPriceScale;
                }
                index++;
            }

            // Margin Call
            if (marginCallBar >= firstBar)
                XMarginCallBar = XLeft + (marginCallBar - firstBar) * XScale;
            else
                XMarginCallBar = 0;

            //OOS
            if (isOOS && barOOS > firstBar)
                XOOSBar = XLeft + (barOOS - firstBar) * XScale;
            else
                XOOSBar = 0;

            YBalance = YBottom - (balance - minimum) * YScale;

            isHideScanningLine = false;
            modellingQuolity = " MQ " + Data.ModellingQuality.ToString("N2") + "%";
        }

Usage Example

        // Updates the balance chart.
        void UpdateBalanceChart()
        {
            if (!isChartRecalculation)
            {
                return;
            }

            pnlSmallBalanceChart.SetChartData();
            pnlSmallBalanceChart.InitChart();
            pnlSmallBalanceChart.Invalidate();
        }
All Usage Examples Of Forex_Strategy_Builder.Small_Balance_Chart::InitChart