Пример #1
0
        /// <summary>
        ///     Initialize the form and controls
        /// </summary>
        public BarExplorer(int barNumber)
        {
            pnlChart = new Panel();
            pnlInfo  = new Panel();
            toolTip  = new ToolTip();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            SetJournalPoints();
        }
Пример #2
0
        /// <summary>
        ///     Navigates to a bar.
        /// </summary>
        private void Navigate(string sDir)
        {
            switch (sDir)
            {
            case "< !":
                for (int i = barCurrent - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.BackTestEval(i) == BacktestEval.Ambiguous)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case "! >":
                for (int i = barCurrent + 1; i < Data.Bars; i++)
                {
                    if (Backtester.BackTestEval(i) == BacktestEval.Ambiguous)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case "<<":
                for (int i = barCurrent - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.SummaryTrans(i) != Transaction.Transfer &&
                        Backtester.SummaryTrans(i) != Transaction.None)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case ">>":
                for (int i = barCurrent + 1; i < Data.Bars; i++)
                {
                    if (Backtester.SummaryTrans(i) != Transaction.Transfer &&
                        Backtester.SummaryTrans(i) != Transaction.None)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case "<max":
                int maxWp  = 0;
                int maxBar = barCurrent;
                for (int i = barCurrent - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.WayPoints(i) > maxWp)
                    {
                        maxWp  = Backtester.WayPoints(i);
                        maxBar = i;
                    }
                }
                barCurrent = maxBar;
                break;

            case ">max":
                maxWp  = 0;
                maxBar = barCurrent;
                for (int i = barCurrent + 1; i < Data.Bars; i++)
                {
                    if (Backtester.WayPoints(i) > maxWp)
                    {
                        maxWp  = Backtester.WayPoints(i);
                        maxBar = i;
                    }
                }
                barCurrent = maxBar;
                break;

            case "<":
                if (barCurrent > Data.FirstBar)
                {
                    barCurrent--;
                }
                break;

            case ">":
                if (barCurrent < Data.Bars - 1)
                {
                    barCurrent++;
                }
                break;

            case "Go":
                barCurrent = (int)nudGo.Value - 1;
                break;
            }

            SetBtnNavigate();

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

            var rectPnlChart = new Rectangle(Border, infoRowHeight, pnlChart.ClientSize.Width - 2 * Border,
                                             pnlChart.ClientSize.Height - infoRowHeight - Border);

            pnlChart.Invalidate(rectPnlChart);

            var rectPnlInfo = new Rectangle(Border, 2 * infoRowHeight, pnlInfo.ClientSize.Width - 2 * Border,
                                            pnlInfo.ClientSize.Height - 2 * infoRowHeight - Border);

            pnlInfo.Invalidate(rectPnlInfo);

            nudGo.Value = barCurrent + 1;
        }