/// <summary>
        /// Calculates the generated result
        /// </summary>
        private bool CalculateTheResult(bool isSaveEqualResult)
        {
            bool isBetter = false;

            _cycles++;

            Data.FirstBar = Data.Strategy.SetFirstBar();
            Data.Strategy.AdjustUsePreviousBarValue();

            // Sets default logical group for all slots that are open (not locked or linked).
            foreach (IndicatorSlot slot in Data.Strategy.Slot)
            {
                if (slot.SlotStatus == StrategySlotStatus.Open)
                {
                    slot.LogicalGroup = Data.Strategy.GetDefaultGroup(slot.SlotNumber);
                }
            }

#if !DEBUG
            try
            {
#endif
            Backtester.Calculate();

            int balance          = (_isOOS ? Backtester.Balance(_barOOS) : Backtester.NetBalance);
            bool isLimitationsOK = IsLimitationsFulfilled();

            if (isLimitationsOK)
            {
                if (_bestBalance < balance ||
                    (_bestBalance == balance && (isSaveEqualResult || Data.Strategy.Slots < _strategyBest.Slots)))
                {
                    _strategyBest = Data.Strategy.Clone();
                    _strategyBest.PropertiesStatus = Data.Strategy.PropertiesStatus;
                    for (int slot = 0; slot < Data.Strategy.Slots; slot++)
                    {
                        _strategyBest.Slot[slot].SlotStatus = Data.Strategy.Slot[slot].SlotStatus;
                    }

                    string description = GenerateDescription();
                    if (balance > _bestBalance)
                    {
                        AddStrategyToGeneratorHistory(description);
                    }
                    else
                    {
                        UpdateStrategyInGeneratorHistory(description);
                    }
                    SetStrategyDescriptionButton();

                    _bestBalance       = balance;
                    isBetter           = true;
                    _isStartegyChanged = true;

                    RefreshSmallBalanceChart();
                    RefreshAccountStatisticas();
                    RebuildStrategyLayout(_strategyBest);
                    Top10AddStrategy();
                }
                else if (Top10Field.IsNominated(balance))
                {
                    Top10AddStrategy();
                }
            }

            SetLabelCyclesText(_cycles.ToString(CultureInfo.InvariantCulture));
#if !DEBUG
        }

        catch (Exception exception)
        {
            string       text    = GenerateCalculationErrorMessage(exception.Message);
            const string caption = "Strategy Calculation Error";
            ReportIndicatorError(text, caption);

            isBetter = false;
        }
#endif

            return(isBetter);
        }
        /// <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();
            }
        }