EGY-AI Logo
EGY-AI
Live GA trading engine
๐ŸงฌBeginner8 min read

Genetic Algorithms

How evolution became a programming technique

The core idea

A genetic algorithm (GA) is a way of solving problems by mimicking how biological evolution works. Instead of writing step-by-step instructions to find the best answer, you let a population of candidate solutions compete, and the best ones survive and reproduce.

Over many generations, the population gets better and better at solving the problem โ€” not because you told it how, but because bad solutions die out and good ones pass their traits to the next generation.

Think of it like breeding dogs for speed. You don't engineer the perfect dog from scratch. You pick the fastest ones, breed them, and repeat โ€” until the population is full of fast dogs.

The four steps of every GA

1
Initialisation

Create a population of random solutions. In EGY-AI, each solution is a set of trading strategy parameters: how long a moving average window to use, what RSI threshold to enter on, how much risk to take per trade.

2
Fitness evaluation

Test each solution against real market data. In EGY-AI, we backtest each strategy on real historical BTC candles and give it a fitness score based on how well it would have performed โ€” accounting for fees and drawdown, not just raw profit.

3
Selection & Crossover

The best-performing strategies are selected as "parents." They produce children by mixing their parameters together (crossover). If two good strategies each have one useful trait, their child might have both.

4
Mutation

Randomly change a small part of some children. This prevents the population from getting stuck on a local optimum โ€” introducing new variations the crossover alone would never discover.

Then the new generation replaces the old one, and the cycle repeats. Over time the population converges toward better and better solutions.

The evolution cycle

Here's what one generation looks like in EGY-AI:

24 strategiesPopulation
โ†’
Backtest eachFitness eval
โ†’
Best 4 surviveSelection
โ†’
Breed + mutateNext gen
โ†’
RepeatEvery 45s

Why use a GA for trading?

A trading strategy has many parameters โ€” moving average lengths, RSI thresholds, stop-loss levels, entry timing. Finding the best combination by hand is practically impossible.

You could try every combination (brute force), but with even 5 parameters and 20 possible values each, that's 3.2 million combinations. A GA finds a very good solution in a fraction of that time by intelligently exploring the search space.

EGY-AI evolves a population of 24 strategy variants every 45 seconds, on real historical BTC/USDT candles fetched live from Binance. The best-performing strategy sends the live trade signals.

Key vocabulary

Population
A group of candidate solutions. EGY-AI uses 24 individuals per generation.
Individual / Genome
One specific set of strategy parameters โ€” one candidate solution.
Fitness
A score measuring how good an individual is. Higher = better performance.
Selection
Picking the best individuals to reproduce. EGY-AI uses tournament selection.
Crossover
Combining two parents to create a child that inherits traits from both.
Mutation
Randomly changing part of an individual to introduce new variation.
Generation
One full cycle of evaluation โ†’ selection โ†’ crossover โ†’ mutation.
Elitism
Keeping the best individuals unchanged so good solutions are never lost.