First, I just now found that this check boxes has a BUG. It works in the opposite way I wanted .

The old text of the check box was "Generate a new strategy at every start" and the new text is "Generate higher profit than the starting". The new text has an opposite meaning according to the older but I haven't mirrored the logic. I'll correct the text or the logic as soon as we establish the desired behavior. The check box code name is chbGenerateNewStrategy.

When user press "Generate" button, Generator sets a variable **bestValue**.

```
if (chbGenerateNewStrategy.Checked)
bestValue = 0;
else if (rbnCustomSortingNone.Checked) // No custom sorting
bestValue = Backtester.NetBalance;
else
bestValue = float.MinValue;
```

Is the code clear?

If chbGenerateNewStrategy is checked on, bestValue is set to zero.

If chbGenerateNewStrategy is checked of and:

- do not use custom sorting: bestValue is set to current NetBalance.

- with custom sorting: bestValue is the lowest possible negative number.

Generator starts:

Generator selects a random count of indicators and random indicator parameters at every calculation cycle. The strategy shape must correspond to the settings of max opening and max closing logic slots and also it takes into account the locked and linked slots.

After that Generator performs backtest calculations.

Simplified code:

```
Backtester.Calculate();
Backtester.CalculateAccountStats();
float value = 0;
if (IsCriteriaFulfilled())
{
if (rbnCustomSortingNone.Checked) // No custom sorting
value = Backtester.NetBalance;
else
value = CustomSortingResult()
if (bestValue < value)
{
bestValue = value;
AddStrategyToGeneratorHistory(description);
RefreshSmallBalanceChart();
RefreshAccountStatistics();
RebuildStrategyLayout(strategyBest);
Top10AddStrategy();
}
}
```

First Generator checks if all criteria from "Criteria" tab are fulfilled.

If not, Generator starts new generation.

After that Generator sets the calculated result in a variable **value**.

If we do not use custom sorting, value = Backtester.NetBalance

If we use Custom Sorting, value = CustomSortingResult()

Later, Generator compares value and bestValue.

If we have greater value (it means greater profit or greater Custom Sorting result), Generator updates all charts and stats and pushes the strategy at the top of Top10.

...

An example with no custom sorting and chbGenerateNewStrategy is checked:

If we have a strategy with NetBalance = 7000.

We press Generate button Generator sets bestValue = 0;

Generator generates and calculates a strategy.

It checks if all criteria are fulfilled.

- if not, it starts new calculation

Lets say that the new strategy has NetBalance = 5500

Generator compares the new NetBalance with bestValue.

And since bestValue = 0, Generator accepts the new strategy.

Generator sets bestValue = 5500.

....

An example with no custom sorting and chbGenerateNewStrategy is **NOT checked**:

If we have a strategy with NetBalance = 7000.

We press Generate button Generator sets bestValue = 7000;

Generator generates and calculates a strategy.

It checks if all criteria are fulfilled.

- if not, it starts new calculation

Lets say that the new strategy has NetBalance = 5500

Generator compares the new NetBalance with bestValue.

And since bestValue = 7000, Generator **does not** accepts the new strategy.

It generates new strategy. Lets say it has NetBalance = 7500.

This time Generator will accept the strategy and will set bestValue = 7500.

..........

So when chbGenerateNewStrategy is checked, Generator accepts the first generated strategy that satisfies all criteria.

When chbGenerateNewStrategy is NOT checked, Generator accepts the generated strategy that satisfies all criteria AND has greater profit than the initial strategy.

...

The question is now with what text to display chbGenerateNewStrategy check box!