Home › Documentation › Building strategies
Block 6 · bis

Generation modes

The Mode selector (top panel of the Mass Test) decides how the combination space is searched. When the space is small it is worth trying all of it; when it is astronomical (millions or trillions of combos) you sample at random.

Do not confuse the Random (Monte Carlo) generation mode with the Monte Carlo Simulation in the Performance Report: here Monte Carlo means building combinations at random; there it means reshuffling the trades of a strategy you have already chosen.

EXHAUSTIVE

It tries EVERY possible combination, with no cap and no sampling. Lazy enumeration in blocks: memory use stays constant however huge the space is.

Tested 2,280,294 of 2,280,294
// 100% — the COMPLETE space
Ideal when the number of possible combos is manageable (it fits in reasonable time).
RANDOM · MONTE CARLO

It builds each combo at random: direction, number of conditions (k), the conditions themselves, TP and SL. It gives a fair shot to simple strategies (1-2 conditions), which tend to be the most robust.

k := 1 + random(MaxAnd)
distinct conditions drawn at random from the pool
// + random TP/SL from the range
Recommended for giant spaces. It is the "random search" of the commercial generators.
RANDOM · UNIFORM

It picks a global index at random and "un-ranks" it into the exact combo (a combinatorial number system). Mathematically uniform: every combo in the whole space is equally likely.

r := random(0 .. Total)
un-ranking → the exact combo
// tends towards combos with many conditions
For when you want a statistically uniform sample of the complete space.
GENETIC

It does not search blindly: it evolves. It breeds strategies like a breeder — keeps the best, crosses and mutates them, and repeats generation after generation. Each round starts from the best of the last one, so it accumulates progress instead of starting from scratch.

// every generation:
evaluate → select → cross + mutate
// the champions survive (elitism)
The most efficient for enormous spaces: it explores widely and then refines towards what works.

The Genetic mode in depth

The random modes search blindly: each sample is independent and learns nothing from the past. The genetic one is different — it accumulates progress. It borrows the idea of natural selection: it keeps a population of strategies, holds on to the best ones, combines them with each other (crossover) and introduces small changes (mutation), then repeats. Generation by generation, the whole population drifts towards better and better strategies.

Its philosophy: explore widely (like the random mode) and then exploit and refine towards the good regions. For spaces of millions or trillions of combinations it is far more efficient than random sampling, because each round aims better thanks to what the last one learned.

The evolutionary cycle (one generation)
1 · Evaluate
Backtest each individual → its fitness
2 · Select
The best get more offspring (tournament)
3 · Cross
Mix two parents → one child
4 · Mutate
Small random changes
5 · Repeat
New generation → back to 1

Generation 0 is a random population. Each individual is a strategy = {direction, entry conditions, exit conditions, TP, SL} — its "DNA". Crossing and mutating manipulate that DNA, always producing valid strategies.

The parameters, one by one
Population

How many strategies live in each generation (individuals backtested per round). More population = more diversity and better exploration, but each generation costs more. Typically 200–1000.

Generations

The maximum number of evolution rounds. More generations give more time to refine, but there comes a point where it stops improving (it converges). Typically 30–100.

Tournament

To choose each parent, N individuals are drawn at random and the one with the best fitness wins. A large N = more selection pressure (the good ones take over fast, at the risk of losing diversity); a small N = more randomness. Typically 2–5.

Elite %

What fraction of the best strategies pass through unchanged into the next generation, without crossing or mutating. It guarantees the best find is never lost — which is why the curve never goes down. Typically 5–10%.

Mut %

The chance that a child undergoes a mutation (changing a condition, adjusting the TP/SL, flipping the direction…). Little mutation converges fast but can stall; a lot explores more but is more chaotic. Typically 10–20%.

Immig %

Fresh blood: every generation injects this fraction of completely random individuals. It fights "diversity collapse" (the whole population turning into clones and giving up on exploring). Typically 3–5%.

Stop (convergence)

If the best fitness does not improve for N generations in a row, the engine stops on its own: it has converged and carrying on would waste compute. Set it to 0 to always exhaust every generation. Typically 10–15.

Seeding

Instead of starting with a random Generation 0, it holds an audition: it evaluates N random candidates and starts with the best ones. That way the genetic mode begins with a decent squad and converges sooner and better. Typically 20,000; 0 = the classic random Gen 0. You can also seed from your Libraries (the «🧬 Seed the genetic» button).

Robustness anti-overfitting

It changes what the genetic mode is looking for: from "makes the most in the backtest" to "makes money and holds up". (1) Optimizes on the first 70% (holdout: the final 30% is kept as unseen validation). (2) Penalizes complexity (fewer conditions). (3) Rewards the sample (more trades = more believable). The ranking shows the In-Sample; take the winner to Walk-Forward / 360 Analysis to see the Out-of-Sample.

Fitness — how "good" gets measured

Each individual is scored with the same ranking criterion you pick at the foot of the window (Net P. $, Profit Factor, Net P. %, Win %). One important guardrail: strategies with fewer trades than "Min. Trades" get the lowest score and are never selected → the genetic mode does not converge on "flukes" built from 3 lucky trades.

The convergence curve

While it runs, a chart appears next to the results table: the X axis is the generation and the Y axis the best fitness of that generation. The orange dots draw how the population improves round by round, live.

Thanks to elitism, the curve is a rising staircase (it goes up or stays flat, never down). The typical shape: big jumps at the start (the easy gains) and flattening at the end (convergence). If it flattens early, the search has already found its optimum in that space.

Reproducible

The Seed controls all the randomness (initial population, crossings, mutations). Same seed + same config ⇒ same evolution. With Seed 0 a new one is generated and shown next to the field.

Same destination

The champions land in the same results table (top N) as every other mode, with identical hand-offs: Performance, Portfolio, Walk-Forward, 360 Analysis…

On the CPU

It runs on the CPU (multithreaded): it needs each generation's results in order to select. GPU acceleration is not available for this mode.

⏱️
How do I make the test longer (or more exhaustive)?

The genetic mode finishing quickly is not a flaw: it means it converges quickly towards what works. But if you want it to explore more deeply, you have four levers, from most to least impact:

1
Stop = 0. This is the main reason it ends early: by default (12) it cuts out as soon as the best fails to improve for 12 generations in a row. Set it to 0 and it will exhaust EVERY generation without stopping on convergence.
2
Raise Generations and Population. The total work is roughly Population × Generations backtests. From 300×40 (12,000) to, say, 1500 × 200 = 300,000 strategies evaluated.
3
Raise Mut% and Immig% (diversity). This is what makes the extra time count: if you only raise the generations and the population has already converged, the extra rounds just polish the same champion. With more mutation (25-35%) and immigrants (10-15%), the population keeps exploring new ground instead of stagnating into clones.
4
Widen the space. If it converges instantly, there is little to explore: tick more indicators or wider period ranges → a longer, richer search.
// Recipe for a long, exhaustive run:
Population 1500 · Generations 200 · Tournament 3 · Elite% 8 · Mut% 30 · Immig% 12 · Stop 0

In short: being fast and effective is a good sign — the genetic mode is efficient. Stretching it out makes sense when you are after a wider variety of edges or squeezing large search spaces.

Samples

In the random modes, the Samples field sets how many combos get tried (e.g. 1,000,000) and the sweep stops when it reaches them. In Exhaustive mode it is ignored and the field is disabled.

Seed

Leave the Seed at 0 and every run generates a fresh seed automatically → each pass explores a different random subset of the space. The seed actually used is shown next to the field (→ used: N); type it into the box to reproduce that same sweep.

If you type a fixed value, the random modes become reproducible: same seed + same configuration ⇒ same samples. In Exhaustive mode it is not used (the field is disabled): the enumeration is deterministic.

Constant memory (streaming top N)

Whatever the mode, AniQuant does not pile every result into RAM: it keeps only the top N by the ranking criterion (the MaxRes field), discarding the rest on the fly. That way memory use stays flat even if the sweep runs for hours or days.

// For every valid combo:
if ranking_value > worst_of_topN then replace; else discard;

GPU acceleration (OpenCL)

OPTIONAL

Tick the GPU box to run the sweep on the graphics card through OpenCL: one GPU thread per combination. On large spaces it is typically 10-15× faster than the CPU. If there is no compatible OpenCL GPU, AniQuant says so in the log and falls back to the CPU automatically.

Resident series

The bars and every indicator series are computed and uploaded to the GPU once; each batch only sends the combinations to evaluate.

Asynchronous pipeline

While the GPU computes one block, the CPU is already enumerating and preparing the next (double buffering). That way the card never waits: utilization goes from around 50% up to nearly 100%.

Block size

Adjustable in Settings → Block size (combos per pass). The optimum depends on the machine; in testing around 25,000 worked best. Tiny or giant batches both do worse.

Diagnostics in the log

On startup it states the engine actually used (GPU + device name, or CPU + thread count) and the reason if the GPU was unavailable.

Same results

CPU and GPU produce the same metrics: the GPU only changes the speed, not the backtest logic.

Live progress

A progress bar at the foot of the window shows how it is going: during preparation (loading data and uploading series to the GPU) it animates in marquee mode, and switches to a real percentage once the sweep starts. The status bar refreshes every block (around 50,000 combos) and the results list updates live:

  • →combos done / total and %
  • → number of valid results found
  • →rate (combos/s) and estimated ETA

If the ETA goes past 10 years, the system warns you to "narrow the parameter ranges": the space is too big, even though it no longer exhausts memory.

💡
When to use each mode

Exhaustive: when the possible combos are few — it guarantees 100% of the space.
Random (Monte Carlo): the general-purpose option for large spaces; it favors simple, robust strategies.
Random (Uniform): when you want a statistically representative sample of the complete space.
Genetic: when the space is enormous and you want the search to learn and refine towards the best, instead of sampling blind. The most powerful for discovering strategies.

Try it yourself

AniQuant can be tried free for 30 days, with every module and no card.

← Previous
How strategy optimization works
Next →
Chart with visual indicators
More in Building strategies