
I Let an Algorithm Evolve Trading Strategies for 127 Generations — Here's What Happened
Generation 0 was garbage. Thirty randomly generated trading strategies, each a different combination of RSI thresholds, MACD weights, stop-loss percentages, and holding periods. Most of them lost money. A few managed to break even by pure luck. The best one had a fitness score of 12. I hit enter and went to make coffee. What I Was Running The setup: a genetic algorithm that breeds trading strategies. Each strategy is a "DNA" — a vector of ~40 numerical parameters that control how stocks are scored, when to buy, when to sell, how much risk to take. The algorithm mutates these numbers, backtests the mutations against 500 stocks of Chinese A-share market data, keeps the top performers, and repeats. Every parameter is readable. Here's what the scoring weights look like — each one controls how much a particular signal matters: # From actual StrategyDNA — 40+ built-in weights w_momentum = 0.0842 # RSI + slope w_mean_reversion = 0.1205 # RSI oversold signals w_bollinger = 0.0974 # Bollinger B
Continue reading on Dev.to Python
Opens in a new tab

