T() public static method

Language Translation.
public static T ( string phrase ) : string
phrase string
return string
コード例 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Instrument_Editor()
        {
            pnlInstruments   = new Fancy_Panel(Language.T("Instruments"));
            pnlProperties    = new Fancy_Panel(Language.T("Instrument Properties"));
            pnlAddInstrument = new Fancy_Panel(Language.T("Add an Instrument"));

            // Instruments' controls
            lbxInstruments = new ListBox();
            btnDelete      = new Button();
            btnUp          = new Button();
            btnDown        = new Button();

            // Properties' controls
            lblPropSymbol      = new Label();
            lblPropType        = new Label();
            lblPropComment     = new Label();
            lblPropDigits      = new Label();
            lblPropPoint       = new Label();
            lblPropLots        = new Label();
            lblPropSpread      = new Label();
            lblPropSwap        = new Label();
            lblPropCommission  = new Label();
            lblPropSlippage    = new Label();
            lblPropPriceIn     = new Label();
            lblPropAccountIn   = new Label();
            lblPropAccountRate = new Label();
            lblPropFileName    = new Label();
            lblPropDataFiles   = new Label();

            tbxPropSymbol      = new TextBox();
            tbxPropType        = new TextBox();
            tbxPropComment     = new TextBox();
            tbxPropPoint       = new TextBox();
            tbxPropSpread      = new TextBox();
            tbxPropSlippage    = new TextBox();
            tbxPropPriceIn     = new TextBox();
            tbxPropAccountIn   = new TextBox();
            tbxPropAccountRate = new TextBox();
            tbxPropFileName    = new TextBox();

            cbxPropSwap       = new ComboBox();
            cbxPropCommission = new ComboBox();
            cbxPropCommScope  = new ComboBox();
            cbxPropCommTime   = new ComboBox();

            nudPropDigits      = new NumericUpDown();
            nudPropLotSize     = new NumericUpDown();
            nudPropSpread      = new NumericUpDown();
            nudPropSwapLong    = new NumericUpDown();
            nudPropSwapShort   = new NumericUpDown();
            nudPropCommission  = new NumericUpDown();
            nudPropSlippage    = new NumericUpDown();
            nudPropAccountRate = new NumericUpDown();

            btnAccept = new Button();

            // Add an Instrument's controls
            lblAddInstrSymbol = new Label();
            lblAddInstrType   = new Label();
            tbxAddInstrSymbol = new TextBox();
            cbxAddInstrType   = new ComboBox();
            btnAddInstrAdd    = new Button();

            btnClose = new Button();

            font          = this.Font;
            fontCaption   = new Font(Font.FontFamily, 9);
            captionHeight = (float)Math.Max(fontCaption.Height, 18);
            colorText     = LayoutColors.ColorControlText;
            bNeedReset    = false;

            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            Icon            = Data.Icon;
            BackColor       = LayoutColors.ColorFormBack;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            AcceptButton    = btnAccept;
            Text            = Language.T("Instrument Editor");
            FormClosing    += new FormClosingEventHandler(Instrument_Editor_FormClosing);

            // pnlInstruments
            pnlInstruments.Parent = this;

            // pnlProperties
            pnlProperties.Parent = this;

            // pnlAddInstrument
            pnlAddInstrument.Parent = this;

            // lbxInstruments
            lbxInstruments.Parent    = pnlInstruments;
            lbxInstruments.BackColor = LayoutColors.ColorControlBack;
            //lbxInstruments.BorderStyle = BorderStyle.None;
            lbxInstruments.ForeColor = colorText;
            lbxInstruments.Items.AddRange(Instruments.SymbolList);

            // Button UP
            btnUp.Parent = pnlInstruments;
            btnUp.Text   = Language.T("Up");
            btnUp.UseVisualStyleBackColor = true;
            btnUp.Click += new EventHandler(BtnUp_Click);

            // Button Down
            btnDown.Parent = pnlInstruments;
            btnDown.Text   = Language.T("Down");
            btnDown.UseVisualStyleBackColor = true;
            btnDown.Click += new EventHandler(BtnDown_Click);

            // Button Delete
            btnDelete.Parent = pnlInstruments;
            btnDelete.Text   = Language.T("Delete");
            btnDelete.UseVisualStyleBackColor = true;
            btnDelete.Click += new EventHandler(BtnDelete_Click);

            // lblAddInstrSymbol
            lblAddInstrSymbol.Parent    = pnlAddInstrument;
            lblAddInstrSymbol.ForeColor = colorText;
            lblAddInstrSymbol.BackColor = Color.Transparent;
            lblAddInstrSymbol.AutoSize  = false;
            lblAddInstrSymbol.TextAlign = ContentAlignment.MiddleRight;
            lblAddInstrSymbol.Text      = Language.T("Symbol");

            // tbxAddInstrSymbol
            tbxAddInstrSymbol.Parent    = pnlAddInstrument;
            tbxAddInstrSymbol.ForeColor = colorText;

            // lblAddInstrType
            lblAddInstrType.Parent    = pnlAddInstrument;
            lblAddInstrType.ForeColor = colorText;
            lblAddInstrType.BackColor = Color.Transparent;
            lblAddInstrType.AutoSize  = false;
            lblAddInstrType.TextAlign = ContentAlignment.MiddleRight;
            lblAddInstrType.Text      = Language.T("Type");

            // cbxAddInstrType
            cbxAddInstrType.Parent        = pnlAddInstrument;
            cbxAddInstrType.Name          = "cbxAddInstrType";
            cbxAddInstrType.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxAddInstrType.Items.AddRange(Enum.GetNames(typeof(Instrumet_Type)));
            cbxAddInstrType.SelectedIndex = 0;

            // btnAddInstrAdd
            btnAddInstrAdd.Parent = pnlAddInstrument;
            btnAddInstrAdd.Name   = "btnAddInstrAdd";
            btnAddInstrAdd.Text   = Language.T("Add");
            btnAddInstrAdd.UseVisualStyleBackColor = true;
            btnAddInstrAdd.Click += new EventHandler(BtnAddInstrAdd_Click);

            // pnlProperties
            lblPropSymbol.Parent    = pnlProperties;
            lblPropSymbol.ForeColor = colorText;
            lblPropSymbol.BackColor = Color.Transparent;
            lblPropSymbol.AutoSize  = false;
            lblPropSymbol.TextAlign = ContentAlignment.MiddleRight;
            lblPropSymbol.Text      = Language.T("Symbol");

            // lblPropType
            lblPropType.Parent    = pnlProperties;
            lblPropType.ForeColor = colorText;
            lblPropType.BackColor = Color.Transparent;
            lblPropType.AutoSize  = false;
            lblPropType.TextAlign = ContentAlignment.MiddleRight;
            lblPropType.Text      = Language.T("Type");

            // lblPropComment
            lblPropComment.Parent    = pnlProperties;
            lblPropComment.ForeColor = colorText;
            lblPropComment.BackColor = Color.Transparent;
            lblPropComment.AutoSize  = false;
            lblPropComment.TextAlign = ContentAlignment.MiddleRight;
            lblPropComment.Text      = Language.T("Comment");

            // lblPropDigits
            lblPropDigits.Parent    = pnlProperties;
            lblPropDigits.ForeColor = colorText;
            lblPropDigits.BackColor = Color.Transparent;
            lblPropDigits.AutoSize  = false;
            lblPropDigits.TextAlign = ContentAlignment.MiddleRight;
            lblPropDigits.Text      = Language.T("Digits");

            // lblPropPoint
            lblPropPoint.Parent    = pnlProperties;
            lblPropPoint.ForeColor = colorText;
            lblPropPoint.BackColor = Color.Transparent;
            lblPropPoint.AutoSize  = false;
            lblPropPoint.TextAlign = ContentAlignment.MiddleRight;
            lblPropPoint.Text      = Language.T("Point value");

            // lblPropLots
            lblPropLots.Parent    = pnlProperties;
            lblPropLots.ForeColor = colorText;
            lblPropLots.BackColor = Color.Transparent;
            lblPropLots.AutoSize  = false;
            lblPropLots.TextAlign = ContentAlignment.MiddleRight;
            lblPropLots.Text      = Language.T("Lot size");

            // lblPropSpread
            lblPropSpread.Parent    = pnlProperties;
            lblPropSpread.ForeColor = colorText;
            lblPropSpread.BackColor = Color.Transparent;
            lblPropSpread.AutoSize  = false;
            lblPropSpread.TextAlign = ContentAlignment.MiddleRight;
            lblPropSpread.Text      = Language.T("Spread in");

            // lblPropSwap
            lblPropSwap.Parent    = pnlProperties;
            lblPropSwap.ForeColor = colorText;
            lblPropSwap.BackColor = Color.Transparent;
            lblPropSwap.AutoSize  = false;
            lblPropSwap.TextAlign = ContentAlignment.MiddleRight;
            lblPropSwap.Text      = Language.T("Swap in");

            // lblPropCommission
            lblPropCommission.Parent    = pnlProperties;
            lblPropCommission.ForeColor = colorText;
            lblPropCommission.BackColor = Color.Transparent;
            lblPropCommission.AutoSize  = false;
            lblPropCommission.TextAlign = ContentAlignment.MiddleRight;
            lblPropCommission.Text      = Language.T("Commission in");

            // lblPropSlippage
            lblPropSlippage.Parent    = pnlProperties;
            lblPropSlippage.ForeColor = colorText;
            lblPropSlippage.BackColor = Color.Transparent;
            lblPropSlippage.AutoSize  = false;
            lblPropSlippage.TextAlign = ContentAlignment.MiddleRight;
            lblPropSlippage.Text      = Language.T("Slippage in");

            // lblPropPriceIn
            lblPropPriceIn.Parent    = pnlProperties;
            lblPropPriceIn.ForeColor = colorText;
            lblPropPriceIn.BackColor = Color.Transparent;
            lblPropPriceIn.AutoSize  = false;
            lblPropPriceIn.TextAlign = ContentAlignment.MiddleRight;
            lblPropPriceIn.Text      = Language.T("Price in");

            // lblPropAccountIn
            lblPropAccountIn.Parent    = pnlProperties;
            lblPropAccountIn.ForeColor = colorText;
            lblPropAccountIn.BackColor = Color.Transparent;
            lblPropAccountIn.AutoSize  = false;
            lblPropAccountIn.TextAlign = ContentAlignment.MiddleRight;
            lblPropAccountIn.Text      = Language.T("Account in");

            // lblPropAccountRate
            lblPropAccountRate.Parent    = pnlProperties;
            lblPropAccountRate.ForeColor = colorText;
            lblPropAccountRate.BackColor = Color.Transparent;
            lblPropAccountRate.AutoSize  = false;
            lblPropAccountRate.TextAlign = ContentAlignment.MiddleRight;
            lblPropAccountRate.Text      = Language.T("Account exchange rate");

            // lblPropFileName
            lblPropFileName.Parent    = pnlProperties;
            lblPropFileName.BackColor = Color.Transparent;
            lblPropFileName.ForeColor = colorText;
            lblPropFileName.AutoSize  = false;
            lblPropFileName.TextAlign = ContentAlignment.MiddleRight;
            lblPropFileName.Text      = Language.T("Base name of the data files");

            // lblPropDataFiles
            lblPropDataFiles.Parent    = pnlProperties;
            lblPropDataFiles.BackColor = Color.Transparent;
            lblPropDataFiles.ForeColor = colorText;
            lblPropDataFiles.AutoSize  = false;
            lblPropDataFiles.TextAlign = ContentAlignment.TopLeft;
            lblPropDataFiles.Text      = "";

            // tbxPropSymbol
            tbxPropSymbol.Parent    = pnlProperties;
            tbxPropSymbol.BackColor = LayoutColors.ColorControlBack;
            tbxPropSymbol.ForeColor = colorText;
            tbxPropSymbol.Enabled   = false;

            // tbxPropType
            tbxPropType.Parent    = pnlProperties;
            tbxPropType.BackColor = LayoutColors.ColorControlBack;
            tbxPropType.ForeColor = colorText;
            tbxPropType.Enabled   = false;

            // tbxPropComment
            tbxPropComment.Parent    = pnlProperties;
            tbxPropComment.BackColor = LayoutColors.ColorControlBack;
            tbxPropComment.ForeColor = colorText;

            // tbxPropPoint
            tbxPropPoint.Parent    = pnlProperties;
            tbxPropPoint.BackColor = LayoutColors.ColorControlBack;
            tbxPropPoint.ForeColor = colorText;
            tbxPropPoint.Enabled   = false;

            // tbxPropSpread
            tbxPropSpread.Parent    = pnlProperties;
            tbxPropSpread.BackColor = LayoutColors.ColorControlBack;
            tbxPropSpread.ForeColor = colorText;
            tbxPropSpread.Enabled   = false;
            tbxPropSpread.Text      = Language.T("pips");

            // tbxPropSlippage
            tbxPropSlippage.Parent    = pnlProperties;
            tbxPropSlippage.BackColor = LayoutColors.ColorControlBack;
            tbxPropSlippage.ForeColor = colorText;
            tbxPropSlippage.Enabled   = false;
            tbxPropSlippage.Text      = Language.T("pips");

            // tbxPropPriceIn
            tbxPropPriceIn.Parent       = pnlProperties;
            tbxPropPriceIn.BackColor    = LayoutColors.ColorControlBack;
            tbxPropPriceIn.ForeColor    = colorText;
            tbxPropPriceIn.TextChanged += new EventHandler(TbxPropPriceIn_TextChanged);

            // tbxPropAccountIn
            tbxPropAccountIn.Parent    = pnlProperties;
            tbxPropAccountIn.BackColor = LayoutColors.ColorControlBack;
            tbxPropAccountIn.ForeColor = colorText;
            tbxPropAccountIn.Enabled   = false;
            tbxPropAccountIn.Text      = Configs.AccountCurrency;

            // tbxPropAccountRate
            tbxPropAccountRate.Parent    = pnlProperties;
            tbxPropAccountRate.BackColor = LayoutColors.ColorControlBack;
            tbxPropAccountRate.ForeColor = colorText;
            tbxPropAccountRate.Enabled   = false;
            tbxPropAccountRate.Text      = "Deal price";

            // tbxPropFileName
            tbxPropFileName.Parent       = pnlProperties;
            tbxPropFileName.BackColor    = LayoutColors.ColorControlBack;
            tbxPropFileName.ForeColor    = colorText;
            tbxPropFileName.TextChanged += new EventHandler(TbxPropFileName_TextChanged);

            // cbxPropSwap
            cbxPropSwap.Parent        = pnlProperties;
            cbxPropSwap.Name          = "cbxPropSwap";
            cbxPropSwap.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxPropSwap.Items.AddRange(new string[] { Language.T("pips"), Language.T("percents"), Language.T("money") });
            cbxPropSwap.SelectedIndex = 0;

            // cbxPropCommission
            cbxPropCommission.Parent        = pnlProperties;
            cbxPropCommission.Name          = "cbxPropCommission";
            cbxPropCommission.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxPropCommission.Items.AddRange(new string[] { Language.T("pips"), Language.T("percents"), Language.T("money") });
            cbxPropCommission.SelectedIndex         = 0;
            cbxPropCommission.SelectedIndexChanged += new EventHandler(CbxPropCommission_SelectedIndexChanged);

            // cbxPropCommScope
            cbxPropCommScope.Parent        = pnlProperties;
            cbxPropCommScope.Name          = "cbxPropCommScope";
            cbxPropCommScope.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxPropCommScope.Items.AddRange(new string[] { Language.T("per lot"), Language.T("per deal") });
            cbxPropCommScope.SelectedIndex = 0;

            // cbxPropCommTime
            cbxPropCommTime.Parent        = pnlProperties;
            cbxPropCommTime.Name          = "cbxPropCommTime";
            cbxPropCommTime.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxPropCommTime.Items.AddRange(new string[] { Language.T("at opening"), Language.T("at open/close") });
            cbxPropCommTime.SelectedIndex = 0;

            // NumericUpDown Digits
            nudPropDigits.BeginInit();
            nudPropDigits.Parent        = pnlProperties;
            nudPropDigits.Name          = "nudPropDigits";
            nudPropDigits.Minimum       = 0;
            nudPropDigits.Maximum       = 5;
            nudPropDigits.Increment     = 1;
            nudPropDigits.Value         = 4;
            nudPropDigits.TextAlign     = HorizontalAlignment.Center;
            nudPropDigits.ValueChanged += new EventHandler(NudPropDigits_ValueChanged);
            nudPropDigits.EndInit();

            // nudPropLotSize
            nudPropLotSize.BeginInit();
            nudPropLotSize.Parent    = pnlProperties;
            nudPropLotSize.Name      = "nudPropLotSize";
            nudPropLotSize.Minimum   = 0;
            nudPropLotSize.Maximum   = 100000;
            nudPropLotSize.Increment = 1;
            nudPropLotSize.Value     = 10000;
            nudPropLotSize.TextAlign = HorizontalAlignment.Center;
            nudPropLotSize.EndInit();

            // nudPropSpread
            nudPropSpread.BeginInit();
            nudPropSpread.Parent        = pnlProperties;
            nudPropSpread.Name          = "nudPropSpread";
            nudPropSpread.TextAlign     = HorizontalAlignment.Center;
            nudPropSpread.Minimum       = 0;
            nudPropSpread.Maximum       = 500;
            nudPropSpread.Increment     = 0.01M;
            nudPropSpread.DecimalPlaces = 2;
            nudPropSpread.Value         = 4;
            nudPropSpread.EndInit();
            toolTip.SetToolTip(nudPropSpread, Language.T("Difference between Bid and Ask prices."));

            // NumericUpDown Swap Long
            nudPropSwapLong.BeginInit();
            nudPropSwapLong.Parent        = pnlProperties;
            nudPropSwapLong.Name          = "nudPropSwapLong";
            nudPropSwapLong.TextAlign     = HorizontalAlignment.Center;
            nudPropSwapLong.Minimum       = -500;
            nudPropSwapLong.Maximum       = 500;
            nudPropSwapLong.Increment     = 0.01M;
            nudPropSwapLong.DecimalPlaces = 2;
            nudPropSwapLong.Value         = 1;
            nudPropSwapLong.EndInit();
            toolTip.SetToolTip(nudPropSwapLong, Language.T("Swap number for a long position rollover") + Environment.NewLine + Language.T("A positive value decreases your profit."));

            // NumericUpDown Swap Short
            nudPropSwapShort.BeginInit();
            nudPropSwapShort.Parent        = pnlProperties;
            nudPropSwapShort.Name          = "nudPropSwapShort";
            nudPropSwapShort.TextAlign     = HorizontalAlignment.Center;
            nudPropSwapShort.Minimum       = -500;
            nudPropSwapShort.Maximum       = 500;
            nudPropSwapShort.Increment     = 0.01M;
            nudPropSwapShort.DecimalPlaces = 2;
            nudPropSwapShort.Value         = -1;
            nudPropSwapShort.EndInit();
            toolTip.SetToolTip(nudPropSwapShort, Language.T("Swap number for a short position rollover") + Environment.NewLine + Language.T("A negative value decreases your profit."));

            // NumericUpDown nudPropCommission
            nudPropCommission.BeginInit();
            nudPropCommission.Parent        = pnlProperties;
            nudPropCommission.Name          = "nudPropCommission";
            nudPropCommission.TextAlign     = HorizontalAlignment.Center;
            nudPropCommission.Minimum       = -500;
            nudPropCommission.Maximum       = 500;
            nudPropCommission.Increment     = 0.01M;
            nudPropCommission.DecimalPlaces = 2;
            nudPropCommission.Value         = 0;
            nudPropCommission.EndInit();

            // NumericUpDown nudPropSlippage
            nudPropSlippage.BeginInit();
            nudPropSlippage.Parent        = pnlProperties;
            nudPropSlippage.Name          = "nudPropSlippage";
            nudPropSlippage.TextAlign     = HorizontalAlignment.Center;
            nudPropSlippage.Minimum       = 0;
            nudPropSlippage.Maximum       = 200;
            nudPropSlippage.Increment     = 1;
            nudPropSlippage.DecimalPlaces = 0;
            nudPropSlippage.Value         = 0;
            nudPropSlippage.EndInit();
            toolTip.SetToolTip(nudPropSlippage, Language.T("Number of pips you lose due to an inaccurate order execution."));

            // NumericUpDown nudPropAccountRate
            nudPropAccountRate.BeginInit();
            nudPropAccountRate.Parent        = pnlProperties;
            nudPropAccountRate.Name          = "nudPropAccountRate";
            nudPropAccountRate.TextAlign     = HorizontalAlignment.Center;
            nudPropAccountRate.Minimum       = 0;
            nudPropAccountRate.Maximum       = 100000;
            nudPropAccountRate.Increment     = 0.0001M;
            nudPropAccountRate.DecimalPlaces = 4;
            nudPropAccountRate.Value         = 1;
            nudPropAccountRate.ValueChanged += new EventHandler(nudPropAccountRate_ValueChanged);
            nudPropAccountRate.EndInit();

            // Button Accept
            btnAccept.Parent = pnlProperties;
            btnAccept.Name   = "btnAccept";
            btnAccept.Text   = Language.T("Accept");
            btnAccept.Click += new EventHandler(BtnAccept_Click);
            btnAccept.UseVisualStyleBackColor = true;

            //Button Close
            btnClose.Parent                  = this;
            btnClose.Text                    = Language.T("Close");
            btnClose.DialogResult            = DialogResult.Cancel;
            btnClose.UseVisualStyleBackColor = true;
        }
コード例 #2
0
        /// <summary>
        /// Paints panel pnlChart
        /// </summary>
        private void PnlChartPaint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.Clear(LayoutColors.ColorChartBack);

            if (!Data.IsData || !Data.IsResult)
            {
                return;
            }

            var pnl   = (Panel)sender;
            int width = pnl.ClientSize.Width;

            // Caption background
            var   pntStart     = new PointF(0, 0);
            SizeF szfCaption   = new Size(width, _infoRowHeight);
            var   rectfCaption = new RectangleF(pntStart, szfCaption);

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

            // Caption Text
            var stringFormat = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Center
            };
            string stringCaptionText = Language.T("Price Route Inside the Bar");

            rectfCaption = new RectangleF(Border, 0, pnl.ClientSize.Width - 2 * Border, _infoRowHeight);
            g.DrawString(stringCaptionText, _fontInfo, _brushCaptionText, rectfCaption, stringFormat);

            // Paint the panel background
            var rectClient = new RectangleF(0, _infoRowHeight, pnl.ClientSize.Width, pnl.Height - _infoRowHeight);

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

            // Paint bar info
            var rectBarInfo = new RectangleF(Border, _infoRowHeight + 1, pnl.ClientSize.Width - 2 * Border, _infoRowHeight);

            g.DrawString(_barInfo, _fontInfo, _brushGridText, rectBarInfo, stringFormat);

            // Searching the min and the max price and volume
            width = pnl.ClientSize.Width - 2 * Border;
            double    maxPrice  = Data.High[_barCurrent];
            double    minPrice  = Data.Low[_barCurrent];
            const int space     = 8;
            int       spcRight  = _szPrice.Width + 4;
            const int xLeft     = Border + space;
            int       xRight    = width - spcRight;
            int       yTop      = 2 * _infoRowHeight + 6;
            int       yBottom   = pnl.ClientSize.Height - 22;
            int       barPixels = _maxWayPoints < 10 ? 28 : _maxWayPoints < 15 ? 24 : 20;
            const int spcLeft   = 3;
            int       x         = barPixels + spcLeft;

            int       pointLeft   = x + barPixels + 30;
            int       pointRight  = xRight - 20;
            int       points      = Backtester.WayPoints(_barCurrent);
            const int pointRadius = 3;

            // Grid
            var    iCntLabels = (int)Math.Max((yBottom - yTop) / 30d, 1);
            double deltaPoint = (Data.InstrProperties.Digits == 5 || Data.InstrProperties.Digits == 3)
                                    ? Data.InstrProperties.Point * 100
                                    : Data.InstrProperties.Point * 10;
            double delta =
                Math.Max(Math.Round((maxPrice - minPrice) / iCntLabels, Data.InstrProperties.Point < 0.001 ? 3 : 1),
                         deltaPoint);

            minPrice   = Math.Round(minPrice, Data.InstrProperties.Point < 0.001f ? 3 : 1) - Data.InstrProperties.Point * 10;
            minPrice  -= delta;
            maxPrice  += delta;
            iCntLabels = (int)Math.Ceiling((maxPrice - minPrice) / delta);
            maxPrice   = minPrice + iCntLabels * delta;

            double scaleY = (yBottom - yTop) / (iCntLabels * delta);
            var    yOpen  = (int)(yBottom - (Data.Open[_barCurrent] - minPrice) * scaleY);
            var    yHigh  = (int)(yBottom - (Data.High[_barCurrent] - minPrice) * scaleY);
            var    yLow   = (int)(yBottom - (Data.Low[_barCurrent] - minPrice) * scaleY);
            var    yClose = (int)(yBottom - (Data.Close[_barCurrent] - minPrice) * scaleY);

            // Find the price distance
            double priceDistance = 0;

            for (int point = 1; point < points; point++)
            {
                priceDistance +=
                    Math.Abs(Backtester.WayPoint(_barCurrent, point).Price -
                             Backtester.WayPoint(_barCurrent, point - 1).Price);
            }
            double dPriceForAPixel = (pointRight - pointLeft) / priceDistance;

            // Points X
            var aiPointX = new int[points];

            aiPointX[0] = pointLeft;
            for (int point = 1; point < points - 1; point++)
            {
                var iDistance =
                    (int)
                    (Math.Abs(Backtester.WayPoint(_barCurrent, point).Price -
                              Backtester.WayPoint(_barCurrent, point - 1).Price) * dPriceForAPixel);
                aiPointX[point] = aiPointX[point - 1] + iDistance;
            }
            aiPointX[points - 1] = pointRight;
            for (int point = 1; point < points - 1; point++)
            {
                if (aiPointX[point] - aiPointX[point - 1] < barPixels + 1)
                {
                    aiPointX[point] = aiPointX[point - 1] + barPixels + 1;
                }
            }
            for (int point = points - 2; point > 0; point--)
            {
                if (aiPointX[point + 1] - aiPointX[point] < barPixels + 1)
                {
                    aiPointX[point] = aiPointX[point + 1] - barPixels - 1;
                }
            }

            // Find coordinates of the Way Points
            var pntWay = new Point[points];

            for (int point = 0; point < points; point++)
            {
                var pointY = (int)(yBottom - (Backtester.WayPoint(_barCurrent, point).Price - minPrice) * scaleY);
                pntWay[point] = new Point(aiPointX[point], pointY);
            }

            // Horizontal grid and Price labels
            for (double label = minPrice; label <= maxPrice + Data.InstrProperties.Point; label += delta)
            {
                var labelY = (int)(yBottom - (label - minPrice) * scaleY);
                g.DrawString(label.ToString(Data.FF), Font, _brushGridText, xRight, labelY - Font.Height / 2 - 1);
                g.DrawLine(_penGrid, Border + space, labelY, xRight, labelY);
            }

            // Vertical Grid
            g.DrawLine(_penGrid, x + barPixels / 2 - 1, yTop, x + barPixels / 2 - 1, yBottom + 2);
            for (int point = 0; point < points; point++)
            {
                var pt1 = new Point(pntWay[point].X, yTop);
                var pt2 = new Point(pntWay[point].X, yBottom + 2);
                var pt3 = new Point(pntWay[point].X - 5, yBottom + 4);
                g.DrawLine(_penGrid, pt1, pt2);
                g.DrawString((point + 1).ToString(CultureInfo.InvariantCulture), Font, _brushGridText, pt3);
            }

            // Bar Number
            string barNumber = (_barCurrent + 1).ToString(CultureInfo.InvariantCulture);
            int    stringX   = x + barPixels / 2 - 1 - g.MeasureString(barNumber, Font).ToSize().Width / 2;
            Brush  barBrush  = Backtester.BackTestEval(_barCurrent) == BacktestEval.Ambiguous ? _brushRed : _brushGridText;

            g.DrawString(barNumber, Font, barBrush, stringX, yBottom + 4);

            // Draw the bar
            g.DrawLine(_penBarBorder, x + barPixels / 2 - 1, yLow, x + barPixels / 2 - 1, yHigh);
            if (yClose < yOpen) // White bar
            {
                var rect    = new Rectangle(x, yClose, barPixels - 2, yOpen - yClose);
                var lgBrush = new LinearGradientBrush(rect, _colorBarWight1, _colorBarWight2, 5f);
                g.FillRectangle(lgBrush, rect);
                g.DrawRectangle(_penBarBorder, x, yClose, barPixels - 2, yOpen - yClose);
            }
            else if (yClose > yOpen) // Black bar
            {
                var rect    = new Rectangle(x, yOpen, barPixels - 2, yClose - yOpen);
                var lgBrush = new LinearGradientBrush(rect, _colorBarBlack1, _colorBarBlack2, 5f);
                g.FillRectangle(lgBrush, rect);
                g.DrawRectangle(_penBarBorder, x, yOpen, barPixels - 2, yClose - yOpen);
            }
            else // Cross
            {
                g.DrawLine(_penBarBorder, x, yClose, x + barPixels - 2, yClose);
            }

            // Draw cancelled orders
            for (int orderIndex = 0; orderIndex < Backtester.Orders(_barCurrent); orderIndex++)
            {
                int   ordNumber = Backtester.OrdNumb(_barCurrent, orderIndex);
                Order order     = Backtester.OrdFromNumb(ordNumber);
                if (order.OrdStatus != OrderStatus.Cancelled)
                {
                    continue;
                }

                if (order.OrdPrice > Data.High[_barCurrent] || order.OrdPrice < Data.Low[_barCurrent])
                {
                    continue;
                }

                int d     = barPixels / 2 - 1;
                int x1    = x + d;
                int x2    = x + barPixels - 2;
                var yDeal = (int)(yBottom - (order.OrdPrice - minPrice) * scaleY);
                var pen   = new Pen(LayoutColors.ColorChartGrid, 2);

                if (order.OrdDir == OrderDirection.Buy)
                {
                    g.DrawLine(pen, x, yDeal, x1, yDeal);
                    g.DrawLine(pen, x1, yDeal, x2, yDeal - d);
                    g.DrawLine(pen, x2 + 1, yDeal - d + 1, x1 + d / 2 + 1, yDeal - d + 1);
                    g.DrawLine(pen, x2, yDeal - d, x2, yDeal - d / 2);
                }
                else if (order.OrdDir == OrderDirection.Sell)
                {
                    g.DrawLine(pen, x, yDeal + 1, x1 + 1, yDeal + 1);
                    g.DrawLine(pen, x1, yDeal, x2, yDeal + d);
                    g.DrawLine(pen, x1 + d / 2 + 1, yDeal + d, x2, yDeal + d);
                    g.DrawLine(pen, x2, yDeal + d, x2, yDeal + d / 2 + 1);
                }
            }

            // Draw the deals on the bar
            for (int pos = 0; pos < Backtester.Positions(_barCurrent); pos++)
            {
                if (Backtester.PosTransaction(_barCurrent, pos) == Transaction.Transfer)
                {
                    continue;
                }

                var yDeal = (int)(yBottom - (Backtester.PosOrdPrice(_barCurrent, pos) - minPrice) * scaleY);

                if (Backtester.PosDir(_barCurrent, pos) == PosDirection.Long ||
                    Backtester.PosDir(_barCurrent, pos) == PosDirection.Short)
                {
                    int d  = barPixels / 2 - 1;
                    int x1 = x + d;
                    int x2 = x + barPixels - 2;
                    if (Backtester.OrdFromNumb(Backtester.PosOrdNumb(_barCurrent, pos)).OrdDir == OrderDirection.Buy)
                    {
                        // Buy
                        var pen = new Pen(LayoutColors.ColorTradeLong, 2);
                        g.DrawLine(pen, x, yDeal, x1, yDeal);
                        g.DrawLine(pen, x1, yDeal, x2, yDeal - d);
                        g.DrawLine(pen, x2 + 1, yDeal - d + 1, x1 + d / 2 + 1, yDeal - d + 1);
                        g.DrawLine(pen, x2, yDeal - d, x2, yDeal - d / 2);
                    }
                    else
                    {
                        // Sell
                        var pen = new Pen(LayoutColors.ColorTradeShort, 2);
                        g.DrawLine(pen, x, yDeal + 1, x1 + 1, yDeal + 1);
                        g.DrawLine(pen, x1, yDeal, x2, yDeal + d);
                        g.DrawLine(pen, x1 + d / 2 + 1, yDeal + d, x2, yDeal + d);
                        g.DrawLine(pen, x2, yDeal + d, x2, yDeal + d / 2 + 1);
                    }
                }
                else if (Backtester.PosDir(_barCurrent, pos) == PosDirection.Closed)
                {
                    // Close position
                    int d   = barPixels / 2 - 1;
                    int x1  = x + d;
                    int x2  = x + barPixels - 3;
                    var pen = new Pen(LayoutColors.ColorTradeClose, 2);
                    g.DrawLine(pen, x, yDeal, x1, yDeal);
                    g.DrawLine(pen, x1, yDeal + d / 2, x2, yDeal - d / 2);
                    g.DrawLine(pen, x1, yDeal - d / 2, x2, yDeal + d / 2);
                }
            }

            // Draw position lots
            for (int point = 0; point < points; point++)
            {
                int posNumber = Backtester.WayPoint(_barCurrent, point).PosNumb;
                if (posNumber == -1)
                {
                    continue;
                }

                Position     position     = Backtester.PosFromNumb(posNumber);
                double       posLots      = position.PosLots;
                PosDirection posDirection = position.PosDir;
                WayPointType wpType       = Backtester.WayPoint(_barCurrent, point).WPType;

                var hight  = (int)(Math.Max(posLots * 2, 2));
                int lenght = barPixels;
                int posX   = pntWay[point].X - (barPixels - 1) / 2;
                int posY   = yBottom - hight;

                if (point < points - 1)
                {
                    lenght = pntWay[point + 1].X - pntWay[point].X + 1;
                }

                if (posDirection == PosDirection.Long)
                {
                    // Long
                    var rect    = new Rectangle(posX - 1, posY - 1, lenght, hight + 2);
                    var lgBrush = new LinearGradientBrush(rect, _colorLongTrade1, _colorLongTrade2,
                                                          LinearGradientMode.Vertical);
                    rect = new Rectangle(posX - 1, posY, lenght, hight);
                    g.FillRectangle(lgBrush, rect);
                }
                else if (posDirection == PosDirection.Short)
                {
                    // Short
                    var rect    = new Rectangle(posX - 1, posY - 1, lenght, hight + 2);
                    var lgBrush = new LinearGradientBrush(rect, _colorShortTrade1, _colorShortTrade2,
                                                          LinearGradientMode.Vertical);
                    rect = new Rectangle(posX - 1, posY, lenght, hight);
                    g.FillRectangle(lgBrush, rect);
                }
                else if (posDirection == PosDirection.Closed && wpType == WayPointType.Exit)
                {
                    // Closed
                    var rect    = new Rectangle(posX - 1, yBottom - 2, barPixels + 1, 2);
                    var lgBrush = new LinearGradientBrush(rect, _colorClosedTrade1, _colorClosedTrade2,
                                                          LinearGradientMode.Vertical);
                    rect = new Rectangle(posX, yBottom - 2, barPixels - 1, 2);
                    g.FillRectangle(lgBrush, rect);
                }
            }

            // Draw the Beziers
            for (int point = 1; point < points; point++)
            {
                Point ptKnot1 = pntWay[point - 1];
                Point ptKnot2 = pntWay[point];

                int ctrlX1 = (ptKnot1.X + ptKnot2.X) / 2;
                int ctrlX2 = (ptKnot1.X + ptKnot2.X) / 2;

                int ctrlY1 = ptKnot1.Y;
                int ctrlY2 = ptKnot2.Y;

                if (point > 1)
                {
                    if (pntWay[point - 2].Y > pntWay[point - 1].Y && pntWay[point - 1].Y > pntWay[point].Y ||
                        pntWay[point - 2].Y < pntWay[point - 1].Y && pntWay[point - 1].Y < pntWay[point].Y)
                    {
                        ctrlY1 = (pntWay[point - 1].Y + pntWay[point].Y) / 2;
                    }
                }
                if (point < points - 1)
                {
                    if (pntWay[point - 1].Y > pntWay[point].Y && pntWay[point].Y > pntWay[point + 1].Y ||
                        pntWay[point - 1].Y < pntWay[point].Y && pntWay[point].Y < pntWay[point + 1].Y)
                    {
                        ctrlY2 = (pntWay[point - 1].Y + pntWay[point].Y) / 2;
                    }
                }

                if (point == 1)
                {
                    ctrlX1 = ptKnot1.X;
                    ctrlY1 = ptKnot1.Y;
                }
                if (point == points - 1)
                {
                    ctrlX2 = ptKnot2.X;
                    ctrlY2 = ptKnot2.Y;
                }

                var ptControl1 = new Point(ctrlX1, ctrlY1);
                var ptControl2 = new Point(ctrlX2, ctrlY2);

                g.DrawBezier(_penCross, ptKnot1, ptControl1, ptControl2, ptKnot2);
            }

            // Draw the WayPoints
            Brush brushWeyPnt = new SolidBrush(LayoutColors.ColorChartBack);

            for (int point = 0; point < points; point++)
            {
                g.FillEllipse(brushWeyPnt, pntWay[point].X - pointRadius, pntWay[point].Y - pointRadius, 2 * pointRadius,
                              2 * pointRadius);
                g.DrawEllipse(_penCross, pntWay[point].X - pointRadius, pntWay[point].Y - pointRadius, 2 * pointRadius,
                              2 * pointRadius);
            }

            // Draw O, H, L, C labels
            for (int point = 0; point < points; point++)
            {
                WayPointType wpType = Backtester.WayPoint(_barCurrent, point).WPType;
                if (wpType != WayPointType.Open && wpType != WayPointType.High &&
                    wpType != WayPointType.Low && wpType != WayPointType.Close)
                {
                    continue;
                }

                string label = "?";
                switch (wpType)
                {
                case WayPointType.Open:
                    label = "O";
                    break;

                case WayPointType.High:
                    label = "H";
                    break;

                case WayPointType.Low:
                    label = "L";
                    break;

                case WayPointType.Close:
                    label = "C";
                    break;
                }

                int xPoint = pntWay[point].X;
                int yPoint = pntWay[point].Y - Font.Height - 3;

                var stringFormatLabel = new StringFormat {
                    Alignment = StringAlignment.Center
                };
                g.DrawString(label, Font, _brushGridText, xPoint, yPoint, stringFormatLabel);
            }

            // Draw the deals on the route
            for (int point = 0; point < points; point++)
            {
                int posNumber = Backtester.WayPoint(_barCurrent, point).PosNumb;
                int ordNumber = Backtester.WayPoint(_barCurrent, point).OrdNumb;

                if (posNumber < 0 || ordNumber < 0)
                {
                    continue;
                }

                PosDirection   posDirection = Backtester.PosFromNumb(posNumber).PosDir;
                OrderDirection ordDirection = Backtester.OrdFromNumb(ordNumber).OrdDir;
                WayPointType   wpType       = Backtester.WayPoint(_barCurrent, point).WPType;

                if (wpType == WayPointType.None || wpType == WayPointType.Open || wpType == WayPointType.High ||
                    wpType == WayPointType.Low || wpType == WayPointType.Close)
                {
                    continue;
                }

                int yDeal = pntWay[point].Y;

                if (posDirection == PosDirection.Long || posDirection == PosDirection.Short ||
                    wpType == WayPointType.Cancel)
                {
                    int d = barPixels / 2 - 1;
                    x = pntWay[point].X - d;
                    int x1 = pntWay[point].X;
                    int x2 = x + barPixels - 2;
                    if (ordDirection == OrderDirection.Buy)
                    {
                        // Buy
                        var pen = new Pen(LayoutColors.ColorTradeLong, 2);
                        if (wpType == WayPointType.Cancel)
                        {
                            pen = new Pen(LayoutColors.ColorChartGrid, 2);
                        }
                        g.DrawLine(pen, x, yDeal, x1, yDeal);
                        g.DrawLine(pen, x1, yDeal, x2, yDeal - d);
                        g.DrawLine(pen, x2 + 1, yDeal - d + 1, x1 + d / 2 + 1, yDeal - d + 1);
                        g.DrawLine(pen, x2, yDeal - d, x2, yDeal - d / 2);
                    }
                    else
                    {
                        // Sell
                        var pen = new Pen(LayoutColors.ColorTradeShort, 2);
                        if (wpType == WayPointType.Cancel)
                        {
                            pen = new Pen(LayoutColors.ColorChartGrid, 2);
                        }
                        g.DrawLine(pen, x, yDeal + 1, x1 + 1, yDeal + 1);
                        g.DrawLine(pen, x1, yDeal, x2, yDeal + d);
                        g.DrawLine(pen, x1 + d / 2 + 1, yDeal + d, x2, yDeal + d);
                        g.DrawLine(pen, x2, yDeal + d, x2, yDeal + d / 2 + 1);
                    }
                }

                if (posDirection == PosDirection.Closed)
                {
                    // Close position
                    int d = barPixels / 2 - 1;
                    x = pntWay[point].X - d;
                    int x1  = pntWay[point].X;
                    int x2  = x + barPixels - 3;
                    var pen = new Pen(LayoutColors.ColorTradeClose, 2);
                    g.DrawLine(pen, x, yDeal, x1, yDeal);
                    g.DrawLine(pen, x1, yDeal + d / 2, x2, yDeal - d / 2);
                    g.DrawLine(pen, x1, yDeal - d / 2, x2, yDeal + d / 2);
                }
            }

            // Coordinate axes
            g.DrawLine(_penAxes, xLeft, yTop - 4, xLeft, yBottom); // Vertical left line
            g.DrawLine(_penAxes, xLeft, yBottom, xRight, yBottom);

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

            g.DrawLine(penBorder, 1, _infoRowHeight, 1, pnl.ClientSize.Height);
            g.DrawLine(penBorder, pnl.ClientSize.Width - Border + 1, _infoRowHeight, pnl.ClientSize.Width - Border + 1,
                       pnl.ClientSize.Height);
            g.DrawLine(penBorder, 0, pnl.ClientSize.Height - Border + 1, pnl.ClientSize.Width,
                       pnl.ClientSize.Height - Border + 1);
        }
コード例 #3
0
        /// <summary>
        /// Paints panel pnlOptions
        /// </summary>
        private void PnlOptionsPaint(object sender, PaintEventArgs e)
        {
            var       pnl    = (Panel)sender;
            Graphics  g      = e.Graphics;
            const int border = 2;

            // Chart Title
            string str                 = Language.T("Interpolation Methods");
            var    font                = new Font(Font.FontFamily, 9);
            var    fCaptionHeight      = (float)Math.Max(font.Height, 18);
            var    rectfCaption        = new RectangleF(0, 0, pnl.ClientSize.Width, fCaptionHeight);
            var    stringFormatCaption = new StringFormat
            {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
            };

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(str, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectfCaption, stringFormatCaption);

            // Paint the panel background
            var rectClient = new RectangleF(border, fCaptionHeight, pnl.ClientSize.Width - 2 * border,
                                            pnl.Height - fCaptionHeight - border);

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

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

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

            int       positionX = (PnlOptions.ClientSize.Width - 10) / 3;
            const int positionY = 35;
            int       num       = 0;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (num < _countMethods)
                    {
                        var pt1 = new Point(j * positionX + 10, i * 30 + positionY);
                        var pt2 = new Point(j * positionX + 30, i * 30 + positionY);
                        var pen = new Pen(Color.Red);
                        switch ((InterpolationMethod)AchboxMethods[num].Tag)
                        {
                        case InterpolationMethod.Pessimistic:
                            pen = new Pen(LayoutColors.ComparatorChartPessimisticLine);
                            break;

                        case InterpolationMethod.Shortest:
                            pen = new Pen(LayoutColors.ComparatorChartShortestLine);
                            break;

                        case InterpolationMethod.Nearest:
                            pen = new Pen(LayoutColors.ComparatorChartNearestLine);
                            break;

                        case InterpolationMethod.Optimistic:
                            pen = new Pen(LayoutColors.ComparatorChartOptimisticLine);
                            break;

                        case InterpolationMethod.Random:
                            var   pntRnd1  = new Point(j * positionX + 10, i * 30 + positionY - 6);
                            var   pntRnd2  = new Point(j * positionX + 30, i * 30 + positionY - 6);
                            var   pntRnd3  = new Point(j * positionX + 10, i * 30 + positionY + 6);
                            var   pntRnd4  = new Point(j * positionX + 30, i * 30 + positionY + 6);
                            var   penRnd   = new Pen(LayoutColors.ComparatorChartRandomBands, 2);
                            Brush brushRnd = new SolidBrush(LayoutColors.ComparatorChartRandomArea);
                            g.FillRectangle(brushRnd,
                                            new Rectangle(pntRnd1.X, pntRnd1.Y, pntRnd2.X - pntRnd1.X,
                                                          pntRnd4.Y - pntRnd2.Y));
                            g.DrawLine(penRnd, pntRnd1, pntRnd2);
                            g.DrawLine(penRnd, pntRnd3, pntRnd4);
                            pen = new Pen(LayoutColors.ComparatorChartRandomLine);
                            break;
                        }
                        pen.Width = 2;
                        g.DrawLine(pen, pt1, pt2);
                    }
                    else
                    {
                        var pt1 = new Point(j * positionX + 10, i * 30 + positionY);
                        var pt2 = new Point(j * positionX + 30, i * 30 + positionY);
                        var pen = new Pen(LayoutColors.ComparatorChartBalanceLine)
                        {
                            Width = 3
                        };
                        g.DrawLine(pen, pt1, pt2);
                    }

                    num++;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Paints panel pnlInfo
        /// </summary>
        private void PnlInfoPaint(object sender, PaintEventArgs e)
        {
            // ---------------------------------------------------------------------+
            // |                          Way points description                    |
            // |--------------------------------------------------------------------+
            // | Number | Description | Price | Direction | Lots | Position | Order |
            // |--------------------------------------------------------------------+
            //xp0      xp1           xp2     xp3         xp4    xp5        xp6     xp7

            Graphics g = e.Graphics;

            g.Clear(LayoutColors.ColorControlBack);

            if (!Data.IsData || !Data.IsResult)
            {
                return;
            }

            var    pnl  = (Panel)sender;
            string ff   = Data.FF; // Format modifier to print the floats
            var    size = new Size(_aiX[_columns] - _aiX[0], _infoRowHeight);
            var    sf   = new StringFormat {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near
            };

            // Caption background
            var   pntStart     = new PointF(0, 0);
            SizeF szfCaption   = new Size(pnl.ClientSize.Width, 2 * _infoRowHeight);
            var   rectfCaption = new RectangleF(pntStart, szfCaption);

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

            // Caption Text
            var stringFormat = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Near
            };
            string stringCaptionText = Language.T("Way Points Description");
            float  captionWidth      = Math.Min(_pnlInfo.ClientSize.Width, _aiX[_columns] - _aiX[0]);
            float  fCaptionTextWidth = g.MeasureString(stringCaptionText, _fontInfo).Width;
            float  fCaptionTextX     = Math.Max((captionWidth - fCaptionTextWidth) / 2f, 0);
            var    pfCaptionText     = new PointF(fCaptionTextX, 0);
            var    sfCaptionText     = new SizeF(captionWidth - fCaptionTextX, _infoRowHeight);

            rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);

            // First caption raw
            g.DrawString(stringCaptionText, _fontInfo, _brushCaptionText, rectfCaption, stringFormat);

            // Second caption raw
            for (int i = 0; i < _columns; i++)
            {
                g.DrawString(_asTitles[i], _fontInfo, _brushCaptionText, (_aiX[i] + _aiX[i + 1]) / 2f, _infoRowHeight, sf);
            }

            Brush brush = new SolidBrush(LayoutColors.ColorControlText);

            for (int pnt = 0; pnt < Backtester.WayPoints(_barCurrent); pnt++)
            {
                int y     = (pnt + 2) * _infoRowHeight;
                var point = new Point(_aiX[0], y);

                // Even row
                if (Math.Abs(pnt % 2f - 0) > 0.00001)
                {
                    g.FillRectangle(_brushEvenRow, new Rectangle(point, size));
                }

                int          positionNumber = Backtester.WayPoint(_barCurrent, pnt).PosNumb;
                WayPointType wpType         = Backtester.WayPoint(_barCurrent, pnt).WPType;
                PosDirection posDirection   = Backtester.PosFromNumb(positionNumber).PosDir;
                double       posLots        = Backtester.PosFromNumb(positionNumber).PosLots;
                int          ordNumber      = Backtester.WayPoint(_barCurrent, pnt).OrdNumb;

                g.DrawString((pnt + 1).ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (_aiX[0] + _aiX[1]) / 2f,
                             y, sf);
                g.DrawString(Language.T(WayPoint.WPTypeToString(wpType)), _fontInfo, brush, _aiX[1] + 2, y);
                g.DrawString(Backtester.WayPoint(_barCurrent, pnt).Price.ToString(ff), _fontInfo, brush,
                             (_aiX[3] + _aiX[2]) / 2f, y, sf);

                if (positionNumber > -1)
                {
                    g.DrawString(Language.T(posDirection.ToString()), _fontInfo, brush, (_aiX[4] + _aiX[3]) / 2f, y, sf);
                    g.DrawString(posLots.ToString(CultureInfo.InvariantCulture), _fontInfo, brush,
                                 (_aiX[5] + _aiX[4]) / 2f, y, sf);
                    g.DrawString((positionNumber + 1).ToString(CultureInfo.InvariantCulture), _fontInfo, brush,
                                 (_aiX[6] + _aiX[5]) / 2f, y, sf);
                }

                if (ordNumber > -1)
                {
                    g.DrawString((ordNumber + 1).ToString(CultureInfo.InvariantCulture), _fontInfo, brush,
                                 (_aiX[7] + _aiX[6]) / 2f, y, sf);
                }
            }

            // Vertical lines
            var penLine = new Pen(LayoutColors.ColorJournalLines);

            for (int i = 1; i < _columns; i++)
            {
                g.DrawLine(penLine, _aiX[i], 2 * _infoRowHeight, _aiX[i], ClientSize.Height - Border);
            }

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

            g.DrawLine(penBorder, 1, 2 * _infoRowHeight, 1, pnl.ClientSize.Height);
            g.DrawLine(penBorder, pnl.ClientSize.Width - Border + 1, 2 * _infoRowHeight, pnl.ClientSize.Width - Border + 1,
                       pnl.ClientSize.Height);
            g.DrawLine(penBorder, 0, pnl.ClientSize.Height - Border + 1, pnl.ClientSize.Width,
                       pnl.ClientSize.Height - Border + 1);
        }
コード例 #5
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;
        }
コード例 #6
0
        /// <summary>
        /// Loads the Intrabar data.
        /// </summary>
        private int LoadIntrabarData(DataPeriods period)
        {
            var instrument = new Instrument(Data.InstrProperties.Clone(), (int)period)
            {
                DataDir = Data.OfflineDataDir,
                MaxBars = Configs.MaxIntraBars
            };


            // Loads the data
            int loadingResult   = instrument.LoadData();
            int loadedIntrabars = instrument.Bars;

            if (loadingResult == 0 && loadedIntrabars > 0)
            {
                if (Data.Period != DataPeriods.week)
                {
                    if (instrument.DaysOff > 5)
                    {
                        _warningMessage += Environment.NewLine + Language.T("Data for:") + " " + Data.Symbol + " " +
                                           Data.DataPeriodToString(period) + " - " + Language.T("Maximum days off:") +
                                           " " + instrument.DaysOff;
                    }
                    if (Data.Update - instrument.Update > new TimeSpan(24, 0, 0))
                    {
                        _warningMessage += Environment.NewLine + Language.T("Data for:") + " " + Data.Symbol + " " +
                                           Data.DataPeriodToString(period) + " - " + Language.T("Updated on:") + " " +
                                           instrument.Update.ToString(CultureInfo.InvariantCulture);
                    }
                }

                int startBigBar;
                for (startBigBar = 0; startBigBar < Data.Bars; startBigBar++)
                {
                    if (Data.Time[startBigBar] >= instrument.Time(0))
                    {
                        break;
                    }
                }

                int stopBigBar;
                for (stopBigBar = startBigBar; stopBigBar < Data.Bars; stopBigBar++)
                {
                    if (Data.IntraBarsPeriods[stopBigBar] != Data.Period)
                    {
                        break;
                    }
                }

                // Seek for a place to put the intrabars.
                int lastIntraBar = 0;
                for (int bar = startBigBar; bar < stopBigBar; bar++)
                {
                    Data.IntraBarData[bar] = new Bar[(int)Data.Period / (int)period];
                    DateTime endTime  = Data.Time[bar] + new TimeSpan(0, (int)Data.Period, 0);
                    int      indexBar = 0;
                    for (int intrabar = lastIntraBar;
                         intrabar < loadedIntrabars && instrument.Time(intrabar) < endTime;
                         intrabar++)
                    {
                        if (instrument.Time(intrabar) >= Data.Time[bar])
                        {
                            Data.IntraBarData[bar][indexBar].Time  = instrument.Time(intrabar);
                            Data.IntraBarData[bar][indexBar].Open  = instrument.Open(intrabar);
                            Data.IntraBarData[bar][indexBar].High  = instrument.High(intrabar);
                            Data.IntraBarData[bar][indexBar].Low   = instrument.Low(intrabar);
                            Data.IntraBarData[bar][indexBar].Close = instrument.Close(intrabar);
                            Data.IntraBarsPeriods[bar]             = period;
                            Data.IntraBarBars[bar]++;
                            indexBar++;
                            lastIntraBar = intrabar;
                        }
                    }
                }
            }

            return(loadedIntrabars);
        }
コード例 #7
0
 /// <summary>
 /// Generate the Market Statistics
 /// </summary>
 public static void GenerateMarketStats()
 {
     MarketStatsValue[0]  = Symbol;
     MarketStatsValue[1]  = DataPeriodToString(Period);
     MarketStatsValue[2]  = Bars.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[3]  = Update.ToString(DF);
     MarketStatsValue[4]  = Update.ToString("HH:mm");
     MarketStatsValue[5]  = Time[0].ToString(DF);
     MarketStatsValue[6]  = Time[0].ToString("HH:mm");
     MarketStatsValue[7]  = MinPrice.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[8]  = MaxPrice.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[9]  = AverageGap + " " + Language.T("pips");
     MarketStatsValue[10] = MaxGap + " " + Language.T("pips");
     MarketStatsValue[11] = AverageHighLow + " " + Language.T("pips");
     MarketStatsValue[12] = MaxHighLow + " " + Language.T("pips");
     MarketStatsValue[13] = AverageCloseOpen + " " + Language.T("pips");
     MarketStatsValue[14] = MaxCloseOpen + " " + Language.T("pips");
     MarketStatsValue[15] = DaysOff.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[16] = Configs.MaxBars.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[17] = Configs.UseStartTime ? Configs.DataStartTime.ToShortDateString() : Language.T("No limits");
     MarketStatsValue[18] = Configs.UseEndTime ? Configs.DataEndTime.ToShortDateString() : Language.T("No limits");
     MarketStatsValue[19] = Configs.FillInDataGaps ? Language.T("Accomplished") : Language.T("Switched off");
     MarketStatsValue[20] = Configs.CutBadData ? Language.T("Accomplished") : Language.T("Switched off");
 }
コード例 #8
0
        /// <summary>
        /// Prepare the parameters
        /// </summary>
        private void SetUpPaintData()
        {
            // Panel caption
            _captionText         = Language.T("Indicator Chart");
            _captionFont         = new Font(Font.FontFamily, 9);
            _captionHeight       = Math.Max(_captionFont.Height, 18);
            _captionWidth        = ClientSize.Width;
            _captionBrush        = new SolidBrush(LayoutColors.ColorCaptionText);
            _captionRectangle    = new RectangleF(0, 0, _captionWidth, _captionHeight);
            _captionStringFormat = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap
            };

            if (!Data.IsData || !Data.IsResult || Data.Bars <= StatsBuffer.FirstBar)
            {
                return;
            }

            _xLeft                         = Space;
            _xRight                        = ClientSize.Width - Space;
            _yTop                          = (int)_captionHeight + Space;
            _yBottom                       = ClientSize.Height - _scrollBar.Height - Space;
            _yPriceBottom                  = _yBottom;
            _separateIndicatorsCount       = 0;
            _separateIndicatorsChartHeight = 0;
            _indicatorSlots                = new int[Configs.MaxEntryFilters + Configs.MaxExitFilters + 2];

            _penFore   = new Pen(LayoutColors.ColorChartFore);
            _penVolume = new Pen(LayoutColors.ColorVolume);
            _penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption),
                                 Border);

            for (int slot = StatsBuffer.Strategy.Slots - 1; slot >= 0; slot--)
            {
                if (StatsBuffer.Strategy.Slot[slot].SeparatedChart)
                {
                    _indicatorSlots[_separateIndicatorsCount++] = slot;
                }
            }

            if (_separateIndicatorsCount > 0)
            {
                _separateIndicatorsChartHeight = (_yBottom - _yTop) / (2 + _separateIndicatorsCount);
                _yPriceBottom = _yBottom - _separateIndicatorsCount * _separateIndicatorsChartHeight;
            }

            _maxPrice  = double.MinValue;
            _minPrice  = double.MaxValue;
            _maxVolume = int.MinValue;

            for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
            {
                if (Data.High[bar] > _maxPrice)
                {
                    _maxPrice = Data.High[bar];
                }
                if (Data.Low[bar] < _minPrice)
                {
                    _minPrice = Data.Low[bar];
                }
                if (Data.Volume[bar] > _maxVolume)
                {
                    _maxVolume = Data.Volume[bar];
                }
            }
            _minPrice = Math.Round(_minPrice, Data.InstrProperties.Point < 0.001 ? 3 : 1) -
                        Data.InstrProperties.Point * 10;
            _maxPrice = Math.Round(_maxPrice, Data.InstrProperties.Point < 0.001 ? 3 : 1) +
                        Data.InstrProperties.Point * 10;
            _scaleY    = (_yPriceBottom - _yTop) / (_maxPrice - _minPrice);
            _scaleYVol = _maxVolume > 0 ? ((_yPriceBottom - _yTop) / 8d) / _maxVolume : 0d;

            // Volume, Lots and Price
            _x             = new int[_chartBars];
            _yOpen         = new int[_chartBars];
            _yHigh         = new int[_chartBars];
            _yLow          = new int[_chartBars];
            _yClose        = new int[_chartBars];
            _yVolume       = new int[_chartBars];
            _rectPosition  = new Rectangle[_chartBars];
            _brushPosition = new Brush[_chartBars];

            int index = 0;

            for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
            {
                _x[index]       = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                _yOpen[index]   = (int)(_yPriceBottom - (Data.Open[bar] - _minPrice) * _scaleY);
                _yHigh[index]   = (int)(_yPriceBottom - (Data.High[bar] - _minPrice) * _scaleY);
                _yLow[index]    = (int)(_yPriceBottom - (Data.Low[bar] - _minPrice) * _scaleY);
                _yClose[index]  = (int)(_yPriceBottom - (Data.Close[bar] - _minPrice) * _scaleY);
                _yVolume[index] = (int)(_yPriceBottom - Data.Volume[bar] * _scaleYVol);

                // Draw position lots
                if (StatsBuffer.IsPos(bar))
                {
                    var posHight = (int)(Math.Max(StatsBuffer.SummaryLots(bar) * 2, 2));
                    int yPos     = _yPriceBottom - posHight;

                    switch (StatsBuffer.SummaryDir(bar))
                    {
                    case PosDirection.Long:
                        _rectPosition[index]  = new Rectangle(_x[index], yPos, 1, posHight);
                        _brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeLong);
                        break;

                    case PosDirection.Short:
                        _rectPosition[index]  = new Rectangle(_x[index], yPos, 1, posHight);
                        _brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeShort);
                        break;

                    case PosDirection.Closed:
                        _rectPosition[index]  = new Rectangle(_x[index], yPos - 2, 1, 2);
                        _brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeClose);
                        break;
                    }
                }
                else
                {
                    // There is no position
                    _rectPosition[index]  = Rectangle.Empty;
                    _brushPosition[index] = new SolidBrush(LayoutColors.ColorChartBack);
                }
                index++;
            }

            // Indicators in the chart
            int slots = StatsBuffer.Strategy.Slots;

            _isSeparatedChart = new bool[slots];
            _componentLenght  = new int[slots];
            _chartType        = new IndChartType[slots][];
            _chartLine        = new Point[slots][][];
            _chartDot         = new Rectangle[slots][][];
            _chartLevel       = new Rectangle[slots][][];
            _chartValue       = new double[slots][][];
            _chartPen         = new Pen[slots][][];
            _chartBrush       = new Brush[slots][];

            for (int slot = 0; slot < slots; slot++)
            {
                _isSeparatedChart[slot] = StatsBuffer.Strategy.Slot[slot].SeparatedChart;
                int count = StatsBuffer.Strategy.Slot[slot].Component.Length;
                _componentLenght[slot] = count;
                _chartType[slot]       = new IndChartType[count];
                _chartLine[slot]       = new Point[count][];
                _chartDot[slot]        = new Rectangle[count][];
                _chartLevel[slot]      = new Rectangle[count][];
                _chartValue[slot]      = new double[count][];
                _chartPen[slot]        = new Pen[count][];
                _chartBrush[slot]      = new Brush[count];
            }

            for (int slot = 0; slot < slots; slot++)
            {
                if (_isSeparatedChart[slot])
                {
                    continue;
                }

                for (int comp = 0; comp < _componentLenght[slot]; comp++)
                {
                    _chartType[slot][comp] = StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType;
                    switch (StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType)
                    {
                    case IndChartType.Line:
                    case IndChartType.CloudUp:
                    case IndChartType.CloudDown:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartLine[slot][comp] = new Point[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yPriceBottom - (value - _minPrice) * _scaleY);

                            if (Math.Abs(value - 0) < 0.0001)
                            {
                                _chartLine[slot][comp][bar - _chartFirstBar] =
                                    _chartLine[slot][comp][Math.Max(bar - _chartFirstBar - 1, 0)];
                            }
                            else
                            {
                                _chartLine[slot][comp][bar - _chartFirstBar] = new Point(x, y);
                            }
                        }
                        break;

                    case IndChartType.Dot:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartDot[slot][comp] = new Rectangle[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yPriceBottom - (value - _minPrice) * _scaleY);
                            _chartDot[slot][comp][bar - _chartFirstBar] = new Rectangle(x, y, 1, 1);
                        }
                        break;

                    case IndChartType.Level:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartLevel[slot][comp] = new Rectangle[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yPriceBottom - (value - _minPrice) * _scaleY);
                            _chartLevel[slot][comp][bar - _chartFirstBar] = new Rectangle(x, y, _chartBarWidth, 1);
                        }
                        break;
                    }
                }
            }

            // Separate indicators
            _yIndTop    = new int[_separateIndicatorsCount];
            _yIndBottom = new int[_separateIndicatorsCount];
            _maxValues  = new double[_separateIndicatorsCount];
            _minValues  = new double[_separateIndicatorsCount];
            _scales     = new double[_separateIndicatorsCount];

            for (int ind = 0; ind < _separateIndicatorsCount; ind++)
            {
                _yIndTop[ind]    = _yBottom - (ind + 1) * _separateIndicatorsChartHeight + 1;
                _yIndBottom[ind] = _yBottom - ind * _separateIndicatorsChartHeight - 1;
                _maxValues[ind]  = double.MinValue;
                _minValues[ind]  = double.MaxValue;
                int slot = _indicatorSlots[ind];

                for (int comp = 0; comp < _componentLenght[slot]; comp++)
                {
                    if (StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType != IndChartType.NoChart)
                    {
                        for (
                            int bar = Math.Max(_chartFirstBar, StatsBuffer.Strategy.Slot[slot].Component[comp].FirstBar);
                            bar <= _chartLastBar;
                            bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            if (value > _maxValues[ind])
                            {
                                _maxValues[ind] = value;
                            }
                            if (value < _minValues[ind])
                            {
                                _minValues[ind] = value;
                            }
                        }
                    }
                }

                _maxValues[ind] = Math.Max(_maxValues[ind], StatsBuffer.Strategy.Slot[slot].MaxValue);
                _minValues[ind] = Math.Min(_minValues[ind], StatsBuffer.Strategy.Slot[slot].MinValue);

                foreach (double specialValue in StatsBuffer.Strategy.Slot[slot].SpecValue)
                {
                    if (Math.Abs(specialValue - 0) < 0.0001)
                    {
                        _maxValues[ind] = Math.Max(_maxValues[ind], 0);
                        _minValues[ind] = Math.Min(_minValues[ind], 0);
                    }
                }

                _scales[ind] = (_yIndBottom[ind] - _yIndTop[ind] - 2) / (Math.Max(_maxValues[ind] - _minValues[ind], 0.0001f));

                // Indicator chart
                for (int comp = 0; comp < StatsBuffer.Strategy.Slot[slot].Component.Length; comp++)
                {
                    _chartType[slot][comp] = StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType;
                    switch (_chartType[slot][comp])
                    {
                    case IndChartType.Line:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartLine[slot][comp] = new Point[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yIndBottom[ind] - 1 - (value - _minValues[ind]) * _scales[ind]);
                            _chartLine[slot][comp][bar - _chartFirstBar] = new Point(x, y);
                        }
                        break;

                    case IndChartType.Histogram:
                        _chartValue[slot][comp] = new double[_chartLastBar - _chartFirstBar + 1];
                        _chartPen[slot][comp]   = new Pen[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            _chartValue[slot][comp][bar - _chartFirstBar] = value;
                            if (value > StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar - 1])
                            {
                                _chartPen[slot][comp][bar - _chartFirstBar] = _penGreen;
                            }
                            else
                            {
                                _chartPen[slot][comp][bar - _chartFirstBar] = _penRed;
                            }
                        }
                        break;
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Initializes the strategy field
        /// </summary>
        void InitializeStrategy()
        {
            // Button Overview
            tsbtOverview             = new ToolStripButton();
            tsbtOverview.Name        = "Overview";
            tsbtOverview.Text        = Language.T("Overview");
            tsbtOverview.Click      += new EventHandler(BtnTools_OnClick);
            tsbtOverview.ToolTipText = Language.T("See the strategy overview.");
            tsStrategy.Items.Add(tsbtOverview);

            // Button Generator
            tsbtGenerator             = new ToolStripButton();
            tsbtGenerator.Name        = "Generator";
            tsbtGenerator.Text        = Language.T("Generator");
            tsbtGenerator.Click      += new EventHandler(BtnTools_OnClick);
            tsbtGenerator.ToolTipText = Language.T("Generate or improve a strategy.");
            tsStrategy.Items.Add(tsbtGenerator);

            // Button tsbtStrategySize1
            tsbtStrategySize1 = new ToolStripButton();
            tsbtStrategySize1.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsbtStrategySize1.Image        = Properties.Resources.slot_size_max;
            tsbtStrategySize1.Tag          = 1;
            tsbtStrategySize1.Click       += new EventHandler(BtnSlotSize_Click);
            tsbtStrategySize1.ToolTipText  = Language.T("Show detailed info in the slots.");
            tsbtStrategySize1.Alignment    = ToolStripItemAlignment.Right;
            tsStrategy.Items.Add(tsbtStrategySize1);

            // Button tsbtStrategySize2
            tsbtStrategySize2 = new ToolStripButton();
            tsbtStrategySize2.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsbtStrategySize2.Image        = Properties.Resources.slot_size_min;
            tsbtStrategySize2.Tag          = 2;
            tsbtStrategySize2.Click       += new EventHandler(BtnSlotSize_Click);
            tsbtStrategySize2.ToolTipText  = Language.T("Show minimum info in the slots.");
            tsbtStrategySize2.Alignment    = ToolStripItemAlignment.Right;
            tsStrategy.Items.Add(tsbtStrategySize2);

            // Button tsbtStrategyInfo
            tsbtStrategyInfo = new ToolStripButton();
            tsbtStrategyInfo.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsbtStrategyInfo.Image        = Properties.Resources.str_info_infook;
            tsbtStrategyInfo.Tag          = SlotSizeMinMidMax.min;
            tsbtStrategyInfo.Click       += new EventHandler(BtnStrategyDescription_Click);
            tsbtStrategyInfo.ToolTipText  = Language.T("Show the strategy description.");
            tsbtStrategyInfo.Alignment    = ToolStripItemAlignment.Right;
            tsStrategy.Items.Add(tsbtStrategyInfo);

            // Button Optimizer
            tsbtOptimizer             = new ToolStripButton();
            tsbtOptimizer.Name        = "Optimizer";
            tsbtOptimizer.Text        = Language.T("Optimizer");
            tsbtOptimizer.Click      += new EventHandler(BtnTools_OnClick);
            tsbtOptimizer.ToolTipText = Language.T("Optimize the strategy parameters.");
            tsStrategy.Items.Add(tsbtOptimizer);

            // Creates strategyLayout
            strategyLayout        = new Strategy_Layout(Data.Strategy.Clone());
            strategyLayout.Parent = pnlStrategy;
            strategyLayout.btnAddOpenFilter.Click  += new EventHandler(BtnAddOpenFilter_Click);
            strategyLayout.btnAddCloseFilter.Click += new EventHandler(BtnAddCloseFilter_Click);

            btnShowJournalByPos        = new Button();
            btnShowJournalByPos.Parent = pnlStrategy;
            btnShowJournalByPos.Text   = Language.T("Journal by Positions");
            btnShowJournalByPos.UseVisualStyleBackColor = true;
            btnShowJournalByPos.Click += new EventHandler(BtnShowJournalByPos_Click);

            btnShowJournalByBars        = new Button();
            btnShowJournalByBars.Parent = pnlStrategy;
            btnShowJournalByBars.Text   = Language.T("Journal by Bars");
            btnShowJournalByBars.UseVisualStyleBackColor = true;
            btnShowJournalByBars.Click += new EventHandler(BtnShowJournalByBars_Click);

            pnlStrategy.Resize += new EventHandler(PnlStrategy_Resize);

            return;
        }
コード例 #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Edit_Translation()
        {
            // The form
            MaximizeBox     = false;
            MinimizeBox     = false;
            Icon            = Data.Icon;
            BackColor       = LayoutColors.ColorFormBack;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            Text            = Language.T("Edit Translation");
            FormClosing    += new FormClosingEventHandler(Actions_FormClosing);

            // Controls
            pnlCommon       = new Fancy_Panel(Language.T("Common Parameters"));
            pnlPhrases      = new Fancy_Panel(Language.T("English Phrase - Translated Phrase"));
            alblInputNames  = new Label[5];
            atbxInputValues = new TextBox[5];
            atbxMain        = new TextBox[TEXTBOXES];
            atbxAlt         = new TextBox[TEXTBOXES];
            scrollBar       = new VScrollBar();
            tbxSearch       = new TextBox();
            btnSearch       = new Button();
            btnUntranslated = new Button();
            btnAccept       = new Button();
            btnCancel       = new Button();

            // Common
            pnlCommon.Parent = this;

            // Phrases
            pnlPhrases.Parent = this;

            // Input Names
            string[] asInputNames = new string[] {
                Language.T("Language"),
                Language.T("File name"),
                Language.T("Author"),
                Language.T("Website"),
                Language.T("Contacts"),
            };

            // Input Values
            string[] asInputValues = new string[] {
                Configs.Language,
                Language.LanguageFileName,
                Language.Author,
                Language.AuthorsWebsite,
                Language.AuthorsEmail,
            };

            // Common parameters
            for (int i = 0; i < asInputNames.Length; i++)
            {
                alblInputNames[i]           = new Label();
                alblInputNames[i].Parent    = pnlCommon;
                alblInputNames[i].ForeColor = LayoutColors.ColorControlText;
                alblInputNames[i].BackColor = Color.Transparent;
                alblInputNames[i].AutoSize  = true;
                alblInputNames[i].Text      = asInputNames[i];

                atbxInputValues[i]        = new TextBox();
                atbxInputValues[i].Parent = pnlCommon;
                atbxInputValues[i].Text   = asInputValues[i];
            }

            // Phrases
            for (int i = 0; i < TEXTBOXES; i++)
            {
                atbxMain[i]           = new TextBox();
                atbxMain[i].Parent    = pnlPhrases;
                atbxMain[i].Multiline = true;
                atbxMain[i].ReadOnly  = true;
                atbxMain[i].ForeColor = Color.DarkGray;

                atbxAlt[i]              = new TextBox();
                atbxAlt[i].Parent       = pnlPhrases;
                atbxAlt[i].Multiline    = true;
                atbxAlt[i].Tag          = i;
                atbxAlt[i].TextChanged += new EventHandler(Edit_Translation_TextChanged);
            }

            // Vertical ScrollBar
            scrollBar.Parent        = pnlPhrases;
            scrollBar.Visible       = true;
            scrollBar.Enabled       = true;
            scrollBar.ValueChanged += new EventHandler(ScrollBar_ValueChanged);
            scrollBar.TabStop       = true;

            // TextBox Search
            tbxSearch.Parent       = this;
            tbxSearch.TextChanged += new EventHandler(TbxSearch_TextChanged);

            // Button Search
            btnSearch.Parent = this;
            btnSearch.Name   = "Search";
            btnSearch.Text   = Language.T("Search");
            btnSearch.Click += new EventHandler(Btn_Click);
            btnSearch.UseVisualStyleBackColor = true;

            // Button Untranslated
            btnUntranslated.Parent = this;
            btnUntranslated.Name   = "Untranslated";
            btnUntranslated.Text   = Language.T("Not Translated");
            btnUntranslated.Click += new EventHandler(Btn_Click);
            btnUntranslated.UseVisualStyleBackColor = true;

            // Button Cancel
            btnCancel.Parent                  = this;
            btnCancel.Name                    = "Cancel";
            btnCancel.Text                    = Language.T("Cancel");
            btnCancel.DialogResult            = DialogResult.Cancel;
            btnCancel.Click                  += new EventHandler(Btn_Click);
            btnCancel.UseVisualStyleBackColor = true;

            // Button Accept
            btnAccept.Parent                  = this;
            btnAccept.Name                    = "Accept";
            btnAccept.Text                    = Language.T("Accept");
            btnAccept.DialogResult            = DialogResult.OK;
            btnAccept.Click                  += new EventHandler(Btn_Click);
            btnAccept.Enabled                 = false;
            btnAccept.UseVisualStyleBackColor = true;
        }
コード例 #11
0
        public AboutScreen()
        {
            PnlBase     = new FancyPanel();
            Label1      = new Label();
            Label2      = new Label();
            Label3      = new Label();
            Label4      = new Label();
            Label5      = new Label();
            Label6      = new Label();
            PictureBox1 = new PictureBox();
            LlWebsite   = new LinkLabel();
            LlForum     = new LinkLabel();
            LlEmail     = new LinkLabel();
            LlCredits   = new LinkLabel();
            BtnOk       = new Button();

            // Panel Base
            PnlBase.Parent = this;

            // pictureBox1
            PictureBox1.TabStop   = false;
            PictureBox1.BackColor = Color.Transparent;
            PictureBox1.Image     = Resources.Logo;

            // label1
            Label1.AutoSize  = true;
            Label1.Font      = new Font("Microsoft Sans Serif", 16F, FontStyle.Bold);
            Label1.ForeColor = LayoutColors.ColorControlText;
            Label1.BackColor = Color.Transparent;
            Label1.Text      = Data.ProgramName;

            string stage = String.Empty;

            if (Data.IsProgramBeta)
            {
                stage = " " + Language.T("Beta");
            }
            else if (Data.IsProgramRC)
            {
                stage = " " + "RC";
            }

            // label2
            Label2.AutoSize  = true;
            Label2.Font      = new Font("Microsoft Sans Serif", 12F);
            Label2.ForeColor = LayoutColors.ColorControlText;
            Label2.BackColor = Color.Transparent;
            Label2.Text      = Language.T("Version") + ": " + Data.ProgramVersion + stage;

            // label3
            Label3.AutoSize  = true;
            Label3.Font      = new Font("Microsoft Sans Serif", 10F);
            Label3.ForeColor = LayoutColors.ColorControlText;
            Label3.BackColor = Color.Transparent;
            Label3.Text      = "Copyright © 2006 - 2012 Miroslav Popov" + Environment.NewLine + Language.T("Distributor") +
                               " - Forex Software Ltd." + Environment.NewLine + Environment.NewLine +
                               Language.T("This is a freeware program!");

            // label4
            Label4.AutoSize  = true;
            Label4.ForeColor = LayoutColors.ColorControlText;
            Label4.BackColor = Color.Transparent;
            Label4.Text      = Language.T("Website") + ":";

            // label5
            Label5.AutoSize  = true;
            Label5.ForeColor = LayoutColors.ColorControlText;
            Label5.BackColor = Color.Transparent;
            Label5.Text      = Language.T("Support forum") + ":";

            // label6
            Label6.AutoSize  = true;
            Label6.ForeColor = LayoutColors.ColorControlText;
            Label6.BackColor = Color.Transparent;
            Label6.Text      = Language.T("Contacts") + ":";

            // llWebsite
            LlWebsite.AutoSize     = true;
            LlWebsite.TabStop      = true;
            LlWebsite.BackColor    = Color.Transparent;
            LlWebsite.Text         = "http://forexsb.com";
            LlWebsite.Tag          = "http://forexsb.com/";
            LlWebsite.LinkClicked += WebsiteLinkClicked;

            // llForum
            LlForum.AutoSize     = true;
            LlForum.TabStop      = true;
            LlForum.BackColor    = Color.Transparent;
            LlForum.Text         = "http://forexsb.com/forum";
            LlForum.Tag          = "http://forexsb.com/forum/";
            LlForum.LinkClicked += WebsiteLinkClicked;

            // llEmail
            LlEmail.AutoSize     = true;
            LlEmail.TabStop      = true;
            LlEmail.BackColor    = Color.Transparent;
            LlEmail.Text         = "*****@*****.**";
            LlEmail.Tag          = "mailto:[email protected]";
            LlEmail.LinkClicked += WebsiteLinkClicked;

            // LlCredits
            LlCredits.AutoSize     = true;
            LlCredits.TabStop      = true;
            LlCredits.BackColor    = Color.Transparent;
            LlCredits.Text         = Language.T("Credits and Contributors");
            LlCredits.Tag          = "http://forexsb.com/wiki/credits";
            LlCredits.LinkClicked += WebsiteLinkClicked;

            // Button Base
            BtnOk.Parent = this;
            BtnOk.Text   = Language.T("Ok");
            BtnOk.UseVisualStyleBackColor = true;
            BtnOk.Click += BtnOkClick;

            // AboutScreen
            PnlBase.Controls.Add(Label1);
            PnlBase.Controls.Add(Label2);
            PnlBase.Controls.Add(Label3);
            PnlBase.Controls.Add(Label4);
            PnlBase.Controls.Add(Label5);
            PnlBase.Controls.Add(Label6);
            PnlBase.Controls.Add(LlEmail);
            PnlBase.Controls.Add(LlForum);
            PnlBase.Controls.Add(LlWebsite);
            PnlBase.Controls.Add(LlCredits);
            PnlBase.Controls.Add(PictureBox1);

            StartPosition   = FormStartPosition.CenterScreen;
            Text            = Language.T("About") + " " + Data.ProgramName;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            BackColor       = LayoutColors.ColorFormBack;
            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            ClientSize      = new Size(360, 310);
        }
コード例 #12
0
        /// <summary>
        /// Initializes the controls in panel pnlJournal.
        /// </summary>
        void InitializeJournal()
        {
            // pnlJournalRight
            pnlJournalRight        = new Panel();
            pnlJournalRight.Parent = pnlJournal;
            pnlJournalRight.Dock   = DockStyle.Fill;

            // pnlJournalOrder
            pnlJournalOrder        = new Journal_Ord();
            pnlJournalOrder.Parent = pnlJournalRight;
            pnlJournalOrder.Dock   = DockStyle.Fill;
            pnlJournalOrder.Cursor = Cursors.Hand;
            pnlJournalOrder.Click += new EventHandler(PnlJournal_Click);
            pnlJournalOrder.BtnRemoveJournal.Click += new EventHandler(BtnRemoveJournal_Click);
            pnlJournalOrder.BtnToggleJournal.Click += new EventHandler(BtnToggleJournal_Click);
            toolTip.SetToolTip(pnlJournalOrder, Language.T("Click to view Bar Explorer."));

            Splitter splitter1 = new Splitter();

            splitter1.Parent = pnlJournalRight;
            splitter1.Dock   = DockStyle.Bottom;
            splitter1.Height = space;

            // pnlJournalPosition
            pnlJournalPosition        = new Journal_Pos();
            pnlJournalPosition.Parent = pnlJournalRight;
            pnlJournalPosition.Dock   = DockStyle.Bottom;
            pnlJournalPosition.Cursor = Cursors.Hand;
            pnlJournalPosition.Click += new EventHandler(PnlJournal_Click);
            toolTip.SetToolTip(pnlJournalPosition, Language.T("Click to view Bar Explorer."));

            splJournal        = new Splitter();
            splJournal.Parent = pnlJournal;
            splJournal.Dock   = DockStyle.Left;
            splJournal.Width  = space;

            // pnlJournalData
            pnlJournalByBars                    = new Journal_Bars();
            pnlJournalByBars.Name               = "pnlJournalData";
            pnlJournalByBars.Parent             = pnlJournal;
            pnlJournalByBars.Dock               = DockStyle.Left;
            pnlJournalByBars.SelectedBarChange += new EventHandler(PnlJournal_SelectedBarChange);
            pnlJournalByBars.MouseDoubleClick  += new MouseEventHandler(PnlJournal_MouseDoubleClick);
            toolTip.SetToolTip(pnlJournalByBars, Language.T("Click to select a bar.") + Environment.NewLine + Language.T("Double click to view Bar Explorer."));

            // pnlJournalByPositions
            pnlJournalByPositions                         = new Journal_Positions();
            pnlJournalByPositions.Name                    = "pnlJournalByPositions";
            pnlJournalByPositions.Parent                  = pnlJournal;
            pnlJournalByPositions.Dock                    = DockStyle.Fill;
            pnlJournalByPositions.SelectedBarChange      += new EventHandler(PnlJournal_SelectedBarChange);
            pnlJournalByPositions.MouseDoubleClick       += new MouseEventHandler(PnlJournal_MouseDoubleClick);
            pnlJournalByPositions.BtnRemoveJournal.Click += new EventHandler(BtnRemoveJournal_Click);
            pnlJournalByPositions.BtnToggleJournal.Click += new EventHandler(BtnToggleJournal_Click);
            toolTip.SetToolTip(pnlJournalByPositions, Language.T("Click to select a bar.") + Environment.NewLine + Language.T("Double click to view Bar Explorer."));

            pnlJournal.Resize                  += new EventHandler(PnlJournal_Resize);
            pnlJournalRight.Visible             = Configs.JournalByBars;
            pnlJournalByBars.Visible            = Configs.JournalByBars;
            splJournal.Visible                  = Configs.JournalByBars;
            pnlJournalByPositions.Visible       = !Configs.JournalByBars;
            pnlJournalByPositions.ShowTransfers = Configs.JournalShowTransfers;

            return;
        }
コード例 #13
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Trading_Charges()
        {
            pnlBase = new Fancy_Panel();

            lblSpread     = new Label();
            lblSwapLong   = new Label();
            lblSwapShort  = new Label();
            lblCommission = new Label();
            lblSlippage   = new Label();

            nudSpread     = new NumericUpDown();
            nudSwapLong   = new NumericUpDown();
            nudSwapShort  = new NumericUpDown();
            nudCommission = new NumericUpDown();
            nudSlippage   = new NumericUpDown();

            btnEditInstrument = new Button();
            btnAccept         = new Button();
            btnCancel         = new Button();

            font      = this.Font;
            colorText = LayoutColors.ColorControlText;

            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            Icon            = Data.Icon;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            AcceptButton    = btnAccept;
            Text            = Language.T("Trading Charges") + " - " + Data.Symbol;

            // pnlBase
            pnlBase.Parent = this;

            // Label Spread
            lblSpread.Parent    = pnlBase;
            lblSpread.ForeColor = colorText;
            lblSpread.BackColor = Color.Transparent;
            lblSpread.AutoSize  = true;
            lblSpread.Text      = Language.T("Spread") + " [" + Language.T("pips") + "]";

            // Label Swap Long
            lblSwapLong.Parent    = pnlBase;
            lblSwapLong.ForeColor = colorText;
            lblSwapLong.BackColor = Color.Transparent;
            lblSwapLong.AutoSize  = true;
            lblSwapLong.Text      = Language.T("Swap number for a long position rollover") + " [" +
                                    (Data.InstrProperties.SwapType == Commission_Type.money ?
                                     Data.InstrProperties.PriceIn :
                                     Language.T(Data.InstrProperties.SwapType.ToString())) + "]" + Environment.NewLine +
                                    "(" + Language.T("A positive value decreases your profit.") + ")";

            // Label Swap Short
            lblSwapShort.Parent    = pnlBase;
            lblSwapShort.ForeColor = colorText;
            lblSwapShort.BackColor = Color.Transparent;
            lblSwapShort.AutoSize  = true;
            lblSwapShort.Text      = Language.T("Swap number for a short position rollover") + " [" +
                                     (Data.InstrProperties.SwapType == Commission_Type.money ?
                                      Data.InstrProperties.PriceIn :
                                      Language.T(Data.InstrProperties.SwapType.ToString())) + "]" + Environment.NewLine +
                                     "(" + Language.T("A negative value decreases your profit.") + ")";

            // Label Commission
            lblCommission.Parent    = pnlBase;
            lblCommission.ForeColor = colorText;
            lblCommission.BackColor = Color.Transparent;
            lblCommission.AutoSize  = true;
            lblCommission.Text      = Language.T("Commission in") + " " +
                                      Data.InstrProperties.CommissionTypeToString + " " +
                                      Data.InstrProperties.CommissionScopeToString + " " +
                                      Data.InstrProperties.CommissionTimeToString +
                                      (Data.InstrProperties.CommissionType == Commission_Type.money ? " [" + Data.InstrProperties.PriceIn + "]" : "");

            // Label Slippage
            lblSlippage.Parent    = pnlBase;
            lblSlippage.ForeColor = colorText;
            lblSlippage.BackColor = Color.Transparent;
            lblSlippage.AutoSize  = true;
            lblSlippage.Text      = Language.T("Slippage") + " [" + Language.T("pips") + "]";

            // NumericUpDown Spread
            nudSpread.BeginInit();
            nudSpread.Parent        = pnlBase;
            nudSpread.Name          = Language.T("Spread");
            nudSpread.TextAlign     = HorizontalAlignment.Center;
            nudSpread.Minimum       = 0;
            nudSpread.Maximum       = 500;
            nudSpread.Increment     = 0.01M;
            nudSpread.DecimalPlaces = 2;
            nudSpread.Value         = 4;
            nudSpread.EndInit();
            toolTip.SetToolTip(nudSpread, Language.T("Difference between Bid and Ask prices."));

            // NumericUpDown Swap Long
            nudSwapLong.BeginInit();
            nudSwapLong.Parent        = pnlBase;
            nudSwapLong.Name          = "SwapLong";
            nudSwapLong.TextAlign     = HorizontalAlignment.Center;
            nudSwapLong.Minimum       = -500;
            nudSwapLong.Maximum       = 500;
            nudSwapLong.Increment     = 0.01M;
            nudSwapLong.DecimalPlaces = 2;
            nudSwapLong.Value         = 1;
            nudSwapLong.EndInit();
            toolTip.SetToolTip(nudSwapLong, Language.T("A position changes its average price with the selected number during a rollover."));

            // NumericUpDown Swap Short
            nudSwapShort.BeginInit();
            nudSwapShort.Parent        = pnlBase;
            nudSwapShort.Name          = "SwapShort";
            nudSwapShort.TextAlign     = HorizontalAlignment.Center;
            nudSwapShort.Minimum       = -500;
            nudSwapShort.Maximum       = 500;
            nudSwapShort.Increment     = 0.01M;
            nudSwapShort.DecimalPlaces = 2;
            nudSwapShort.Value         = -1;
            nudSwapShort.EndInit();
            toolTip.SetToolTip(nudSwapShort, Language.T("A position changes its average price with the selected number during a rollover."));

            // NumericUpDown Commission
            nudCommission.BeginInit();
            nudCommission.Parent        = pnlBase;
            nudCommission.Name          = Language.T("Commission");
            nudCommission.TextAlign     = HorizontalAlignment.Center;
            nudCommission.Minimum       = -500;
            nudCommission.Maximum       = 500;
            nudCommission.Increment     = 0.01M;
            nudCommission.DecimalPlaces = 2;
            nudCommission.Value         = 0;
            nudCommission.EndInit();

            // NumericUpDown Slippage
            nudSlippage.BeginInit();
            nudSlippage.Parent    = pnlBase;
            nudSlippage.Name      = "Slippage";
            nudSlippage.TextAlign = HorizontalAlignment.Center;
            nudSlippage.Minimum   = 0;
            nudSlippage.Maximum   = 200;
            nudSlippage.Increment = 1;
            nudSlippage.Value     = 0;
            nudSlippage.EndInit();
            toolTip.SetToolTip(nudSlippage, Language.T("Number of pips you lose due to an inaccurate order execution."));

            //Button btnEditInstrument
            btnEditInstrument.Parent = this;
            btnEditInstrument.Name   = "EditInstrument";
            btnEditInstrument.Text   = Language.T("More");
            btnEditInstrument.Click += new EventHandler(BtnEditInstrument_Click);
            btnEditInstrument.UseVisualStyleBackColor = true;

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

            //Button Accept
            btnAccept.Parent                  = this;
            btnAccept.Name                    = "Accept";
            btnAccept.Text                    = Language.T("Accept");
            btnAccept.DialogResult            = DialogResult.OK;
            btnAccept.UseVisualStyleBackColor = true;

            return;
        }
コード例 #14
0
        /// <summary>
        /// Initialize the form and controls
        /// </summary>
        public Comparator()
        {
            pnlOptions        = new Panel();
            pnlChart          = new Panel();
            progressBar       = new ProgressBar();
            lblAverageBalance = new Label();
            numRandom         = new NumericUpDown();
            lblRandomCycles   = new Label();
            btnCalculate      = new Button();
            btnClose          = new Button();

            Text            = Language.T("Comparator");
            BackColor       = LayoutColors.ColorFormBack;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            Icon            = Data.Icon;
            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            FormClosing    += new FormClosingEventHandler(Actions_FormClosing);

            isPaintChart = false;

            //Button Calculate
            btnCalculate.Parent = this;
            btnCalculate.Name   = "btnCalculate";
            btnCalculate.Text   = Language.T("Calculate");
            btnCalculate.Click += new EventHandler(BtnCalculate_Click);
            btnCalculate.UseVisualStyleBackColor = true;

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

            // ProgressBar
            progressBar.Parent  = this;
            progressBar.Minimum = 1;
            progressBar.Maximum = 100;
            progressBar.Step    = 1;

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

            pnlOptions.Parent    = this;
            pnlOptions.ForeColor = LayoutColors.ColorControlText;
            pnlOptions.Paint    += new PaintEventHandler(PnlOptions_Paint);

            countMethods  = Enum.GetValues(typeof(InterpolationMethod)).Length;
            achboxMethods = new CheckBox[countMethods];
            for (int i = 0; i < countMethods; i++)
            {
                achboxMethods[i]                 = new CheckBox();
                achboxMethods[i].Parent          = pnlOptions;
                achboxMethods[i].Text            = Language.T(Enum.GetNames(typeof(InterpolationMethod))[i]);
                achboxMethods[i].Tag             = Enum.GetValues(typeof(InterpolationMethod)).GetValue(i);
                achboxMethods[i].Checked         = true;
                achboxMethods[i].BackColor       = Color.Transparent;
                achboxMethods[i].AutoSize        = true;
                achboxMethods[i].CheckedChanged += new EventHandler(Comparator_CheckedChanged);
            }

            // Label Average Balance
            lblAverageBalance.Parent    = pnlOptions;
            lblAverageBalance.AutoSize  = true;
            lblAverageBalance.Text      = Language.T("Average balance");
            lblAverageBalance.ForeColor = LayoutColors.ColorControlText;
            lblAverageBalance.BackColor = Color.Transparent;
            lblAverageBalance.TextAlign = ContentAlignment.MiddleLeft;

            // NumUpDown random cycles
            numRandom.BeginInit();
            numRandom.Parent    = this;
            numRandom.Value     = 25;
            numRandom.Minimum   = 3;
            numRandom.Maximum   = 100;
            numRandom.TextAlign = HorizontalAlignment.Center;
            numRandom.EndInit();

            // Label Random Cycles
            lblRandomCycles.Parent    = this;
            lblRandomCycles.AutoSize  = true;
            lblRandomCycles.ForeColor = LayoutColors.ColorControlText;
            lblRandomCycles.BackColor = Color.Transparent;
            lblRandomCycles.Text      = Language.T("Random iterations");
            lblRandomCycles.TextAlign = ContentAlignment.MiddleLeft;

            // Colors
            penOptimistic    = new Pen(LayoutColors.ComparatorChartOptimisticLine);
            penPessimistic   = new Pen(LayoutColors.ComparatorChartPessimisticLine);
            penShortest      = new Pen(LayoutColors.ComparatorChartShortestLine);
            penNearest       = new Pen(LayoutColors.ComparatorChartNearestLine);
            penRandom        = new Pen(LayoutColors.ComparatorChartRandomLine);
            penRandBands     = new Pen(LayoutColors.ComparatorChartRandomBands);
            brushRandArea    = new SolidBrush(LayoutColors.ComparatorChartRandomArea);
            penBalance       = new Pen(LayoutColors.ComparatorChartBalanceLine);
            penBalance.Width = 2;

            // BackGroundWorker
            bgWorker = new BackgroundWorker();
            bgWorker.WorkerReportsProgress      = true;
            bgWorker.WorkerSupportsCancellation = true;
            bgWorker.DoWork             += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.ProgressChanged    += new ProgressChangedEventHandler(bgWorker_ProgressChanged);
            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);

            Configs.TradeUntilMarginCall = false;

            return;
        }
コード例 #15
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Scanner()
        {
            InfoPanel    = new Panel();
            BalanceChart = new SmallBalanceChart();
            ProgressBar  = new ProgressBar();
            LblProgress  = new Label();
            ChbAutoscan  = new CheckBox();
            ChbTickScan  = new CheckBox();
            BtnClose     = new Button();

            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            Icon            = Data.Icon;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            AcceptButton    = BtnClose;
            Text            = Language.T("Intrabar Scanner");
            BackColor       = LayoutColors.ColorFormBack;
            FormClosing    += ScannerFormClosing;

            _colorText      = LayoutColors.ColorControlText;
            _fontInfo       = new Font(Font.FontFamily, 9);
            _infoRowHeight  = Math.Max(_fontInfo.Height, 18);
            _isTickDataFile = CheckTickDataFile();

            // pnlInfo
            InfoPanel.Parent    = this;
            InfoPanel.BackColor = LayoutColors.ColorControlBack;
            InfoPanel.Paint    += PnlInfoPaint;

            // Small Balance Chart
            BalanceChart.Parent = this;

            // ProgressBar
            ProgressBar.Parent = this;

            // Label Progress
            LblProgress.Parent    = this;
            LblProgress.ForeColor = LayoutColors.ColorControlText;
            LblProgress.AutoSize  = true;

            // Automatic Scan checkbox.
            ChbAutoscan.Parent          = this;
            ChbAutoscan.ForeColor       = _colorText;
            ChbAutoscan.BackColor       = Color.Transparent;
            ChbAutoscan.Text            = Language.T("Automatic Scan");
            ChbAutoscan.Checked         = Configs.Autoscan;
            ChbAutoscan.AutoSize        = true;
            ChbAutoscan.CheckedChanged += ChbAutoscanCheckedChanged;

            // Tick Scan checkbox.
            ChbTickScan.Parent          = this;
            ChbTickScan.ForeColor       = _colorText;
            ChbTickScan.BackColor       = Color.Transparent;
            ChbTickScan.Text            = Language.T("Use Ticks");
            ChbTickScan.Checked         = Configs.UseTickData && _isTickDataFile;
            ChbTickScan.AutoSize        = true;
            ChbTickScan.Visible         = _isTickDataFile;
            ChbTickScan.CheckedChanged += ChbTickScanCheckedChanged;

            //Button Close
            BtnClose.Parent                  = this;
            BtnClose.Name                    = "Close";
            BtnClose.Text                    = Language.T("Close");
            BtnClose.DialogResult            = DialogResult.OK;
            BtnClose.UseVisualStyleBackColor = true;

            // BackGroundWorker
            BgWorker = new BackgroundWorker {
                WorkerReportsProgress = true, WorkerSupportsCancellation = true
            };
            BgWorker.DoWork             += BgWorkerDoWork;
            BgWorker.ProgressChanged    += BgWorkerProgressChanged;
            BgWorker.RunWorkerCompleted += BgWorkerRunWorkerCompleted;

            _isLoadingNow = false;

            if (!_isTickDataFile)
            {
                Configs.UseTickData = false;
            }
        }
コード例 #16
0
        /// <summary>
        /// Initializes the Journal
        /// </summary>
        private void InitializeJournal()
        {
            // Horizontal ScrollBar
            _hScrollBar = new HScrollBar {
                Parent = this, Dock = DockStyle.Bottom, SmallChange = 100, LargeChange = 300
            };
            _hScrollBar.ValueChanged += HScrollBarValueChanged;

            // Vertical ScrollBar
            _vScrollBar = new VScrollBar
            {
                Parent = this, Dock = DockStyle.Right, TabStop = true, SmallChange = 1, LargeChange = 4
            };
            _vScrollBar.ValueChanged += VScrollBarValueChanged;

            Graphics g = CreateGraphics();

            _font = new Font(Font.FontFamily, 9);

            string longestDirection = "";

            foreach (PosDirection posDir in Enum.GetValues(typeof(PosDirection)))
            {
                if (g.MeasureString(Language.T(posDir.ToString()), _font).Width >
                    g.MeasureString(longestDirection, _font).Width)
                {
                    longestDirection = Language.T(posDir.ToString());
                }
            }

            string longestTransaction = "";

            foreach (Transaction transaction in Enum.GetValues(typeof(Transaction)))
            {
                if (g.MeasureString(Language.T(transaction.ToString()), _font).Width >
                    g.MeasureString(longestTransaction, _font).Width)
                {
                    longestTransaction = Language.T(transaction.ToString());
                }
            }

            string longestBacktestEval = "";

            foreach (BacktestEval eval in Enum.GetValues(typeof(BacktestEval)))
            {
                if (g.MeasureString(Language.T(eval.ToString()), _font).Width >
                    g.MeasureString(longestBacktestEval, _font).Width)
                {
                    longestBacktestEval = Language.T(eval.ToString());
                }
            }

            _titlesInPips = new[]
            {
                Language.T("Position"),
                Language.T("Bar"),
                Language.T("Bar Opening Time"),
                Language.T("Transaction"),
                Language.T("Direction"),
                Language.T("Lots"),
                Language.T("Ord Price"),
                Language.T("Avrg Price"),
                Language.T("Margin"),
                Language.T("Spread"),
                Language.T("Rollover"),
                Language.T("Commission"),
                Language.T("Slippage"),
                Language.T("Profit Loss"),
                Language.T("Floating P/L"),
                Language.T("Balance"),
                Language.T("Equity"),
                Language.T("Backtest")
            };

            _titlesInMoney = new[]
            {
                Language.T("Position"),
                Language.T("Bar"),
                Language.T("Bar Opening Time"),
                Language.T("Transaction"),
                Language.T("Direction"),
                Language.T("Amount"),
                Language.T("Ord Price"),
                Language.T("Avrg Price"),
                Language.T("Margin"),
                Language.T("Spread"),
                Language.T("Rollover"),
                Language.T("Commission"),
                Language.T("Slippage"),
                Language.T("Profit Loss"),
                Language.T("Floating P/L"),
                Language.T("Balance"),
                Language.T("Equity"),
                Language.T("Backtest")
            };

            var asColumContent = new[]
            {
                "99999",
                "99999",
                "12/03/08 00:00",
                longestTransaction,
                longestDirection,
                "-99999999",
                "99.99999",
                "99.99999",
                "999999.99",
                "-999.99",
                "-999.99",
                "-999.99",
                "-999.99",
                "-999999.99",
                "-999999.99",
                "-99999999.99",
                "-99999999.99",
                longestBacktestEval
            };

            _rowHeight = Math.Max(_font.Height, 18);
            Padding    = new Padding(Border, 2 * _rowHeight, Border, Border);

            _columns = 18;
            _columnX = new int[19];
            _scaledX = new int[19];

            _columnX[0] = Border;
            _columnX[1] = _columnX[0] +
                          (int)
                          Math.Max(g.MeasureString(asColumContent[0], _font).Width + 16,
                                   g.MeasureString(_titlesInMoney[0], _font).Width) + 4;
            for (int i = 1; i < _columns; i++)
            {
                _columnX[i + 1] = _columnX[i] +
                                  (int)
                                  Math.Max(g.MeasureString(asColumContent[i], _font).Width,
                                           g.MeasureString(_titlesInMoney[i], _font).Width) + 4;
            }
            g.Dispose();
        }
コード例 #17
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        private void LoadData(BackgroundWorker worker)
        {
            int periodsToLoad = 0;
            int allPeriods    = Enum.GetValues(typeof(DataPeriods)).Length;

            Data.IntraBars             = new int[allPeriods];
            Data.IntraBarData          = new Bar[Data.Bars][];
            Data.IntraBarBars          = new int[Data.Bars];
            Data.IntraBarsPeriods      = new DataPeriods[Data.Bars];
            Data.LoadedIntraBarPeriods = 0;

            for (int bar = 0; bar < Data.Bars; bar++)
            {
                Data.IntraBarsPeriods[bar] = Data.Period;
                Data.IntraBarBars[bar]     = 0;
            }

            // Counts how many periods to load
            for (int prd = 0; prd < allPeriods; prd++)
            {
                var period = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);
                if (period < Data.Period)
                {
                    periodsToLoad++;
                }
            }

            // Load the intrabar data (Starts from 1 Min)
            for (int prd = 0; prd < allPeriods && _isLoadingNow; prd++)
            {
                if (worker.CancellationPending)
                {
                    break;
                }

                int loadedBars = 0;
                var period     = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);

                SetLabelProgressText(Language.T("Loading:") + " " + Data.DataPeriodToString(period) + "...");

                if (period < Data.Period)
                {
                    loadedBars = LoadIntrabarData(period);
                    if (loadedBars > 0)
                    {
                        Data.IsIntrabarData = true;
                        Data.LoadedIntraBarPeriods++;
                    }
                }
                else if (period == Data.Period)
                {
                    loadedBars = Data.Bars;
                    Data.LoadedIntraBarPeriods++;
                }

                Data.IntraBars[prd] = loadedBars;

                // Report progress as a percentage of the total task.
                int percentComplete = periodsToLoad > 0 ? 100 * (prd + 1) / periodsToLoad : 100;
                percentComplete = percentComplete > 100 ? 100 : percentComplete;
                if (percentComplete > _progressPercent)
                {
                    _progressPercent = percentComplete;
                    worker.ReportProgress(percentComplete);
                }
            }

            CheckIntrabarData();
            RepairIntrabarData();

            if (Configs.UseTickData)
            {
                SetLabelProgressText(Language.T("Loading:") + " " + Language.T("Ticks") + "...");
                worker.ReportProgress(200);
                try
                {
                    LoadTickData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Updates the journal data from the StatsBuffer.
        /// </summary>
        private void UpdateJournalData()
        {
            _journalData = new string[_shownPos, _columns];
            _posIcons    = new Image[_shownPos];

            for (int posIndex = _firstPos; posIndex < _firstPos + _shownPos; posIndex++)
            {
                int posNumber = posIndex;

                if (!ShowTransfers)
                {
                    posNumber = _posNumbers[posIndex];
                }

                int      row      = posIndex - _firstPos;
                int      bar      = StatsBuffer.PosCoordinates[posNumber].Bar;
                Position position = StatsBuffer.PosFromNumb(posNumber);

                string posAmount = Configs.AccountInMoney
                                       ? (position.PosDir == PosDirection.Short ? "-" : "") +
                                   (position.PosLots * Data.InstrProperties.LotSize).ToString(
                    CultureInfo.InvariantCulture)
                                       : position.PosLots.ToString(CultureInfo.InvariantCulture);

                string profitLoss = Configs.AccountInMoney
                                        ? position.MoneyProfitLoss.ToString("F2")
                                        : position.ProfitLoss.ToString("F2");

                string floatingPL = Configs.AccountInMoney
                                        ? position.MoneyFloatingPL.ToString("F2")
                                        : position.FloatingPL.ToString("F2");

                int p = 0;
                _journalData[row, p++] = (posNumber + 1).ToString(CultureInfo.InvariantCulture);
                _journalData[row, p++] = (bar + 1).ToString(CultureInfo.InvariantCulture);
                _journalData[row, p++] = Data.Time[bar].ToString(Data.DF) + Data.Time[bar].ToString(" HH:mm");
                _journalData[row, p++] = Language.T(position.Transaction.ToString());
                _journalData[row, p++] = Language.T(position.PosDir.ToString());
                _journalData[row, p++] = posAmount;
                _journalData[row, p++] = position.FormOrdPrice.ToString(Data.FF);
                _journalData[row, p++] = position.PosPrice.ToString(Data.FF);
                _journalData[row, p++] = position.RequiredMargin.ToString("F2");

                // Charges
                if (Configs.AccountInMoney)
                {
                    // in currency
                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reverse)
                    {
                        _journalData[row, p++] = position.MoneySpread.ToString("F2");
                    }
                    else
                    {
                        _journalData[row, p++] = "-";
                    }

                    _journalData[row, p++] = position.Transaction == Transaction.Transfer
                                                 ? position.MoneyRollover.ToString("F2")
                                                 : "-";

                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Close ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reduce ||
                        position.Transaction == Transaction.Reverse)
                    {
                        _journalData[row, p++] = position.MoneyCommission.ToString("F2");
                        _journalData[row, p++] = position.MoneySlippage.ToString("F2");
                    }
                    else
                    {
                        _journalData[row, p++] = "-";
                        _journalData[row, p++] = "-";
                    }
                }
                else
                {
                    // In pips
                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reverse)
                    {
                        _journalData[row, p++] = position.Spread.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        _journalData[row, p++] = "-";
                    }

                    _journalData[row, p++] = position.Transaction == Transaction.Transfer
                                                 ? position.Rollover.ToString("F2")
                                                 : "-";

                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Close ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reduce ||
                        position.Transaction == Transaction.Reverse)
                    {
                        _journalData[row, p++] = position.Commission.ToString("F2");
                        _journalData[row, p++] = position.Slippage.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        _journalData[row, p++] = "-";
                        _journalData[row, p++] = "-";
                    }
                }

                // Profit Loss
                if (position.Transaction == Transaction.Close ||
                    position.Transaction == Transaction.Reduce ||
                    position.Transaction == Transaction.Reverse)
                {
                    _journalData[row, p++] = profitLoss;
                }
                else
                {
                    _journalData[row, p++] = "-";
                }

                // Floating Profit Loss
                if (position.PosNumb == StatsBuffer.SummaryPosNumb(bar) &&
                    position.Transaction != Transaction.Close)
                {
                    _journalData[row, p++] = floatingPL; //Last position of the bar only
                }
                else
                {
                    _journalData[row, p++] = "-";
                }

                // Balance / Equity
                if (Configs.AccountInMoney)
                {
                    _journalData[row, p++] = position.MoneyBalance.ToString("F2");
                    _journalData[row, p++] = position.MoneyEquity.ToString("F2");
                }
                else
                {
                    _journalData[row, p++] = position.Balance.ToString("F2");
                    _journalData[row, p++] = position.Equity.ToString("F2");
                }

                _journalData[row, p] = Language.T(StatsBuffer.BackTestEvalToString(bar));

                // Icons
                _posIcons[row] = Position.PositionIconImage(position.PositionIcon);
            }
        }
コード例 #19
0
        /// <summary>
        /// Initializes the controls in panel pnlJournal.
        /// </summary>
        private void InitializeJournal()
        {
            var toolTip = new ToolTip();

            // Journal Right
            PanelJournalRight = new Panel {
                Parent = PanelJournal, Dock = DockStyle.Fill
            };

            // Journal Orders
            JournalOrders = new JournalOrders {
                Parent = PanelJournalRight, Dock = DockStyle.Fill, Cursor = Cursors.Hand
            };
            JournalOrders.Click += PnlJournalMouseClick;
            JournalOrders.CloseButton.Visible = true;
            JournalOrders.CloseButton.Click  += ContextMenuCloseJournalClick;
            toolTip.SetToolTip(JournalOrders, Language.T("Click to view Bar Explorer."));
            toolTip.SetToolTip(JournalOrders.CloseButton, Language.T("Close Journal"));

            new Splitter {
                Parent = PanelJournalRight, Dock = DockStyle.Bottom, Height = Gap
            };

            // Journal Position
            JournalPositions = new JournalPositions {
                Parent = PanelJournalRight, Dock = DockStyle.Bottom, Cursor = Cursors.Hand
            };
            JournalPositions.Click += PnlJournalMouseClick;
            toolTip.SetToolTip(JournalPositions, Language.T("Click to view Bar Explorer."));

            VerticalSplitter = new Splitter {
                Parent = PanelJournal, Dock = DockStyle.Left, Width = Gap
            };

            // Journal by Bars
            JournalByBars = new JournalByBars {
                Name = "JournalByBars", Parent = PanelJournal, Dock = DockStyle.Left
            };
            JournalByBars.PopUpContextMenu.Items.AddRange(GetJournalContextMenuItems());
            JournalByBars.IsContextButtonVisible = true;
            JournalByBars.SelectedBarChange     += PnlJournalSelectedBarChange;
            JournalByBars.MouseDoubleClick      += PnlJournalMouseDoubleClick;
            toolTip.SetToolTip(JournalByBars, Language.T("Click to select a bar.") + Environment.NewLine + Language.T("Double click to view Bar Explorer."));

            // Journal by Positions
            JournalByPositions = new JournalByPositions {
                Name = "JournalByPositions", Parent = PanelJournal, Dock = DockStyle.Fill
            };
            JournalByPositions.PopUpContextMenu.Items.AddRange(GetJournalContextMenuItems());
            JournalByPositions.IsContextButtonVisible = true;
            JournalByPositions.CloseButton.Visible    = true;
            JournalByPositions.CloseButton.Click     += ContextMenuCloseJournalClick;
            JournalByPositions.SelectedBarChange     += PnlJournalSelectedBarChange;
            JournalByPositions.MouseDoubleClick      += PnlJournalMouseDoubleClick;
            toolTip.SetToolTip(JournalByPositions, Language.T("Click to select a bar.") + Environment.NewLine + Language.T("Double click to view Bar Explorer."));
            toolTip.SetToolTip(JournalByPositions.CloseButton, Language.T("Close Journal"));

            PanelJournal.Resize += PnlJournalResize;

            PanelJournalRight.Visible        = Configs.JournalByBars;
            JournalByBars.Visible            = Configs.JournalByBars;
            VerticalSplitter.Visible         = Configs.JournalByBars;
            JournalByPositions.Visible       = !Configs.JournalByBars;
            JournalByPositions.ShowTransfers = Configs.JournalShowTransfers;
        }
コード例 #20
0
        /// <summary>
        /// Paints the journal
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            int scrll        = -_hScrollBar.Value;
            var size         = new Size(ClientSize.Width, _rowHeight);
            var stringFormat = new StringFormat {
                Alignment = StringAlignment.Center
            };

            // Caption background
            var rectfCaption = new RectangleF(0, 0, ClientSize.Width, 2 * _rowHeight);

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

            // Print the journal caption
            string stringCaptionText = Language.T("Journal by Positions") +
                                       (ShowTransfers ? "" : " " + Language.T("without Transfers")) +
                                       (Configs.AccountInMoney
                                            ? " [" + Configs.AccountCurrency + "]"
                                            : " [" + Language.T("pips") + "]");

            g.DrawString(stringCaptionText, _font, _brushCaptionText, new RectangleF(Point.Empty, size), stringFormat);
            g.SetClip(new RectangleF(Border, _rowHeight, ClientSize.Width - 2 * Border, _rowHeight));
            if (Configs.AccountInMoney)
            {
                g.DrawString(_titlesInMoney[0], _font, _brushCaptionText, scrll + (_scaledX[0] + _scaledX[1]) / 2,
                             _rowHeight, stringFormat);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_titlesInMoney[i], _font, _brushCaptionText, scrll + (_scaledX[i] + _scaledX[i + 1]) / 2,
                                 _rowHeight, stringFormat);
                }
            }
            else
            {
                g.DrawString(_titlesInPips[0], _font, _brushCaptionText, scrll + (_scaledX[0] + _scaledX[1]) / 2,
                             _rowHeight, stringFormat);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_titlesInPips[i], _font, _brushCaptionText, scrll + (_scaledX[i] + _scaledX[i + 1]) / 2,
                                 _rowHeight, stringFormat);
                }
            }
            g.ResetClip();

            // Paints the journal's data field
            var rectField = new RectangleF(Border, 2 * _rowHeight, ClientSize.Width - 2 * Border,
                                           ClientSize.Height - 2 * _rowHeight - Border);

            g.FillRectangle(new SolidBrush(_colorBack), rectField);

            size = new Size(ClientSize.Width - _vScrollBar.Width - 2 * Border, _rowHeight);

            // Prints the journal data
            for (int pos = _firstPos; pos < _firstPos + _shownPos; pos++)
            {
                int y     = (pos - _firstPos + 2) * _rowHeight;
                var point = new Point(Border, y);

                // Even row
                if (Math.Abs((pos - _firstPos) % 2f - 0) > 0.0001)
                {
                    g.FillRectangle(_brushEvenRowBack, new Rectangle(point, size));
                }

                // Warning row
                bool isWarning = false;
                if (_journalData[pos - _firstPos, _columns - 1] == Language.T("Ambiguous"))
                {
                    g.FillRectangle(_brushWarningBack, new Rectangle(point, size));
                    isWarning = true;
                }

                // Selected row
                Brush brush;
                if (pos - _firstPos == _selectedRow)
                {
                    g.FillRectangle(_brushSelectedRowBack, new Rectangle(point, size));
                    brush = _brushSelectedRowText;
                }
                else
                {
                    brush = isWarning ? _brushWarningText : _brushRowText;
                }

                // Draw the position icon
                int iImgY = y + (int)Math.Floor((_rowHeight - 16) / 2.0);
                g.DrawImage(_posIcons[pos - _firstPos], scrll + 2, iImgY, 16, 16);

                // Prints the data
                g.DrawString(_journalData[pos - _firstPos, 0], _font, brush, scrll + (16 + _scaledX[1]) / 2,
                             (pos - _firstPos + 2) * _rowHeight, stringFormat);
                for (int i = 1; i < _columns; i++)
                {
                    g.DrawString(_journalData[pos - _firstPos, i], _font, brush,
                                 scrll + (_scaledX[i] + _scaledX[i + 1]) / 2, (pos - _firstPos + 2) * _rowHeight,
                                 stringFormat);
                }
            }

            //g.DrawLine(penLines, 0, iRowHeight, ClientSize.Width, iRowHeight);
            for (int i = 1; i < _columns; i++)
            {
                g.DrawLine(_penLines, _scaledX[i] + scrll, 2 * _rowHeight, _scaledX[i] + scrll, ClientSize.Height);
            }

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

            OnSelectedBarChange(new EventArgs());
        }
コード例 #21
0
        /// <summary>
        /// Constructor
        /// </summary>
        public EditTranslation()
        {
            // The form
            MaximizeBox     = false;
            MinimizeBox     = false;
            Icon            = Data.Icon;
            BackColor       = LayoutColors.ColorFormBack;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            Text            = Language.T("Edit Translation");
            FormClosing    += ActionsFormClosing;

            // Controls
            PnlCommon       = new FancyPanel(Language.T("Common Parameters"));
            PnlPhrases      = new FancyPanel(Language.T("English Phrase - Translated Phrase"));
            AlblInputNames  = new Label[5];
            AtbxInputValues = new TextBox[5];
            AtbxMain        = new TextBox[Textboxes];
            AtbxAlt         = new TextBox[Textboxes];
            ScrollBar       = new VScrollBar();
            TbxSearch       = new TextBox();
            BtnSearch       = new Button();
            BtnUntranslated = new Button();
            BtnAccept       = new Button();
            BtnCancel       = new Button();

            // Common
            PnlCommon.Parent = this;

            // Phrases
            PnlPhrases.Parent = this;

            // Input Names
            var asInputNames = new[]
            {
                Language.T("Language"),
                Language.T("File name"),
                Language.T("Author"),
                Language.T("Website"),
                Language.T("Contacts")
            };

            // Input Values
            var asInputValues = new[]
            {
                Configs.Language,
                Language.LanguageFileName,
                Language.Author,
                Language.AuthorsWebsite,
                Language.AuthorsEmail
            };

            // Common parameters
            for (int i = 0; i < asInputNames.Length; i++)
            {
                AlblInputNames[i] = new Label
                {
                    Parent    = PnlCommon,
                    ForeColor = LayoutColors.ColorControlText,
                    BackColor = Color.Transparent,
                    AutoSize  = true,
                    Text      = asInputNames[i]
                };

                AtbxInputValues[i] = new TextBox {
                    Parent = PnlCommon, Text = asInputValues[i]
                };
            }

            // Phrases
            for (int i = 0; i < Textboxes; i++)
            {
                AtbxMain[i] = new TextBox
                {
                    Parent = PnlPhrases, Multiline = true, ReadOnly = true, ForeColor = Color.DarkGray
                };

                AtbxAlt[i] = new TextBox {
                    Parent = PnlPhrases, Multiline = true, Tag = i
                };
                AtbxAlt[i].TextChanged += EditTranslationTextChanged;
            }

            // Vertical ScrollBar
            ScrollBar.Parent        = PnlPhrases;
            ScrollBar.Visible       = true;
            ScrollBar.Enabled       = true;
            ScrollBar.ValueChanged += ScrollBarValueChanged;
            ScrollBar.TabStop       = true;

            // TextBox Search
            TbxSearch.Parent       = this;
            TbxSearch.TextChanged += TbxSearchTextChanged;

            // Button Search
            BtnSearch.Parent = this;
            BtnSearch.Name   = "Search";
            BtnSearch.Text   = Language.T("Search");
            BtnSearch.Click += BtnClick;
            BtnSearch.UseVisualStyleBackColor = true;

            // Button Untranslated
            BtnUntranslated.Parent = this;
            BtnUntranslated.Name   = "Untranslated";
            BtnUntranslated.Text   = Language.T("Not Translated");
            BtnUntranslated.Click += BtnClick;
            BtnUntranslated.UseVisualStyleBackColor = true;

            // Button Cancel
            BtnCancel.Parent                  = this;
            BtnCancel.Name                    = "Cancel";
            BtnCancel.Text                    = Language.T("Cancel");
            BtnCancel.DialogResult            = DialogResult.Cancel;
            BtnCancel.Click                  += BtnClick;
            BtnCancel.UseVisualStyleBackColor = true;

            // Button Accept
            BtnAccept.Parent                  = this;
            BtnAccept.Name                    = "Accept";
            BtnAccept.Text                    = Language.T("Accept");
            BtnAccept.DialogResult            = DialogResult.OK;
            BtnAccept.Click                  += BtnClick;
            BtnAccept.Enabled                 = false;
            BtnAccept.UseVisualStyleBackColor = true;
        }
コード例 #22
0
        /// <summary>
        /// Constructor
        /// </summary>
        public MetaTrader4Import()
        {
            LblIntro         = new Label();
            TxbDataDirectory = new TextBox();
            BtnBrowse        = new Button();
            PnlSettings      = new FancyPanel();
            PnlInfoBase      = new FancyPanel(Language.T("Imported Files"));
            TbxInfo          = new TextBox();
            BtnHelp          = new Button();
            BtnClose         = new Button();
            BtnImport        = new Button();
            ProgressBarFile  = new ProgressBar();
            ProgressBar      = new ProgressBar();
            LblDestFolder    = new Label();
            TxbDestFolder    = new TextBox();
            BtnDestFolder    = new Button();

            LblStartingDate = new Label();
            DtpStartingDate = new DateTimePicker();
            LblEndingDate   = new Label();
            DtpEndingDate   = new DateTimePicker();

            _colorText = LayoutColors.ColorControlText;

            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            Icon            = Data.Icon;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            AcceptButton    = BtnImport;
            CancelButton    = BtnClose;
            Text            = Language.T("MetaTrader 4 Import");

            // Label Intro
            LblIntro.Parent    = PnlSettings;
            LblIntro.ForeColor = _colorText;
            LblIntro.BackColor = Color.Transparent;
            LblIntro.AutoSize  = true;
            LblIntro.Text      = Language.T("Directory containing MetaTrader 4 HST files:");

            // Data Directory
            TxbDataDirectory.Parent    = PnlSettings;
            TxbDataDirectory.BackColor = LayoutColors.ColorControlBack;
            TxbDataDirectory.ForeColor = _colorText;
            TxbDataDirectory.Text      = Configs.MetaTrader4DataPath;

            // Button Browse
            BtnBrowse.Parent = PnlSettings;
            BtnBrowse.Name   = "Browse";
            BtnBrowse.Text   = Language.T("Browse");
            BtnBrowse.Click += BtnBrowseClick;
            BtnBrowse.UseVisualStyleBackColor = true;

            // Label Starting Date
            LblStartingDate.Parent    = PnlSettings;
            LblStartingDate.ForeColor = _colorText;
            LblStartingDate.BackColor = Color.Transparent;
            LblStartingDate.AutoSize  = true;
            LblStartingDate.Text      = Language.T("Starting Date:");

            // Starting Date
            DtpStartingDate.Parent     = PnlSettings;
            DtpStartingDate.ForeColor  = LayoutColors.ColorCaptionText;
            DtpStartingDate.ShowUpDown = true;

            // Label Ending Date
            LblEndingDate.Parent    = PnlSettings;
            LblEndingDate.ForeColor = _colorText;
            LblEndingDate.BackColor = Color.Transparent;
            LblEndingDate.AutoSize  = true;
            LblEndingDate.Text      = Language.T("Ending Date:");

            // Ending Date
            DtpEndingDate.Parent     = PnlSettings;
            DtpEndingDate.ForeColor  = LayoutColors.ColorCaptionText;
            DtpEndingDate.ShowUpDown = true;

            // LblDestFolder
            LblDestFolder.Parent    = PnlSettings;
            LblDestFolder.ForeColor = LayoutColors.ColorControlText;
            LblDestFolder.BackColor = Color.Transparent;
            LblDestFolder.AutoSize  = true;
            LblDestFolder.Text      = Language.T("Select a destination folder") + ":";

            // TxbDestFolder
            TxbDestFolder.Parent    = PnlSettings;
            TxbDestFolder.BackColor = LayoutColors.ColorControlBack;
            TxbDestFolder.ForeColor = LayoutColors.ColorControlText;
            TxbDestFolder.Text      = String.IsNullOrEmpty(Configs.MT4ImportDestFolder) ? Data.OfflineDataDir : Configs.MT4ImportDestFolder;

            // BtnDestFolder
            BtnDestFolder.Parent = PnlSettings;
            BtnDestFolder.Name   = "BtnDestFolder";
            BtnDestFolder.Text   = Language.T("Browse");
            BtnDestFolder.Click += BtnDestFolderClick;
            BtnDestFolder.UseVisualStyleBackColor = true;

            // PnlSettings
            PnlSettings.Parent = this;

            // PnlInfoBase
            PnlInfoBase.Parent  = this;
            PnlInfoBase.Padding = new Padding(4, (int)PnlInfoBase.CaptionHeight, 2, 2);

            // TbxInfo
            TbxInfo.Parent        = PnlInfoBase;
            TbxInfo.BorderStyle   = BorderStyle.None;
            TbxInfo.Dock          = DockStyle.Fill;
            TbxInfo.BackColor     = LayoutColors.ColorControlBack;
            TbxInfo.ForeColor     = LayoutColors.ColorControlText;
            TbxInfo.Multiline     = true;
            TbxInfo.AcceptsReturn = true;
            TbxInfo.AcceptsTab    = true;
            TbxInfo.ScrollBars    = ScrollBars.Vertical;

            // ProgressBarFile
            ProgressBarFile.Parent = this;

            // ProgressBar
            ProgressBar.Parent = this;

            // Button Help
            BtnHelp.Parent = this;
            BtnHelp.Name   = "Help";
            BtnHelp.Text   = Language.T("Help");
            BtnHelp.Click += BtnHelpClick;
            BtnHelp.UseVisualStyleBackColor = true;

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

            // Button Import
            BtnImport.Parent = this;
            BtnImport.Name   = "Import";
            BtnImport.Text   = Language.T("Import");
            BtnImport.Click += BtnImportClick;
            BtnImport.UseVisualStyleBackColor = true;

            // BackGroundWorker
            _bgWorker = new BackgroundWorker {
                WorkerReportsProgress = true, WorkerSupportsCancellation = true
            };
            _bgWorker.DoWork             += BgWorkerDoWork;
            _bgWorker.RunWorkerCompleted += BgWorkerRunWorkerCompleted;
        }
コード例 #23
0
        /// <summary>
        /// Sets the journal columns with.
        /// </summary>
        private void SetJournalPoints()
        {
            _columns   = 7;
            _aiColumnX = new int[8];
            _aiX       = new int[8];

            Graphics g = CreateGraphics();

            _asTitles = new[]
            {
                Language.T("Number"),
                Language.T("Description"),
                Language.T("Price"),
                Language.T("Direction"),
                Language.T("Lots"),
                Language.T("Position"),
                Language.T("Order")
            };

            string longestDescription = "";

            foreach (WayPointType wpType in Enum.GetValues(typeof(WayPointType)))
            {
                if (g.MeasureString(Language.T(WayPoint.WPTypeToString(wpType)), _fontInfo).Width >
                    g.MeasureString(longestDescription, _fontInfo).Width)
                {
                    longestDescription = Language.T(WayPoint.WPTypeToString(wpType));
                }
            }

            string longestDirection = "";

            foreach (PosDirection posDir in Enum.GetValues(typeof(PosDirection)))
            {
                if (g.MeasureString(Language.T(posDir.ToString()), _fontInfo).Width >
                    g.MeasureString(longestDirection, _fontInfo).Width)
                {
                    longestDirection = Language.T(posDir.ToString());
                }
            }

            _asContent = new[]
            {
                "99",
                longestDescription,
                "99.99999",
                longestDirection,
                "99999",
                "99999",
                "99999"
            };

            _aiColumnX[0] = Border;
            for (int i = 0; i < _columns; i++)
            {
                _aiColumnX[i + 1] = _aiColumnX[i] +
                                    (int)
                                    Math.Max(g.MeasureString(_asContent[i], _fontInfo).Width,
                                             g.MeasureString(_asTitles[i], _fontInfo).Width) + 4;
            }

            _szPrice = g.MeasureString("9.9999", _fontInfo).ToSize();

            g.Dispose();
        }
コード例 #24
0
        private void ImportHSTFile(string file)
        {
            string outpath = Path.Combine(TxbDestFolder.Text, Path.GetFileNameWithoutExtension(file) + ".csv");

            string message = " ({0} bars)";

            if (File.Exists(outpath))
            {
                message = " ({0} bars) *";
            }

            /* MetaTrader4 HST File Format
             *
             * ~~ HEADER ~~
             * int      version (400)
             * string   copyright
             * int      period (TimeSpan)
             * int      digits
             * int      timesign
             * int      lastSync
             * byte[]   13 reserved bytes
             * byte[]   nn reserved bytes
             *
             * ~~ DATA ~~
             * int      time
             * double   open
             * double   low
             * double   high
             * double   close
             * double   volume
             */

            // Update Status
            SetInfoText(Language.T("Import") + " " + Path.GetFileNameWithoutExtension(file) + " ... ");

            try
            {
                var data        = new StringBuilder(); // Output Data Buffer
                int importCount = 0;                   // Imported Record Count
                int exportCount = 0;                   // Exported Record Count

                // Open the Destination File
                var sw = new StreamWriter(new FileStream(outpath, FileMode.Create));

                using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    // Setup the (File) ProgressBar
                    SetupProgressBarFile(fs.Length);

                    // Open the HST File
                    var br = new BinaryReader(fs, Encoding.ASCII);

                    // Read the File Header
                    long     version   = br.ReadInt32();                             // database version
                    string   copyright = new string(br.ReadChars(64)).TrimEnd('\0'); // copyright info
                    string   symbol    = new string(br.ReadChars(12)).TrimEnd('\0'); // symbol name
                    TimeSpan period    = TimeSpan.FromMinutes(br.ReadInt32());       // symbol timeframe
                    int      digits    = br.ReadInt32();                             // the amount of digits after decimal point in the symbol
                    int      timesign  = br.ReadInt32();                             // timesign of the database creation
                    int      lastSync  = br.ReadInt32();                             // the last synchronization time
                    byte[]   res1      = br.ReadBytes(13);                           // to be used in the future
                    var      res2      = new List <byte>();                          // reserved
                    int      chars     = 0;
                    while (br.PeekChar() == 0 && chars < 39)                         // seems to be some additional 'reserved' bytes here
                    {
                        chars++;
                        res2.Add(br.ReadByte());
                    }

                    // Read the File Data
                    while (fs.Position < fs.Length - 1)
                    {
                        // Update the (File) ProgressBar
                        importCount++;
                        if ((int)Math.IEEERemainder(importCount, 5000) == 0)
                        {
                            UpdateProgressBarFile(fs.Position);
                        }

                        // Output data is saved after each 50000 records are imported
                        if (exportCount > 0 && (int)Math.IEEERemainder(exportCount, 50000) == 0)
                        {
                            sw.Write(data);
                            data = new StringBuilder();
                        }

                        int      seconds  = br.ReadInt32();                               // bar time in seconds since 1/1/1970
                        DateTime?dt       = new DateTime(1970, 1, 1).AddSeconds(seconds); // bar time
                        decimal  open     = Math.Round((decimal)br.ReadDouble(), digits); // open
                        decimal  low      = Math.Round((decimal)br.ReadDouble(), digits); // low
                        decimal  high     = Math.Round((decimal)br.ReadDouble(), digits); // high
                        decimal  close    = Math.Round((decimal)br.ReadDouble(), digits); // close
                        decimal  volume   = Math.Round((decimal)br.ReadDouble(), digits); // vol
                        DateTime dateTime = dt.GetValueOrDefault();

                        if (dateTime > _startingDate && dateTime < _endingDate)
                        {
                            var output = new StringBuilder();
                            output.Append(dateTime.ToString("yyyy"));
                            output.Append("-");
                            output.Append(dateTime.ToString("MM"));
                            output.Append("-");
                            output.Append(dateTime.ToString("dd"));
                            output.Append("\t");
                            output.Append(dateTime.ToString("HH"));
                            output.Append(":");
                            output.Append(dateTime.ToString("mm"));
                            output.Append("\t");
                            output.Append(open.ToString(CultureInfo.InvariantCulture));
                            output.Append("\t");
                            output.Append(high.ToString(CultureInfo.InvariantCulture));
                            output.Append("\t");
                            output.Append(low.ToString(CultureInfo.InvariantCulture));
                            output.Append("\t");
                            output.Append(close.ToString(CultureInfo.InvariantCulture));
                            output.Append("\t");
                            output.Append(volume.ToString(CultureInfo.InvariantCulture));

                            data.AppendLine(output.ToString());

                            exportCount++;
                        }
                    }
                }
                sw.Write(data);
                sw.Flush();
                sw.Close();

                SetInfoText(string.Format(message, exportCount));
                SetInfoText(Environment.NewLine);
            }
            catch (Exception ex)
            {
                SetInfoText("Error (" + ex.Message + ")");
                SetInfoText(Environment.NewLine);
            }
        }
コード例 #25
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();
        }
コード例 #26
0
        public Strategy_Properties()
        {
            pnlAveraging         = new Fancy_Panel(Language.T("Handling of Additional Entry Signals"), LayoutColors.ColorSlotCaptionBackAveraging);
            pnlAmounts           = new Fancy_Panel(Language.T("Trading Size"), LayoutColors.ColorSlotCaptionBackAveraging);
            pnlProtection        = new Fancy_Panel(Language.T("Permanent Protection"), LayoutColors.ColorSlotCaptionBackAveraging);
            pnlSmallBalanceChart = new Small_Balance_Chart();

            lblPercent1 = new Label();
            lblPercent2 = new Label();
            lblPercent3 = new Label();

            lblSameDirAction = new Label();
            lblOppDirAction  = new Label();

            cbxSameDirAction = new ComboBox();
            cbxOppDirAction  = new ComboBox();
            nudMaxOpenLots   = new NUD();
            rbConstantUnits  = new RadioButton();
            rbVariableUnits  = new RadioButton();
            nudEntryLots     = new NUD();
            nudAddingLots    = new NUD();
            nudReducingLots  = new NUD();
            lblMaxOpenLots   = new Label();
            lblEntryLots     = new Label();
            lblAddingLots    = new Label();
            lblReducingLots  = new Label();

            chbPermaSL     = new CheckBox();
            cbxPermaSLType = new ComboBox();
            nudPermaSL     = new NUD();
            chbPermaTP     = new CheckBox();
            cbxPermaTPType = new ComboBox();
            nudPermaTP     = new NUD();

            btnAccept  = new Button();
            btnDefault = new Button();
            btnCancel  = new Button();

            font      = this.Font;
            colorText = LayoutColors.ColorControlText;

            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            Icon            = Data.Icon;
            BackColor       = LayoutColors.ColorFormBack;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            AcceptButton    = btnAccept;
            Text            = Language.T("Strategy Properties");

            pnlAveraging.Parent         = this;
            pnlAmounts.Parent           = this;
            pnlProtection.Parent        = this;
            pnlSmallBalanceChart.Parent = this;
            pnlSmallBalanceChart.SetChartData();

            // Label Same dir action
            lblSameDirAction.Parent    = pnlAveraging;
            lblSameDirAction.ForeColor = colorText;
            lblSameDirAction.BackColor = Color.Transparent;
            lblSameDirAction.AutoSize  = true;
            lblSameDirAction.Text      = Language.T("Next same direction signal behavior");

            // Label Opposite dir action
            lblOppDirAction.Parent    = pnlAveraging;
            lblOppDirAction.ForeColor = colorText;
            lblOppDirAction.BackColor = Color.Transparent;
            lblOppDirAction.AutoSize  = true;
            lblOppDirAction.Text      = Language.T("Next opposite direction signal behavior");

            // ComboBox SameDirAction
            cbxSameDirAction.Parent        = pnlAveraging;
            cbxSameDirAction.Name          = "cbxSameDirAction";
            cbxSameDirAction.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxSameDirAction.Items.AddRange(new string[] { Language.T("Nothing"), Language.T("Winner"), Language.T("Add") });
            cbxSameDirAction.SelectedIndex = 0;
            toolTip.SetToolTip(cbxSameDirAction,
                               Language.T("Nothing - cancels the additional orders.") + Environment.NewLine +
                               Language.T("Winner - adds to a winning position.") + Environment.NewLine +
                               Language.T("Add - adds to all positions."));

            // ComboBox OppDirAction
            cbxOppDirAction.Parent        = pnlAveraging;
            cbxOppDirAction.Name          = "cbxOppDirAction";
            cbxOppDirAction.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxOppDirAction.Items.AddRange(new string[] { Language.T("Nothing"), Language.T("Reduce"), Language.T("Close"), Language.T("Reverse") });
            cbxOppDirAction.SelectedIndex = 0;
            toolTip.SetToolTip(cbxOppDirAction,
                               Language.T("Nothing - cancels the additional orders.") + Environment.NewLine +
                               Language.T("Reduce - reduces or closes a position.") + Environment.NewLine +
                               Language.T("Close - closes the position.") + Environment.NewLine +
                               Language.T("Reverse - reverses the position."));

            // Label MaxOpen Lots
            lblMaxOpenLots.Parent    = pnlAmounts;
            lblMaxOpenLots.ForeColor = colorText;
            lblMaxOpenLots.BackColor = Color.Transparent;
            lblMaxOpenLots.AutoSize  = true;
            lblMaxOpenLots.Text      = Language.T("Maximum number of open lots");

            // NumericUpDown MaxOpen Lots
            nudMaxOpenLots.Parent = pnlAmounts;
            nudMaxOpenLots.Name   = "nudMaxOpenLots";
            nudMaxOpenLots.BeginInit();
            nudMaxOpenLots.Minimum       = 0.01M;
            nudMaxOpenLots.Maximum       = 100;
            nudMaxOpenLots.Increment     = 0.01M;
            nudMaxOpenLots.Value         = 20;
            nudMaxOpenLots.DecimalPlaces = 2;
            nudMaxOpenLots.TextAlign     = HorizontalAlignment.Center;
            nudMaxOpenLots.EndInit();

            // Radio Button Constant Units
            rbConstantUnits.Parent    = pnlAmounts;
            rbConstantUnits.ForeColor = colorText;
            rbConstantUnits.BackColor = Color.Transparent;
            rbConstantUnits.Checked   = true;
            rbConstantUnits.AutoSize  = true;
            rbConstantUnits.Name      = "rbConstantUnits";
            rbConstantUnits.Text      = Language.T("Trade a constant number of lots");

            // Radio Button Variable Units
            rbVariableUnits.Parent    = pnlAmounts;
            rbVariableUnits.ForeColor = colorText;
            rbVariableUnits.BackColor = Color.Transparent;
            rbVariableUnits.Checked   = false;
            rbVariableUnits.AutoSize  = false;
            rbVariableUnits.Name      = "rbVariableUnits";
            rbVariableUnits.Text      = Language.T("Trade percent of your account. The percentage values show the part of the account equity used to cover the required margin.");

            // Label Entry Lots
            lblEntryLots.Parent    = pnlAmounts;
            lblEntryLots.ForeColor = colorText;
            lblEntryLots.BackColor = Color.Transparent;
            lblEntryLots.AutoSize  = true;
            lblEntryLots.Text      = Language.T("Number of entry lots for a new position");

            // NumericUpDown Entry Lots
            nudEntryLots.Parent = pnlAmounts;
            nudEntryLots.Name   = "nudEntryLots";
            nudEntryLots.BeginInit();
            nudEntryLots.Minimum       = 0.01M;
            nudEntryLots.Maximum       = 100;
            nudEntryLots.Increment     = 0.01M;
            nudEntryLots.Value         = 1;
            nudEntryLots.DecimalPlaces = 2;
            nudEntryLots.TextAlign     = HorizontalAlignment.Center;
            nudEntryLots.EndInit();

            // Label Entry Lots %
            lblPercent1.Parent    = pnlAmounts;
            lblPercent1.ForeColor = colorText;
            lblPercent1.BackColor = Color.Transparent;

            // Label Adding Lots
            lblAddingLots.Parent    = pnlAmounts;
            lblAddingLots.ForeColor = colorText;
            lblAddingLots.BackColor = Color.Transparent;
            lblAddingLots.AutoSize  = true;
            lblAddingLots.Text      = Language.T("In case of addition - number of lots to add");

            // NumericUpDown Adding Lots
            nudAddingLots.Parent = pnlAmounts;
            nudAddingLots.Name   = "nudAddingLots";
            nudAddingLots.BeginInit();
            nudAddingLots.Minimum       = 0.01M;
            nudAddingLots.Maximum       = 100;
            nudAddingLots.Increment     = 0.01M;
            nudAddingLots.Value         = 1;
            nudAddingLots.DecimalPlaces = 2;
            nudAddingLots.TextAlign     = HorizontalAlignment.Center;
            nudAddingLots.EndInit();

            // Label Adding Lots %
            lblPercent2.Parent    = pnlAmounts;
            lblPercent2.ForeColor = colorText;
            lblPercent2.BackColor = Color.Transparent;

            // Label Reducing Lots
            lblReducingLots.Parent    = pnlAmounts;
            lblReducingLots.ForeColor = colorText;
            lblReducingLots.BackColor = Color.Transparent;
            lblReducingLots.AutoSize  = true;
            lblReducingLots.Text      = Language.T("In case of reduction - number of lots to close");

            // NumericUpDown Reducing Lots
            nudReducingLots.Parent = pnlAmounts;
            nudReducingLots.Name   = "nudReducingLots";
            nudReducingLots.BeginInit();
            nudReducingLots.Minimum       = 0.01M;
            nudReducingLots.Maximum       = 100;
            nudReducingLots.Increment     = 0.01m;
            nudReducingLots.DecimalPlaces = 2;
            nudReducingLots.Value         = 1;
            nudReducingLots.TextAlign     = HorizontalAlignment.Center;
            nudReducingLots.EndInit();

            // Label Reducing Lots %
            lblPercent3.Parent    = pnlAmounts;
            lblPercent3.ForeColor = colorText;
            lblPercent3.BackColor = Color.Transparent;

            // CheckBox Permanent Stop Loss
            chbPermaSL.Name      = "chbPermaSL";
            chbPermaSL.Parent    = pnlProtection;
            chbPermaSL.ForeColor = colorText;
            chbPermaSL.BackColor = Color.Transparent;
            chbPermaSL.AutoCheck = true;
            chbPermaSL.AutoSize  = true;
            chbPermaSL.Checked   = false;
            chbPermaSL.Text      = Language.T("Permanent Stop Loss");

            // ComboBox cbxPermaSLType
            cbxPermaSLType.Parent        = pnlProtection;
            cbxPermaSLType.Name          = "cbxPermaSLType";
            cbxPermaSLType.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxPermaSLType.Items.AddRange(new string[] { Language.T("Relative"), Language.T("Absolute") });
            cbxPermaSLType.SelectedIndex = 0;

            // NumericUpDown Permanent S/L
            nudPermaSL.Name   = "nudPermaSL";
            nudPermaSL.Parent = pnlProtection;
            nudPermaSL.BeginInit();
            nudPermaSL.Minimum   = 5;
            nudPermaSL.Maximum   = 5000;
            nudPermaSL.Increment = 1;
            nudPermaSL.Value     = (Data.InstrProperties.Digits == 5 || Data.InstrProperties.Digits == 3) ? 1000 : 100;
            nudPermaSL.TextAlign = HorizontalAlignment.Center;
            nudPermaSL.EndInit();

            // CheckBox Permanent Take Profit
            chbPermaTP.Name      = "chbPermaTP";
            chbPermaTP.Parent    = pnlProtection;
            chbPermaTP.ForeColor = colorText;
            chbPermaTP.BackColor = Color.Transparent;
            chbPermaTP.AutoCheck = true;
            chbPermaTP.AutoSize  = true;
            chbPermaTP.Checked   = false;
            chbPermaTP.Text      = Language.T("Permanent Take Profit");

            // ComboBox cbxPermaTPType
            cbxPermaTPType.Parent        = pnlProtection;
            cbxPermaTPType.Name          = "cbxPermaTPType";
            cbxPermaTPType.DropDownStyle = ComboBoxStyle.DropDownList;
            cbxPermaTPType.Items.AddRange(new string[] { Language.T("Relative"), Language.T("Absolute") });
            cbxPermaTPType.SelectedIndex = 0;

            // NumericUpDown Permanent Take Profit
            nudPermaTP.Parent = pnlProtection;
            nudPermaTP.Name   = "nudPermaTP";
            nudPermaTP.BeginInit();
            nudPermaTP.Minimum   = 5;
            nudPermaTP.Maximum   = 5000;
            nudPermaTP.Increment = 1;
            nudPermaTP.Value     = (Data.InstrProperties.Digits == 5 || Data.InstrProperties.Digits == 3) ? 1000 : 100;
            nudPermaTP.TextAlign = HorizontalAlignment.Center;
            nudPermaTP.EndInit();

            //Button Default
            btnDefault.Parent = this;
            btnDefault.Name   = "btnDefault";
            btnDefault.Text   = Language.T("Default");
            btnDefault.Click += new EventHandler(BtnDefault_Click);
            btnDefault.UseVisualStyleBackColor = true;

            //Button Cancel
            btnCancel.Parent                  = this;
            btnCancel.Name                    = "btnCancel";
            btnCancel.Text                    = Language.T("Cancel");
            btnCancel.DialogResult            = DialogResult.Cancel;
            btnCancel.UseVisualStyleBackColor = true;

            //Button Accept
            btnAccept.Parent                  = this;
            btnAccept.Name                    = "btnAccept";
            btnAccept.Text                    = Language.T("Accept");
            btnAccept.DialogResult            = DialogResult.OK;
            btnAccept.UseVisualStyleBackColor = true;

            return;
        }
コード例 #27
0
        /// <summary>
        /// Initialize the form and controls
        /// </summary>
        public Comparator()
        {
            PnlOptions        = new Panel();
            PnlChart          = new Panel();
            ProgressBar       = new ProgressBar();
            LblAverageBalance = new Label();
            NumRandom         = new NumericUpDown();
            LblRandomCycles   = new Label();
            BtnCalculate      = new Button();
            BtnClose          = new Button();

            Text            = Language.T("Comparator");
            BackColor       = LayoutColors.ColorFormBack;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            Icon            = Data.Icon;
            MaximizeBox     = false;
            MinimizeBox     = false;
            ShowInTaskbar   = false;
            FormClosing    += ActionsFormClosing;

            _isPaintChart = false;

            //Button Calculate
            BtnCalculate.Parent = this;
            BtnCalculate.Name   = "btnCalculate";
            BtnCalculate.Text   = Language.T("Calculate");
            BtnCalculate.Click += BtnCalculateClick;
            BtnCalculate.UseVisualStyleBackColor = true;

            //Button Close
            BtnClose.Parent                  = this;
            BtnClose.Name                    = "btnClose";
            BtnClose.Text                    = Language.T("Close");
            BtnClose.DialogResult            = DialogResult.OK;
            BtnClose.UseVisualStyleBackColor = true;

            // ProgressBar
            ProgressBar.Parent  = this;
            ProgressBar.Minimum = 1;
            ProgressBar.Maximum = 100;
            ProgressBar.Step    = 1;

            PnlChart.Parent    = this;
            PnlChart.ForeColor = LayoutColors.ColorControlText;
            PnlChart.Paint    += PnlChartPaint;

            PnlOptions.Parent    = this;
            PnlOptions.ForeColor = LayoutColors.ColorControlText;
            PnlOptions.Paint    += PnlOptionsPaint;

            _countMethods = Enum.GetValues(typeof(InterpolationMethod)).Length;
            AchboxMethods = new CheckBox[_countMethods];
            for (int i = 0; i < _countMethods; i++)
            {
                AchboxMethods[i] = new CheckBox
                {
                    Parent    = PnlOptions,
                    Text      = Language.T(Enum.GetNames(typeof(InterpolationMethod))[i]),
                    Tag       = Enum.GetValues(typeof(InterpolationMethod)).GetValue(i),
                    Checked   = true,
                    BackColor = Color.Transparent,
                    AutoSize  = true
                };
                AchboxMethods[i].CheckedChanged += ComparatorCheckedChanged;
            }

            // Label Average Balance
            LblAverageBalance.Parent    = PnlOptions;
            LblAverageBalance.AutoSize  = true;
            LblAverageBalance.Text      = Language.T("Average balance");
            LblAverageBalance.ForeColor = LayoutColors.ColorControlText;
            LblAverageBalance.BackColor = Color.Transparent;
            LblAverageBalance.TextAlign = ContentAlignment.MiddleLeft;

            // NumUpDown random cycles
            NumRandom.BeginInit();
            NumRandom.Parent    = this;
            NumRandom.Value     = 25;
            NumRandom.Minimum   = 3;
            NumRandom.Maximum   = 100;
            NumRandom.TextAlign = HorizontalAlignment.Center;
            NumRandom.EndInit();

            // Label Random Cycles
            LblRandomCycles.Parent    = this;
            LblRandomCycles.AutoSize  = true;
            LblRandomCycles.ForeColor = LayoutColors.ColorControlText;
            LblRandomCycles.BackColor = Color.Transparent;
            LblRandomCycles.Text      = Language.T("Random iterations");
            LblRandomCycles.TextAlign = ContentAlignment.MiddleLeft;

            // Colors
            _penOptimistic  = new Pen(LayoutColors.ComparatorChartOptimisticLine);
            _penPessimistic = new Pen(LayoutColors.ComparatorChartPessimisticLine);
            _penShortest    = new Pen(LayoutColors.ComparatorChartShortestLine);
            _penNearest     = new Pen(LayoutColors.ComparatorChartNearestLine);
            _penRandom      = new Pen(LayoutColors.ComparatorChartRandomLine);
            _penRandBands   = new Pen(LayoutColors.ComparatorChartRandomBands);
            _brushRandArea  = new SolidBrush(LayoutColors.ComparatorChartRandomArea);
            _penBalance     = new Pen(LayoutColors.ComparatorChartBalanceLine)
            {
                Width = 2
            };

            // BackGroundWorker
            _bgWorker = new BackgroundWorker {
                WorkerReportsProgress = true, WorkerSupportsCancellation = true
            };
            _bgWorker.DoWork             += BgWorkerDoWork;
            _bgWorker.ProgressChanged    += BgWorkerProgressChanged;
            _bgWorker.RunWorkerCompleted += BgWorkerRunWorkerCompleted;

            Configs.TradeUntilMarginCall = false;
        }
コード例 #28
0
        /// <summary>
        /// Repaint the panel Info
        /// </summary>
        private void PnlInfoPaint(object sender, PaintEventArgs e)
        {
            // +------------------------------------------------------+
            // |                   Data                               |
            // |------------------- ----------------------------------+
            // | Period  | Bars  | From | Until | Cover |  %  | Label |
            // |------------------------------------------------------+
            //xp0       xp1     xp2    xp3     xp4     xp5   xp6     xp7

            Graphics g = e.Graphics;

            g.Clear(LayoutColors.ColorControlBack);

            if (!Data.IsData || !Data.IsResult)
            {
                return;
            }

            var       pnl    = (Panel)sender;
            const int border = 2;
            const int xp0    = border;
            const int xp1    = 80;
            const int xp2    = 140;
            const int xp3    = 200;
            const int xp4    = 260;
            const int xp5    = 320;
            const int xp6    = 370;
            int       xp7    = pnl.ClientSize.Width - border;

            var size = new Size(xp7 - xp0, _infoRowHeight);

            var sf = new StringFormat {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near
            };

            // Caption background
            var   pntStart     = new PointF(0, 0);
            SizeF szfCaption   = new Size(pnl.ClientSize.Width - 0, 2 * _infoRowHeight);
            var   rectfCaption = new RectangleF(pntStart, szfCaption);

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

            // Caption Text
            var stringFormatCaption = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Near
            };
            string stringCaptionText = Language.T("Intrabar Data");
            float  captionWidth      = Math.Min(InfoPanel.ClientSize.Width, xp7 - xp0);
            float  captionTextWidth  = g.MeasureString(stringCaptionText, _fontInfo).Width;
            float  captionTextX      = Math.Max((captionWidth - captionTextWidth) / 2f, 0);
            var    pfCaptionText     = new PointF(captionTextX, 0);
            var    sfCaptionText     = new SizeF(captionWidth - captionTextX, _infoRowHeight);

            rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);

            Brush brush = new SolidBrush(LayoutColors.ColorCaptionText);

            // First caption row
            g.DrawString(stringCaptionText, _fontInfo, brush, rectfCaption, stringFormatCaption);

            // Second title row
            g.DrawString(Language.T("Period"), _fontInfo, brush, (xp1 + xp0) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Bars"), _fontInfo, brush, (xp2 + xp1) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("From"), _fontInfo, brush, (xp3 + xp2) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Until"), _fontInfo, brush, (xp4 + xp3) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Coverage"), _fontInfo, brush, (xp5 + xp4) / 2f, _infoRowHeight, sf);
            g.DrawString("%", _fontInfo, brush, (xp6 + xp5) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Label"), _fontInfo, brush, (xp7 + xp6) / 2f, _infoRowHeight, sf);

            brush = new SolidBrush(LayoutColors.ColorControlText);
            int allPeriods = Enum.GetValues(typeof(DataPeriods)).Length;

            for (int period = 0; period <= allPeriods; period++)
            {
                int y     = (period + 2) * _infoRowHeight;
                var point = new Point(xp0, y);

                if (Math.Abs(period % 2f - 0) > 0.0001)
                {
                    g.FillRectangle(new SolidBrush(LayoutColors.ColorEvenRowBack), new Rectangle(point, size));
                }
            }

            // Tick statistics
            if (_isTickDataFile)
            {
                g.DrawString(Language.T("Tick"), _fontInfo, brush, (xp1 + xp0) / 2, 2 * _infoRowHeight, sf);
                if (Data.IsTickData && Configs.UseTickData)
                {
                    int firstBarWithTicks = -1;
                    int lastBarWithTicks  = -1;
                    int tickBars          = 0;
                    for (int b = 0; b < Data.Bars; b++)
                    {
                        if (firstBarWithTicks == -1 && Data.TickData[b] != null)
                        {
                            firstBarWithTicks = b;
                        }
                        if (Data.TickData[b] != null)
                        {
                            lastBarWithTicks = b;
                            tickBars++;
                        }
                    }
                    double percentage = 100d * tickBars / Data.Bars;

                    int    y     = 2 * _infoRowHeight;
                    string ticks = (Data.Ticks > 999999) ? (Data.Ticks / 1000).ToString(CultureInfo.InvariantCulture) + "K" : Data.Ticks.ToString(CultureInfo.InvariantCulture);
                    g.DrawString(ticks, _fontInfo, brush, (xp2 + xp1) / 2, y, sf);
                    g.DrawString((firstBarWithTicks + 1).ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp3 + xp2) / 2, y, sf);
                    g.DrawString((lastBarWithTicks + 1).ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp4 + xp3) / 2, y, sf);
                    g.DrawString(tickBars.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp5 + xp4) / 2, y, sf);
                    g.DrawString(percentage.ToString("F2"), _fontInfo, brush, (xp6 + xp5) / 2, y, sf);

                    var rectf = new RectangleF(xp6 + 10, y + 4, xp7 - xp6 - 20, 9);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.min1], 60);
                    rectf = new RectangleF(xp6 + 10, y + 7, xp7 - xp6 - 20, 3);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.day], 60);
                }
            }

            for (int prd = 0; prd < allPeriods; prd++)
            {
                int startY = _isTickDataFile ? 3 : 2;
                int y      = (prd + startY) * _infoRowHeight;

                var    period      = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);
                int    intraBars   = Data.IntraBars == null || !Data.IsIntrabarData ? 0 : Data.IntraBars[prd];
                int    fromBar     = 0;
                int    untilBar    = 0;
                int    coveredBars = 0;
                double percentage  = 0;

                bool isMultyAreas = false;
                if (intraBars > 0)
                {
                    bool isFromBarFound  = false;
                    bool isUntilBarFound = false;
                    untilBar = Data.Bars;
                    for (int bar = 0; bar < Data.Bars; bar++)
                    {
                        if (!isFromBarFound && Data.IntraBarsPeriods[bar] == period)
                        {
                            fromBar        = bar;
                            isFromBarFound = true;
                        }
                        if (isFromBarFound && !isUntilBarFound &&
                            (Data.IntraBarsPeriods[bar] != period || bar == Data.Bars - 1))
                        {
                            if (bar < Data.Bars - 1)
                            {
                                isUntilBarFound = true;
                                untilBar        = bar;
                            }
                            else
                            {
                                untilBar = Data.Bars;
                            }
                            coveredBars = untilBar - fromBar;
                        }
                        if (isFromBarFound && isUntilBarFound && Data.IntraBarsPeriods[bar] == period)
                        {
                            isMultyAreas = true;
                            coveredBars++;
                        }
                    }
                    if (isFromBarFound)
                    {
                        percentage = 100d * coveredBars / Data.Bars;
                        fromBar++;
                    }
                    else
                    {
                        fromBar     = 0;
                        untilBar    = 0;
                        coveredBars = 0;
                        percentage  = 0;
                    }
                }
                else if (period == Data.Period)
                {
                    intraBars   = Data.Bars;
                    fromBar     = 1;
                    untilBar    = Data.Bars;
                    coveredBars = Data.Bars;
                    percentage  = 100;
                }

                g.DrawString(Data.DataPeriodToString(period), _fontInfo, brush, (xp1 + xp0) / 2, y, sf);

                if (coveredBars > 0 || period == Data.Period)
                {
                    g.DrawString(intraBars.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp2 + xp1) / 2, y, sf);
                    g.DrawString(fromBar.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp3 + xp2) / 2, y, sf);
                    g.DrawString(untilBar.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp4 + xp3) / 2, y, sf);
                    g.DrawString(coveredBars.ToString(CultureInfo.InvariantCulture) + (isMultyAreas ? "*" : ""), _fontInfo, brush, (xp5 + xp4) / 2, y, sf);
                    g.DrawString(percentage.ToString("F2"), _fontInfo, brush, (xp6 + xp5) / 2, y, sf);

                    var rectf = new RectangleF(xp6 + 10, y + 4, xp7 - xp6 - 20, 9);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[period], 60);
                }
            }

            var penLine = new Pen(LayoutColors.ColorJournalLines);

            g.DrawLine(penLine, xp1, 2 * _infoRowHeight, xp1, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp2, 2 * _infoRowHeight, xp2, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp3, 2 * _infoRowHeight, xp3, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp4, 2 * _infoRowHeight, xp4, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp5, 2 * _infoRowHeight, xp5, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp6, 2 * _infoRowHeight, xp6, pnl.ClientSize.Height);

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

            g.DrawLine(penBorder, 1, 2 * _infoRowHeight, 1, pnl.ClientSize.Height);
            g.DrawLine(penBorder, pnl.ClientSize.Width - border + 1, 2 * _infoRowHeight, pnl.ClientSize.Width - border + 1,
                       pnl.ClientSize.Height);
            g.DrawLine(penBorder, 0, pnl.ClientSize.Height - border + 1, pnl.ClientSize.Width,
                       pnl.ClientSize.Height - border + 1);
        }
コード例 #29
0
        /// <summary>
        /// Paints the charts
        /// </summary>
        private void PnlChartPaint(object sender, PaintEventArgs e)
        {
            var      pnl = (Panel)sender;
            Graphics g   = e.Graphics;

            const int space  = 5;
            const int border = 2;

            // Chart Title
            string unit                = " [" + (Configs.AccountInMoney ? Configs.AccountCurrency : Language.T("pips")) + "]";
            string str                 = Language.T("Balance Chart") + unit;
            var    font                = new Font(Font.FontFamily, 9);
            var    fCaptionHeight      = (float)Math.Max(font.Height, 18);
            var    rectfCaption        = new RectangleF(0, 0, pnl.ClientSize.Width, fCaptionHeight);
            var    stringFormatCaption = new StringFormat
            {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
            };

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(str, Font, new SolidBrush(LayoutColors.ColorCaptionText), rectfCaption, stringFormatCaption);

            // Paint the panel background
            var rectClient = new RectangleF(border, fCaptionHeight, pnl.ClientSize.Width - 2 * border,
                                            pnl.Height - fCaptionHeight - border);

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

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

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

            if (!_isPaintChart)
            {
                if (Backtester.AmbiguousBars == 0)
                {
                    string sNote     = Language.T("The Comparator is useful when the backtest shows ambiguous bars!");
                    var    rectfNote = new RectangleF(0, 30, pnl.ClientSize.Width, Font.Height);
                    g.DrawString(sNote, Font, new SolidBrush(LayoutColors.ColorChartFore), rectfNote,
                                 stringFormatCaption);
                }
                return;
            }

            int bars = Data.Bars - Data.FirstBar;
            int max  = (int)Math.Max(_maximum, _maximumRandom) + 1;
            int min  = (int)Math.Min(_minimum, _minimumRandom) - 1;

            min = (int)Math.Floor(min / 10f) * 10;
            int yTop       = (int)fCaptionHeight + 2 * space + 1;
            int yBottom    = (pnl.ClientSize.Height - 2 * space - border);
            var labelWidth =
                (int)
                Math.Max(g.MeasureString(min.ToString(CultureInfo.InvariantCulture), Font).Width,
                         g.MeasureString(max.ToString(CultureInfo.InvariantCulture), Font).Width);

            labelWidth = Math.Max(labelWidth, 30);
            int xRight = pnl.ClientSize.Width - border - space - labelWidth;

            //
            // Grid
            //
            int cntLabels = Math.Max((yBottom - yTop) / 20, 1);
            var delta     = (float)Math.Max(Math.Round((max - min) / (float)cntLabels), 10);
            int step      = (int)Math.Ceiling(delta / 10) * 10;

            cntLabels = (int)Math.Ceiling((max - min) / (float)step);
            max       = min + cntLabels * step;
            float scaleY    = (yBottom - yTop) / (cntLabels * (float)step);
            Brush brushFore = new SolidBrush(LayoutColors.ColorChartFore);
            var   penGrid   = new Pen(LayoutColors.ColorChartGrid)
            {
                DashStyle = DashStyle.Dash, DashPattern = new float[] { 4, 2 }
            };

            // Price labels
            for (int label = min; label <= max; label += step)
            {
                var labelY = (int)(yBottom - (label - min) * scaleY);
                g.DrawString(label.ToString(CultureInfo.InvariantCulture), Font, brushFore, xRight,
                             labelY - Font.Height / 2 - 1);
                g.DrawLine(penGrid, border + space, labelY, xRight, labelY);
            }

            float fScaleX = (xRight - 2 * space - border) / (float)bars;

            if (_isRandom)
            {
                // Draws the random area and Min Max lines
                var apntMinRandom = new PointF[bars];
                var apntMaxRandom = new PointF[bars];
                for (int iBar = 0; iBar < bars; iBar++)
                {
                    apntMinRandom[iBar].X = border + space + iBar * fScaleX;
                    apntMinRandom[iBar].Y = yBottom - (_afMinRandom[iBar] - min) * scaleY;
                    apntMaxRandom[iBar].X = border + space + iBar * fScaleX;
                    apntMaxRandom[iBar].Y = yBottom - (_afMaxRandom[iBar] - min) * scaleY;
                }
                apntMinRandom[0].Y = apntMaxRandom[0].Y;
                var path = new GraphicsPath();
                path.AddLines(apntMinRandom);
                path.AddLine(apntMinRandom[bars - 1], apntMaxRandom[bars - 1]);
                path.AddLines(apntMaxRandom);
                var region = new Region(path);
                g.FillRegion(_brushRandArea, region);
                g.DrawLines(_penRandBands, apntMinRandom);
                g.DrawLines(_penRandBands, apntMaxRandom);
            }

            // Draws the lines
            for (int m = 0; m < _countMethods; m++)
            {
                if (!AchboxMethods[m].Checked)
                {
                    continue;
                }

                var apntLines = new PointF[bars];
                for (int iBar = 0; iBar < bars; iBar++)
                {
                    apntLines[iBar].X = border + space + iBar * fScaleX;
                    apntLines[iBar].Y = yBottom - (_afMethods[m, iBar] - min) * scaleY;
                }

                var pen = new Pen(LayoutColors.ColorSignalRed);
                switch ((InterpolationMethod)AchboxMethods[m].Tag)
                {
                case InterpolationMethod.Pessimistic:
                    pen = _penPessimistic;
                    break;

                case InterpolationMethod.Shortest:
                    pen = _penShortest;
                    break;

                case InterpolationMethod.Nearest:
                    pen = _penNearest;
                    break;

                case InterpolationMethod.Optimistic:
                    pen = _penOptimistic;
                    break;

                case InterpolationMethod.Random:
                    pen = _penRandom;
                    break;
                }
                g.DrawLines(pen, apntLines);
            }

            // Draws the average balance
            var apntBalance = new PointF[bars];

            for (int bar = 0; bar < bars; bar++)
            {
                apntBalance[bar].X = border + space + bar * fScaleX;
                apntBalance[bar].Y = yBottom - (_afBalance[bar] - min) * scaleY;
            }
            g.DrawLines(_penBalance, apntBalance);

            // Coordinate axes
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), border + space - 1, yTop - space, border + space - 1,
                       yBottom);
            g.DrawLine(new Pen(LayoutColors.ColorChartFore), border + space, yBottom, xRight, yBottom);

            // Balance label
            float fBalanceY = yBottom - (_afBalance[bars - 1] - min) * scaleY;

            g.DrawLine(new Pen(LayoutColors.ColorChartCross), border + space, fBalanceY, xRight - space, fBalanceY);

            var    szBalance = new Size(labelWidth + space, Font.Height + 2);
            var    point     = new Point(xRight - space + 2, (int)(fBalanceY - Font.Height / 2.0 - 1));
            var    rec       = new Rectangle(point, szBalance);
            string sBalance  = ((int)_afBalance[bars - 1]).ToString(CultureInfo.InvariantCulture);

            g.FillRectangle(new SolidBrush(LayoutColors.ColorLabelBack), rec);
            g.DrawRectangle(new Pen(LayoutColors.ColorChartCross), rec);
            g.DrawString(sBalance, Font, new SolidBrush(LayoutColors.ColorLabelText), rec, stringFormatCaption);

            // Scanning note
            var fontNote = new Font(Font.FontFamily, Font.Size - 1);

            if (Configs.Autoscan && !Data.IsIntrabarData)
            {
                g.DrawString(Language.T("Load intrabar data"), fontNote, Brushes.Red, border + space, fCaptionHeight - 2);
            }
            else if (Backtester.IsScanPerformed)
            {
                g.DrawString(Language.T("Scanned") + " MQ " + Data.ModellingQuality.ToString("N2") + "%", fontNote,
                             Brushes.LimeGreen, border + space, fCaptionHeight - 2);
            }

            // Scanned bars
            if (Data.IntraBars != null && Data.IsIntrabarData && Backtester.IsScanPerformed)
            {
                g.DrawLine(new Pen(LayoutColors.ColorChartFore), border + space - 1, yBottom, border + space - 1,
                           yBottom + 8);
                DataPeriods dataPeriod = Data.Period;
                Color       color      = Data.PeriodColor[Data.Period];
                int         iFromBar   = Data.FirstBar;
                for (int bar = Data.FirstBar; bar < Data.Bars; bar++)
                {
                    if (Data.IntraBarsPeriods[bar] != dataPeriod || bar == Data.Bars - 1)
                    {
                        int xStart = (int)((iFromBar - Data.FirstBar) * fScaleX) + border + space;
                        int xEnd   = (int)((bar - Data.FirstBar) * fScaleX) + border + space;
                        iFromBar   = bar;
                        dataPeriod = Data.IntraBarsPeriods[bar];
                        Data.GradientPaint(g, new RectangleF(xStart, yBottom + 3, xEnd - xStart + 2, 5), color, 60);
                        color = Data.PeriodColor[Data.IntraBarsPeriods[bar]];
                    }
                }
            }
        }
コード例 #30
0
        /// <summary>
        /// Gets the date regex pattern that matches the data file.
        /// </summary>
        /// <param name="dataString">The data file content.</param>
        /// <returns>Date regex pattern.</returns>
        private string GetDateMatchPattern(string dataString)
        {
            string       line;
            int          yearPos     = 0;
            int          monthPos    = 0;
            int          dayPos      = 0;
            const string datePattern = @"(?<1>\d{1,4})[\./-](?<2>\d{1,4})[\./-](?<3>\d{1,4})";
            var          regexDate   = new Regex(datePattern, RegexOptions.Compiled);

            var stringReader = new StringReader(dataString);

            while ((line = stringReader.ReadLine()) != null)
            {
                Match matchDate = regexDate.Match(line);

                if (!matchDate.Success)
                {
                    continue;
                }

                int pos1 = int.Parse(matchDate.Result("$1"));
                int pos2 = int.Parse(matchDate.Result("$2"));
                int pos3 = int.Parse(matchDate.Result("$3"));

                // Determines the year index
                if (yearPos == 0)
                {
                    if (pos1 > 31)
                    {
                        yearPos  = 1;
                        monthPos = 2;
                        dayPos   = 3;
                        break;
                    }
                    if (pos3 > 31)
                    {
                        yearPos = 3;
                    }
                }

                // Determines the day index
                if (dayPos == 0 && yearPos > 0)
                {
                    if (yearPos == 1)
                    {
                        dayPos   = 2;
                        monthPos = 3;
                        break;
                    }
                    if (yearPos == 3)
                    {
                        if (pos1 > 12)
                        {
                            dayPos   = 1;
                            monthPos = 2;
                            break;
                        }
                        if (pos2 > 12)
                        {
                            monthPos = 1;
                            dayPos   = 2;
                            break;
                        }
                    }
                }

                // Determines the month index
                if (dayPos > 0 && yearPos > 0)
                {
                    if (yearPos != 1 && dayPos != 1)
                    {
                        monthPos = 1;
                    }
                    else if (yearPos != 2 && dayPos != 2)
                    {
                        monthPos = 2;
                    }
                    else if (yearPos != 3 && dayPos != 3)
                    {
                        monthPos = 3;
                    }
                }

                if (yearPos > 0 && monthPos > 0 && dayPos > 0)
                {
                    break;
                }
            }
            stringReader.Close();

            // If the date format is not recognized we try to find the number of changes
            if (yearPos == 0 || monthPos == 0 || dayPos == 0)
            {
                int old1 = 0;
                int old2 = 0;
                int old3 = 0;

                int changes1 = -1;
                int changes2 = -1;
                int changes3 = -1;

                stringReader = new StringReader(dataString);
                while ((line = stringReader.ReadLine()) != null)
                {
                    Match matchDate = regexDate.Match(line);

                    if (!matchDate.Success)
                    {
                        continue;
                    }

                    int pos1 = int.Parse(matchDate.Result("$1"));
                    int pos2 = int.Parse(matchDate.Result("$2"));
                    int pos3 = int.Parse(matchDate.Result("$3"));

                    if (pos1 != old1)
                    {
                        // pos1 has changed
                        old1 = pos1;
                        changes1++;
                    }
                    if (pos2 != old2)
                    {
                        // pos2 has changed
                        old2 = pos2;
                        changes2++;
                    }
                    if (pos3 != old3)
                    {
                        // date2 has changed
                        old3 = pos3;
                        changes3++;
                    }


                    // Check number of changes
                    if (changes1 > changes2 && changes1 > changes2)
                    {
                        dayPos   = 1;
                        monthPos = 2;
                        yearPos  = 3;
                        break;
                    }
                    if (changes3 > changes1 && changes3 > changes2)
                    {
                        dayPos   = 3;
                        monthPos = 2;
                        yearPos  = 1;
                        break;
                    }
                    if (changes2 > changes1 && changes2 > changes3)
                    {
                        yearPos  = 3;
                        monthPos = 1;
                        dayPos   = 2;
                        break;
                    }
                }
                stringReader.Close();

                if (yearPos > 0)
                {
                    // The year position is known
                    if (yearPos == 1)
                    {
                        if (changes3 > changes2)
                        {
                            monthPos = 2;
                            dayPos   = 3;
                        }
                        else if (changes2 > changes3)
                        {
                            monthPos = 3;
                            dayPos   = 2;
                        }
                    }
                    else if (yearPos == 3)
                    {
                        if (changes2 > changes1)
                        {
                            monthPos = 1;
                            dayPos   = 2;
                        }
                        else if (changes1 > changes2)
                        {
                            monthPos = 2;
                            dayPos   = 1;
                        }
                    }
                }

                // If we don't know the year position but know that the day is somewhere in the end.
                // The year must be on the other end of the pattern because the year doesn't stay in the middle.
                if (yearPos == 0 && dayPos == 1)
                {
                    yearPos  = 3;
                    monthPos = 2;
                }
                if (yearPos == 0 && dayPos == 3)
                {
                    yearPos  = 1;
                    monthPos = 2;
                }

                if (yearPos == 0)
                {
                    // The year position is unknown
                    if (changes1 >= 0 && changes2 > changes1 && changes3 > changes2)
                    {
                        yearPos  = 1;
                        monthPos = 2;
                        dayPos   = 3;
                    }
                    else if (changes1 >= 0 && changes3 > changes1 && changes2 > changes3)
                    {
                        yearPos  = 1;
                        monthPos = 3;
                        dayPos   = 2;
                    }
                    else if (changes2 >= 0 && changes1 > changes2 && changes3 > changes1)
                    {
                        yearPos  = 2;
                        monthPos = 1;
                        dayPos   = 3;
                    }
                    else if (changes2 >= 0 && changes3 > changes2 && changes1 > changes3)
                    {
                        yearPos  = 2;
                        monthPos = 3;
                        dayPos   = 1;
                    }
                    else if (changes3 >= 0 && changes1 > changes3 && changes2 > changes1)
                    {
                        yearPos  = 3;
                        monthPos = 1;
                        dayPos   = 2;
                    }
                    else if (changes3 >= 0 && changes2 > changes3 && changes1 > changes2)
                    {
                        yearPos  = 3;
                        monthPos = 2;
                        dayPos   = 1;
                    }
                }
            }

            string dateMatchPattern = "";

            if (yearPos * monthPos * dayPos > 0)
            {
                if (yearPos == 1 && monthPos == 2 && dayPos == 3)
                {
                    dateMatchPattern = @"(?<year>\d{1,4})[\./-](?<month>\d{1,4})[\./-](?<day>\d{1,4})";
                }
                else if (yearPos == 3 && monthPos == 1 && dayPos == 2)
                {
                    dateMatchPattern = @"(?<month>\d{1,4})[\./-](?<day>\d{1,4})[\./-](?<year>\d{1,4})";
                }
                else if (yearPos == 3 && monthPos == 2 && dayPos == 1)
                {
                    dateMatchPattern = @"(?<day>\d{1,4})[\./-](?<month>\d{1,4})[\./-](?<year>\d{1,4})";
                }
            }
            else
            {
                throw new Exception(Language.T("Could not determine the date format!"));
            }

            return(dateMatchPattern);
        }