コード例 #1
0
        /// <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;
        }
コード例 #2
0
        /// <summary>
        /// BtnGenerate_Click
        /// </summary>
        private void BtnGenerateClick(object sender, EventArgs e)
        {
            if (_isGenerating)
            {
                // Cancel the asynchronous operation
                BgWorker.CancelAsync();
            }
            else
            {
                // Start the bgWorker
                PrepareStrategyForGenerating();
                CheckForLockedSlots();
                PrepareIndicatorLists();
                bool isEnoughIndicators = CheckAvailableIndicators();

                if (_isEntryLocked && _isExitLocked || !isEnoughIndicators)
                {
                    SystemSounds.Hand.Play();
                    return;
                }

                Cursor = Cursors.WaitCursor;

                _minutes          = (int)NUDWorkingMinutes.Value;
                ProgressBar.Style = _minutes > 0 ? ProgressBarStyle.Blocks : ProgressBarStyle.Marquee;

                GeneratedDescription = String.Empty;

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

                IndicatorsField.BlockIndicatorChange();

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

                LblCalcStrInfo.Enabled = true;
                LblCalcStrNumb.Enabled = true;
                ChbHideFSB.Enabled     = true;

                BtnAccept.Enabled = false;
                BtnCancel.Enabled = false;
                BtnGenerate.Text  = Language.T("Stop");

                _isGenerating = true;

                ProgressBar.Value = 1;
                _progressPercent  = 0;
                _cycles           = 0;

                if (ChbGenerateNewStrategy.Checked)
                {
                    Top10Field.ClearTop10Slots();
                }

                BgWorker.RunWorkerAsync();
            }
        }
コード例 #3
0
        /// <summary>
        /// Prepare available indicators for each slot.
        /// </summary>
        private void PrepareIndicatorLists()
        {
            // Clear lists
            _entryIndicators.Clear();
            _entryFilterIndicators.Clear();
            _exitIndicators.Clear();
            _exitIndicatorsWithFilters.Clear();
            _exitFilterIndicators.Clear();

            // Copy all no banned indicators
            foreach (string indicator in IndicatorStore.OpenPointIndicators)
            {
                if (!IndicatorsField.IsIndicatorBanned(SlotTypes.Open, indicator))
                {
                    _entryIndicators.Add(indicator);
                }
            }
            foreach (string indicator in IndicatorStore.OpenFilterIndicators)
            {
                if (!IndicatorsField.IsIndicatorBanned(SlotTypes.OpenFilter, indicator))
                {
                    _entryFilterIndicators.Add(indicator);
                }
            }
            foreach (string indicator in IndicatorStore.ClosePointIndicators)
            {
                if (!IndicatorsField.IsIndicatorBanned(SlotTypes.Close, indicator))
                {
                    _exitIndicators.Add(indicator);
                }
            }
            foreach (string indicator in IndicatorStore.ClosingIndicatorsWithClosingFilters)
            {
                if (!IndicatorsField.IsIndicatorBanned(SlotTypes.Close, indicator))
                {
                    _exitIndicatorsWithFilters.Add(indicator);
                }
            }
            foreach (string indicator in IndicatorStore.CloseFilterIndicators)
            {
                if (!IndicatorsField.IsIndicatorBanned(SlotTypes.CloseFilter, indicator))
                {
                    _exitFilterIndicators.Add(indicator);
                }
            }

            // Remove special cases
            bool isPeriodDayOrWeek = Data.Period == DataPeriods.day || Data.Period == DataPeriods.week;

            if (_entryIndicators.Contains("Fibonacci"))
            {
                _entryIndicators.Remove("Fibonacci");
            }
            if (_entryIndicators.Contains("Day Opening") && isPeriodDayOrWeek)
            {
                _entryIndicators.Remove("Day Opening");
            }
            if (_entryIndicators.Contains("Hourly High Low") && isPeriodDayOrWeek)
            {
                _entryIndicators.Remove("Hourly High Low");
            }
            if (_entryIndicators.Contains("Entry Hour") && isPeriodDayOrWeek)
            {
                _entryIndicators.Remove("Entry Hour");
            }

            if (_entryFilterIndicators.Contains("Random Filter"))
            {
                _entryFilterIndicators.Remove("Random Filter");
            }
            if (_entryFilterIndicators.Contains("Data Bars Filter"))
            {
                _entryFilterIndicators.Remove("Data Bars Filter");
            }
            if (_entryFilterIndicators.Contains("Date Filter"))
            {
                _entryFilterIndicators.Remove("Date Filter");
            }
            if (_entryFilterIndicators.Contains("Long or Short"))
            {
                _entryFilterIndicators.Remove("Long or Short");
            }
            if (_entryFilterIndicators.Contains("Entry Time"))
            {
                _entryFilterIndicators.Remove("Entry Time");
            }
            if (_entryFilterIndicators.Contains("Lot Limiter"))
            {
                _entryFilterIndicators.Remove("Lot Limiter");
            }
            if (_entryFilterIndicators.Contains("Hourly High Low") && isPeriodDayOrWeek)
            {
                _entryFilterIndicators.Remove("Hourly High Low");
            }

            if (_exitIndicators.Contains("Day Closing") && isPeriodDayOrWeek)
            {
                _exitIndicators.Remove("Day Closing");
            }
            if (_exitIndicators.Contains("Hourly High Low") && isPeriodDayOrWeek)
            {
                _exitIndicators.Remove("Hourly High Low");
            }
            if (_exitIndicators.Contains("Exit Hour") && isPeriodDayOrWeek)
            {
                _exitIndicators.Remove("Exit Hour");
            }
            if (_exitIndicators.Contains("Close and Reverse") &&
                _strategyBest.OppSignalAction != OppositeDirSignalAction.Reverse &&
                _strategyBest.PropertiesStatus == StrategySlotStatus.Locked)
            {
                _exitIndicators.Remove("Close and Reverse");
            }

            if (_exitIndicatorsWithFilters.Contains("Day Closing") && isPeriodDayOrWeek)
            {
                _exitIndicatorsWithFilters.Remove("Day Closing");
            }
            if (_exitIndicatorsWithFilters.Contains("Close and Reverse") &&
                _strategyBest.OppSignalAction != OppositeDirSignalAction.Reverse &&
                _strategyBest.PropertiesStatus == StrategySlotStatus.Locked)
            {
                _exitIndicatorsWithFilters.Remove("Close and Reverse");
            }

            if (_exitFilterIndicators.Contains("Random Filter"))
            {
                _exitFilterIndicators.Remove("Random Filter");
            }
            if (_exitFilterIndicators.Contains("Hourly High Low") && isPeriodDayOrWeek)
            {
                _exitFilterIndicators.Remove("Hourly High Low");
            }
        }