private void ChildFormBalanceSheet_Load(object sender, EventArgs e)
        {
            financialStatementModelBindingSource.DataSource = FinancialStatementDao.GetFinancialStatements();
            diagram = (XYDiagram)BalanceChart.Diagram;

            BalanceChart.Animate();
        }
        /// <summary>
        /// Perform initializing
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (CompactMode)
            {
                InfoPanel.Visible    = false;
                BalanceChart.Visible = false;
                LblProgress.Visible  = true;
                ChbAutoscan.Visible  = false;

                Width   = 300;
                Height  = 95;
                TopMost = true;

                StartLoading();
            }
            else
            {
                LblProgress.Visible = false;
                ChbAutoscan.Visible = true;
                BalanceChart.SetChartData();
                Width  = 460;
                Height = 540;
                if (!_isTickDataFile)
                {
                    Height -= _infoRowHeight;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Resets parameters and recalculates the strategy.
        /// </summary>
        private void ResetStrategyParameters()
        {
            for (int param = 0; param < _parameters; param++)
            {
                int    point        = AParameter[param].Point;
                string stringFormat = "{0:F" + point + "}";
                double value        = _initialValues[param];

                AParameter[param].Value        = value;
                AlblParameterValue[param].Text = string.Format(stringFormat, value);
            }

            int lastSlot = -1;

            for (int param = 0; param < _parameters; param++)
            {
                if (AParameter[param].Type != OptimizerParameterType.Indicator)
                {
                    continue;
                }
                if (AParameter[param].SlotNumber == lastSlot)
                {
                    continue;
                }
                lastSlot = AParameter[param].SlotNumber;
                CalculateIndicator(lastSlot);
            }

            Backtester.Calculate();
            Backtester.CalculateAccountStats();
            BalanceChart.SetChartData();
            BalanceChart.InitChart();
            BalanceChart.Invalidate();
            _isStartegyChanged = false;
        }
        /// <summary>
        /// Updates the chart and info panel.
        /// </summary>
        private void ShowScanningResult()
        {
            BalanceChart.SetChartData();
            BalanceChart.InitChart();
            BalanceChart.Invalidate();
            InfoPanel.Invalidate();

            ChbAutoscan.Visible = true;
            ChbTickScan.Visible = Configs.UseTickData || _isTickDataFile;
        }
示例#5
0
        /// <summary>
        /// Menu ShowPriceLineOnClick.
        /// </summary>
        protected override void ShowPriceLineOnClick(object sender, EventArgs e)
        {
            var toolStripMenuItem = (ToolStripMenuItem)sender;

            Configs.ShowPriceChartOnAccountChart = toolStripMenuItem.Checked;

            BalanceChart.SetChartData();
            BalanceChart.InitChart();
            BalanceChart.Invalidate();
        }
        // Updates the balance chart.
        private void UpdateBalanceChart()
        {
            if (!_isChartRecalculation)
            {
                return;
            }

            BalanceChart.SetChartData();
            BalanceChart.InitChart();
            BalanceChart.Invalidate();
        }
示例#7
0
        /// <summary>
        /// This event handler deals with the results of the background operation.
        /// </summary>
        private void BgWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Backtester.Calculate();
            Backtester.CalculateAccountStats();
            BalanceChart.SetChartData();
            BalanceChart.InitChart();
            BalanceChart.Invalidate();

            if (!e.Cancelled && Configs.PlaySounds)
            {
                SystemSounds.Exclamation.Play();
            }

            _isOptimizing     = false;
            BtnCancel.Enabled = true;
            BtnAccept.Enabled = true;
            BtnOptimize.Text  = Language.T("Optimize");
            ProgressBar.Value = 1;

            if (PnlParams.Visible)
            {
                for (int i = 0; i <= (int)OptimizerButtons.ResetStrategy; i++)
                {
                    AOptimizerButtons[i].Enabled = true;
                }
            }

            for (int i = 0; i < _parameters; i++)
            {
                AlblParameterValue[i].Text = GetParameterText(i);
            }

            foreach (Control control in PnlParams.Controls)
            {
                control.Enabled = true;
            }

            foreach (Control control in PnlLimitations.Controls)
            {
                control.Enabled = true;
            }

            foreach (Control control in PnlSettings.Controls)
            {
                control.Enabled = true;
            }

            if (ChbOptimizerWritesReport.Checked)
            {
                SaveReport();
            }

            Cursor = Cursors.Default;
        }
示例#8
0
        /// <summary>
        /// Out of Sample
        /// </summary>
        private void ChbOutOfSampleCheckedChanged(object sender, EventArgs e)
        {
            _isOOS  = ChbOutOfSample.Checked;
            _barOOS = Data.Bars - Data.Bars * (int)NUDOutOfSample.Value / 100 - 1;

            BalanceChart.IsOOS  = _isOOS;
            BalanceChart.OOSBar = _barOOS;

            BalanceChart.SetChartData();
            BalanceChart.InitChart();
            BalanceChart.Invalidate();
        }
        /// <summary>
        /// This event handler deals with the results of the background operation
        /// </summary>
        private void BgWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!e.Cancelled && Configs.PlaySounds)
            {
                SystemSounds.Exclamation.Play();
            }

            RestoreFromBest();

            Backtester.Calculate();
            Backtester.CalculateAccountStats();

            BalanceChart.SetChartData();
            BalanceChart.InitChart();
            BalanceChart.Invalidate();

            StrategyField.Enabled = true;
            RebuildStrategyLayout(_strategyBest);

            _isGenerating = false;

            BtnAccept.Enabled = true;
            BtnCancel.Enabled = true;

            foreach (Control control in PnlCommon.Controls)
            {
                control.Enabled = true;
            }
            foreach (Control control in PnlLimitations.Controls)
            {
                control.Enabled = true;
            }
            foreach (Control control in PnlSettings.Controls)
            {
                control.Enabled = true;
            }

            IndicatorsField.UnBlockIndicatorChange();

            TsbtLockAll.Enabled      = true;
            TsbtUnlockAll.Enabled    = true;
            TsbtLinkAll.Enabled      = true;
            TsbtOverview.Enabled     = true;
            TsbtStrategyInfo.Enabled = true;

            BtnGenerate.Text  = Language.T("Generate");
            ProgressBar.Style = ProgressBarStyle.Blocks;

            Cursor = Cursors.Default;
        }
 private void UpdateChart()
 {
     BalanceChart.SetChartData();
     BalanceChart.InitChart();
     BalanceChart.Invalidate();
 }
示例#11
0
        /// <summary>
        /// Optimize all the checked parameters
        /// </summary>
        private void OptimizeParams(BackgroundWorker worker, DoWorkEventArgs e)
        {
            int bestBalance = (_isOOS ? Backtester.Balance(_barOOS) : Backtester.NetBalance);

            // First Optimization Cycle
            for (int round = 0; round < _checkedParams && _isOptimizing; round++)
            {
                if (worker.CancellationPending)
                {
                    break;
                }

                int param = _aiChecked[round];

                var min  = (double)AnudParameterMin[param].Value;
                var max  = (double)AnudParameterMax[param].Value;
                var step = (double)AnudParameterStep[param].Value;

                for (double value = min; value <= max; value += step)
                {
                    if (worker.CancellationPending)
                    {
                        break;
                    }

                    AParameter[param].Value = value;
                    if (AParameter[param].Type == OptimizerParameterType.Indicator)
                    {
                        CalculateIndicator(AParameter[param].SlotNumber);
                    }

                    Backtester.Calculate();
                    Backtester.CalculateAccountStats();
                    if (ChbOptimizerWritesReport.Checked)
                    {
                        FillInReport();
                    }

                    int balance = _isOOS ? Backtester.Balance(_barOOS) : Backtester.NetBalance;
                    if (balance > bestBalance && IsLimitationsFulfilled())
                    {
                        bestBalance = balance;
                        AParameter[param].BestValue = value;
                        ShowParamBestValue(param);
                        BalanceChart.SetChartData();
                        BalanceChart.InitChart();
                        BalanceChart.Invalidate();
                        _isStartegyChanged = true;
                        SetStrategyToGeneratorHistory();
                    }

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

                AParameter[param].Value = AParameter[param].BestValue;
                if (AParameter[param].Type == OptimizerParameterType.Indicator)
                {
                    CalculateIndicator(AParameter[param].SlotNumber);
                }
                Backtester.Calculate();
                Backtester.CalculateAccountStats();
            }

            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            if (_checkedParams < 2)
            {
                return;
            }

            // Counts the necessary round
            int rounds = 0;

            for (int i = 0; i < _checkedParams - 1; i++)
            {
                for (int j = 0; j < _checkedParams; j++)
                {
                    if (i < j)
                    {
                        rounds++;
                    }
                }
            }

            var aCP     = new CoupleOfParams[rounds];
            var aCPTemp = new CoupleOfParams[rounds];

            rounds = 0;
            for (int i = 0; i < _checkedParams - 1; i++)
            {
                for (int j = 0; j < _checkedParams; j++)
                {
                    if (i < j)
                    {
                        aCPTemp[rounds].Param1   = _aiChecked[i];
                        aCPTemp[rounds].Param2   = _aiChecked[j];
                        aCPTemp[rounds].IsPassed = false;
                        rounds++;
                    }
                }
            }

            // Shaking the parameters
            for (int round = 0; round < rounds; round++)
            {
                int couple;
                do
                {
                    couple = _rand.Next(rounds);
                } while (aCPTemp[couple].IsPassed);
                aCPTemp[couple].IsPassed = true;
                aCP[round] = aCPTemp[couple];
            }

            // The Optimization Cycle
            for (int round = 0; round < rounds; round++)
            {
                if (worker.CancellationPending)
                {
                    break;
                }

                int  param1         = aCP[round].Param1;
                int  param2         = aCP[round].Param2;
                bool isOneIndicator = (AParameter[param1].Type == OptimizerParameterType.Indicator &&
                                       AParameter[param2].Type == OptimizerParameterType.Indicator &&
                                       AParameter[param1].IndParam.IndicatorName ==
                                       AParameter[param2].IndParam.IndicatorName);

                var min1  = (double)AnudParameterMin[param1].Value;
                var max1  = (double)AnudParameterMax[param1].Value;
                var step1 = (double)AnudParameterStep[param1].Value;

                var min2  = (double)AnudParameterMin[param2].Value;
                var max2  = (double)AnudParameterMax[param2].Value;
                var step2 = (double)AnudParameterStep[param2].Value;

                for (double value1 = min1; value1 <= max1; value1 += step1)
                {
                    if (worker.CancellationPending)
                    {
                        break;
                    }

                    if (!isOneIndicator)
                    {
                        AParameter[param1].Value = value1;
                        if (AParameter[param1].Type == OptimizerParameterType.Indicator)
                        {
                            CalculateIndicator(AParameter[param1].SlotNumber);
                        }
                    }

                    for (double value2 = min2; value2 <= max2; value2 += step2)
                    {
                        if (worker.CancellationPending)
                        {
                            break;
                        }

                        if (isOneIndicator)
                        {
                            AParameter[param1].Value = value1;
                            AParameter[param2].Value = value2;
                            if (AParameter[param1].Type == OptimizerParameterType.Indicator)
                            {
                                CalculateIndicator(AParameter[param1].SlotNumber);
                            }
                        }
                        else
                        {
                            AParameter[param2].Value = value2;
                            if (AParameter[param2].Type == OptimizerParameterType.Indicator)
                            {
                                CalculateIndicator(AParameter[param2].SlotNumber);
                            }
                        }

                        // Calculates the Strategy
                        Backtester.Calculate();
                        Backtester.CalculateAccountStats();
                        if (ChbOptimizerWritesReport.Checked)
                        {
                            FillInReport();
                        }

                        int balance = _isOOS ? Backtester.Balance(_barOOS) : Backtester.NetBalance;
                        if (balance > bestBalance && IsLimitationsFulfilled())
                        {
                            bestBalance = balance;
                            AParameter[param1].BestValue = value1;
                            AParameter[param2].BestValue = value2;
                            ShowParamBestValue(param1);
                            ShowParamBestValue(param2);
                            BalanceChart.SetChartData();
                            BalanceChart.InitChart();
                            BalanceChart.Invalidate();
                            _isStartegyChanged = true;
                            SetStrategyToGeneratorHistory();
                        }

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

                AParameter[param1].Value = AParameter[param1].BestValue;
                AParameter[param2].Value = AParameter[param2].BestValue;

                if (isOneIndicator)
                {
                    if (AParameter[param1].Type == OptimizerParameterType.Indicator)
                    {
                        CalculateIndicator(AParameter[param1].SlotNumber);
                    }
                }
                else
                {
                    if (AParameter[param1].Type == OptimizerParameterType.Indicator)
                    {
                        CalculateIndicator(AParameter[param1].SlotNumber);
                    }
                    if (AParameter[param2].Type == OptimizerParameterType.Indicator)
                    {
                        CalculateIndicator(AParameter[param2].SlotNumber);
                    }
                }

                Backtester.Calculate();
                Backtester.CalculateAccountStats();
            }

            if (worker.CancellationPending)
            {
                e.Cancel = true;
            }
        }