/// <summary>
        /// Initialize the form and controls
        /// </summary>
        public Bar_Explorer(int iBarNumber)
        {
            pnlChart = new Panel();
            pnlInfo  = new Panel();
            toolTip  = new ToolTip();

            bar = iBarNumber < Data.FirstBar ? Data.FirstBar : iBarNumber;

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

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

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

            pnlChart.Parent = this;
            pnlChart.Paint += new PaintEventHandler(PnlChart_Paint);

            pnlInfo.Parent = this;
            pnlInfo.Paint += new PaintEventHandler(PnlInfo_Paint);

            btnNavigate = new Button[4];
            string [] btnNavigateText = new string [4] {
                "< !", "<", ">", "! >"
            };
            string[] btnNavigateTips = new string [4] {
                Language.T("Previous ambiguous bar."),
                Language.T("Previous bar."),
                Language.T("Next bar."),
                Language.T("Next ambiguous bar.")
            };

            for (int i = 0; i < 4; i++)
            {
                btnNavigate[i]             = new Button();
                btnNavigate[i].Parent      = this;
                btnNavigate[i].Text        = btnNavigateText[i];
                btnNavigate[i].Name        = btnNavigateText[i];
                btnNavigate[i].Click      += new EventHandler(BtnNavigate_Click);
                btnNavigate[i].MouseWheel += new MouseEventHandler(Bar_Explorer_MouseWheel);
                btnNavigate[i].UseVisualStyleBackColor = true;
                toolTip.SetToolTip(btnNavigate[i], btnNavigateTips[i]);
            }

            btnNavigate[0].Enabled = Backtester.AmbiguousBars > 0;
            btnNavigate[3].Enabled = Backtester.AmbiguousBars > 0;

            nudGo           = new NumericUpDown();
            nudGo.Parent    = this;
            nudGo.TextAlign = HorizontalAlignment.Center;
            nudGo.BeginInit();
            nudGo.Minimum   = Data.FirstBar + 1;
            nudGo.Maximum   = Data.Bars;
            nudGo.Increment = 1;
            nudGo.Value     = bar + 1;
            nudGo.EndInit();

            btnGo        = new Button();
            btnGo.Parent = this;
            btnGo.Name   = "Go";
            btnGo.Text   = Language.T("Go");
            btnGo.UseVisualStyleBackColor = true;
            btnGo.Click      += new EventHandler(BtnNavigate_Click);
            btnGo.MouseWheel += new MouseEventHandler(Bar_Explorer_MouseWheel);
            toolTip.SetToolTip(btnGo, Language.T("Go to the chosen bar."));

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

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

            brushCaptionBack = new SolidBrush(LayoutColors.ColorCaptionBack);
            brushCaptionText = new SolidBrush(LayoutColors.ColorCaptionText);
            brushEvenRow     = new SolidBrush(LayoutColors.ColorEvenRowBack);
            brushBack        = new SolidBrush(LayoutColors.ColorControlBack);
            brushGridText    = new SolidBrush(LayoutColors.ColorChartFore);
            brushBarWhite    = new SolidBrush(LayoutColors.ColorBarWhite);
            brushBarBlack    = new SolidBrush(LayoutColors.ColorBarBlack);
            brushTradeLong   = new SolidBrush(LayoutColors.ColorTradeLong);
            brushTradeShort  = new SolidBrush(LayoutColors.ColorTradeShort);
            brushTradeClose  = new SolidBrush(LayoutColors.ColorTradeClose);

            penGrid             = new Pen(LayoutColors.ColorChartGrid);
            penGrid.DashStyle   = DashStyle.Dash;
            penGrid.DashPattern = new float[] { 4, 2 };
            penGridSolid        = new Pen(LayoutColors.ColorChartGrid);
            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();

            return;
        }
        /// <summary>
        /// Navigates to a bar.
        /// </summary>
        void Navigate(string sDir)
        {
            switch (sDir)
            {
            case "< !":
                for (int i = bar - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.BackTestEval(i) == "Ambiguous")
                    {
                        bar = i;
                        break;
                    }
                }
                break;

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

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

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

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

            default:
                break;
            }

            SetBtnNavigate();

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

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

            pnlChart.Invalidate(rectPnlChart);

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

            pnlInfo.Invalidate(rectPnlInfo);

            nudGo.Value = bar + 1;

            return;
        }
示例#3
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;
        }
示例#4
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;

            BtnsNavigate = 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++)
            {
                BtnsNavigate[i] = new Button {
                    Parent = this, Text = btnNavigateText[i], Name = btnNavigateText[i]
                };
                BtnsNavigate[i].Click      += BtnNavigateClick;
                BtnsNavigate[i].MouseWheel += BarExplorerMouseWheel;
                BtnsNavigate[i].KeyUp      += BtnNavigateKeyUp;
                BtnsNavigate[i].UseVisualStyleBackColor = true;
                _toolTip.SetToolTip(BtnsNavigate[i], btnNavigateTips[i]);
            }

            BtnsNavigate[0].Enabled = Backtester.AmbiguousBars > 0;
            BtnsNavigate[1].Enabled = Backtester.PositionsTotal > 0;
            BtnsNavigate[4].Enabled = Backtester.PositionsTotal > 0;
            BtnsNavigate[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();
        }
        /// <summary>
        /// Navigates to a bar.
        /// </summary>
        void Navigate(string sDir)
        {
            switch (sDir)
            {
            case "< !":
                for (int i = barCurrent - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.BackTestEval(i) == "Ambiguous")
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case "! >":
                for (int i = barCurrent + 1; i < Data.Bars; i++)
                {
                    if (Backtester.BackTestEval(i) == "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;

            default:
                break;
            }

            SetBtnNavigate();

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

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

            pnlChart.Invalidate(rectPnlChart);

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

            pnlInfo.Invalidate(rectPnlInfo);

            nudGo.Value = barCurrent + 1;

            return;
        }