Exemple #1
0
        /// <summary>
        /// Sets chart's instrument and back testing data.
        /// </summary>
        public void SetChartData()
        {
            isNotPaint = !Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar;

            if (isNotPaint)
            {
                return;
            }

            showPriceLine   = Configs.ShowPriceChartOnAccountChart && Backtester.ExecutedOrders > 0;
            isScanPerformed = Backtester.IsScanPerformed;

            firstBar  = Data.FirstBar;
            bars      = Data.Bars;
            chartBars = Data.Bars - firstBar;

            int maxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance;
            int minBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance;
            int maxEquity  = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity  : Backtester.MaxEquity;
            int minEquity  = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity  : Backtester.MinEquity;

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

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

            minimum = (int)(Math.Floor(minimum / 10f) * 10);

            dataMaxPrice = Data.MaxPrice;
            dataMinPrice = Data.MinPrice;

            if (showPriceLine)
            {
                dataClose = new double[bars];
                Data.Close.CopyTo(dataClose, 0);
            }

            if (Configs.AccountInMoney)
            {
                backtesterMoneyBalance = new double[bars];
                backtesterMoneyEquity  = new double[bars];
            }
            else
            {
                backtesterBalance = new int[bars];
                backtesterEquity  = new int[bars];
            }

            if (Configs.AdditionalStatistics)
            {
                if (Configs.AccountInMoney)
                {
                    backtesterLongMoneyBalance  = new double[bars];
                    backtesterShortMoneyBalance = new double[bars];
                }
                else
                {
                    backtesterLongBalance  = new int[bars];
                    backtesterShortBalance = new int[bars];
                }
            }


            for (int bar = firstBar; bar < bars; bar++)
            {
                if (Configs.AccountInMoney)
                {
                    backtesterMoneyBalance[bar] = Backtester.MoneyBalance(bar);
                    backtesterMoneyEquity[bar]  = Backtester.MoneyEquity(bar);
                }
                else
                {
                    backtesterBalance[bar] = Backtester.Balance(bar);
                    backtesterEquity[bar]  = Backtester.Equity(bar);
                }

                if (Configs.AdditionalStatistics)
                {
                    if (Configs.AccountInMoney)
                    {
                        backtesterLongMoneyBalance[bar]  = Backtester.LongMoneyBalance(bar);
                        backtesterShortMoneyBalance[bar] = Backtester.ShortMoneyBalance(bar);
                    }
                    else
                    {
                        backtesterLongBalance[bar]  = Backtester.LongBalance(bar);
                        backtesterShortBalance[bar] = Backtester.ShortBalance(bar);
                    }
                }
            }

            marginCallBar = Backtester.MarginCallBar;

            if (isOOS && barOOS > firstBar)
            {
                balance        = (float)(Configs.AccountInMoney ? Backtester.MoneyBalance(barOOS) : Backtester.Balance(barOOS));
                dataTimeBarOOS = Data.Time[barOOS];
            }
            else
            {
                balance = (float)(Configs.AccountInMoney ? Backtester.NetMoneyBalance : Backtester.NetBalance);
            }

            return;
        }
        /// <summary>
        /// Sets the chart params
        /// </summary>
        public void InitChart()
        {
            if (!Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar)
            {
                return;
            }

            firstBar  = Data.FirstBar;
            bars      = Data.Bars;
            chartBars = Data.Bars - firstBar;
            int iMaxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance;
            int iMinBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance;
            int iMaxEquity  = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity  : Backtester.MaxEquity;
            int iMinEquity  = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity  : Backtester.MinEquity;

            if (Configs.AdditionalStatistics)
            {
                int iMaxLongBalance  = Configs.AccountInMoney ? (int)Backtester.MaxLongMoneyBalance  : Backtester.MaxLongBalance;
                int iMinLongBalance  = Configs.AccountInMoney ? (int)Backtester.MinLongMoneyBalance  : Backtester.MinLongBalance;
                int iMaxShortBalance = Configs.AccountInMoney ? (int)Backtester.MaxShortMoneyBalance : Backtester.MaxShortBalance;
                int iMinShortBalance = Configs.AccountInMoney ? (int)Backtester.MinShortMoneyBalance : Backtester.MinShortBalance;
                int iMaxLSBalance    = Math.Max(iMaxLongBalance, iMaxShortBalance);
                int iMinLSBalance    = Math.Min(iMinLongBalance, iMinShortBalance);

                maximum = Math.Max(Math.Max(iMaxBalance, iMaxEquity), iMaxLSBalance) + 1;
                minimum = Math.Min(Math.Min(iMinBalance, iMinEquity), iMinLSBalance) - 1;
            }
            else
            {
                maximum = Math.Max(iMaxBalance, iMaxEquity) + 1;
                minimum = Math.Min(iMinBalance, iMinEquity) - 1;
            }

            YTop    = border + space;
            YBottom = ClientSize.Height - border - space;
            XLeft   = border;
            XRight  = ClientSize.Width - border - space;
            XScale  = (XRight - XLeft) / (float)chartBars;
            YScale  = (YBottom - YTop) / (float)(maximum - minimum);

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

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

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

            int index = 0;

            for (int iBar = firstBar; iBar < bars; iBar++)
            {
                apntBalance[index].X = XLeft + index * XScale;
                apntEquity[index].X  = XLeft + index * XScale;
                if (Configs.AccountInMoney)
                {
                    apntBalance[index].Y = (float)(YBottom - (Backtester.MoneyBalance(iBar) - minimum) * YScale);
                    apntEquity[index].Y  = (float)(YBottom - (Backtester.MoneyEquity(iBar) - minimum) * YScale);
                }
                else
                {
                    apntBalance[index].Y = YBottom - (Backtester.Balance(iBar) - minimum) * YScale;
                    apntEquity[index].Y  = YBottom - (Backtester.Equity(iBar) - 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 - (Backtester.LongMoneyBalance(iBar) - minimum) * YScale);
                        apntShortBalance[index].Y = (float)(YBottom - (Backtester.ShortMoneyBalance(iBar) - minimum) * YScale);
                    }
                    else
                    {
                        apntLongBalance[index].Y  = YBottom - (Backtester.LongBalance(iBar) - minimum) * YScale;
                        apntShortBalance[index].Y = YBottom - (Backtester.ShortBalance(iBar) - minimum) * YScale;
                    }
                }

                index++;
            }
        }