Forex_Strategy_Builder.Dialogs.Generator.Generator.ReduceTheValuesOfNumericParams C# (CSharp) Method

ReduceTheValuesOfNumericParams() private method

Normalizes the numeric parameters.
private ReduceTheValuesOfNumericParams ( BackgroundWorker worker ) : void
worker System.ComponentModel.BackgroundWorker
return void
        void ReduceTheValuesOfNumericParams(BackgroundWorker worker)
        {
            bool isDoAgain;
            for (int slot = 0; slot < Data.Strategy.Slots; slot++)
            {
                if (bestBalance < 500) break;
                if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Locked) continue;

                // Numeric parameters
                for (int param = 0; param < 6; param++)
                {
                    if (!Data.Strategy.Slot[slot].IndParam.NumParam[param].Enabled) continue;

                    do
                    {
                        if (worker.CancellationPending) break;
                        isDoAgain = false;

                        IndicatorSlot indSlot = Data.Strategy.Slot[slot];
                        NumericParam num = Data.Strategy.Slot[slot].IndParam.NumParam[param];
                        if (num.Caption == "Level" && !indSlot.IndParam.ListParam[0].Text.Contains("Level")) break;

                        Indicator indicator = Indicator_Store.ConstructIndicator(indSlot.IndicatorName, indSlot.SlotType);
                        double defaultValue = indicator.IndParam.NumParam[param].Value;

                        double numOldValue = num.Value;
                        if (num.Value == defaultValue) break;

                        double step  = Math.Pow(10, -num.Point);
                        double value = num.Value;
                        double delta = (defaultValue - value) * 3 / 4;
                        value += delta;
                        value = Math.Round(value, num.Point);

                        if (Math.Abs(value - numOldValue) < value) break;

                        num.Value = value;

                        RecalculateSlots();
                        isDoAgain = CalculateTheResult(true);
                        if (!isDoAgain) RestoreFromBest();

                    } while (isDoAgain);
                }
            }
        }