I gave an AI coding agent one job: build me a trading bot.
Not a toy script. A Python project that reads the market every day, runs statistics on price history, decides what to buy, how much and when to get out, and then does it on its own, with real money, while I sleep.
One month later, the account was down 2.2%. A boring global stock ETF, bought and never touched, was up 0.3% over the same month.
That's not the interesting part, though. The interesting part is the rule I set before a single line of code was written: no LLM was allowed to make a trading decision. The AI built the machine. It never got a vote on the trades.
This post covers why I made that rule, what the AI actually built, how the month went, and the test that made me stop: a version of the bot that made 26% on historical data and still lost.
This is not investment advice. It was a personal experiment in a closed lab, with a small amount of my own money I was prepared to lose. Nothing here is a recommendation to buy, sell or automate anything. Financial markets are aggressive, and the people on the other side of your trade usually have more data, more money and more experience than a side project.
The rule: no LLM in the decisions
When people hear "AI trading bot", they picture a chatbot reading the news and saying "buy". I deliberately built the opposite.
The AI (Claude Code wrote nearly all the code, and Codex reviewed it as a second opinion) was the engineer. The decisions came from fixed rules written in plain Python, applied the same way every time.
Why not let a language model decide?
- I couldn't test it honestly. To know if a strategy works, you replay years of history and see what it would have done. A model may have read about those years during training, so it can "know" what happened next. A rule can't.
- It doesn't answer the same way twice. Ask the same question on two days and you can get two different trades. I wanted a decision I could reproduce and explain.
- It sounds confident when it's guessing. In a market, a confident guess with real money is the most expensive kind of mistake.
So the AI wrote the code, and the code made the calls. If the bot was wrong, I wanted to be able to point at the exact rule that was wrong.
What the AI built: statistics and a decision table
The project is a Python application built on the usual data stack: pandas and numpy for the math, yfinance and ccxt for market data, a scheduler that wakes it up after each market close, and a Telegram bot that tells me everything it does.
Every day it runs the same pipeline:
market data -> is the market trending? (price vs. its 200-day average)
-> which stocks are strongest? (momentum over 3, 6 and 12 months)
-> is there a setup today? (4 statistical patterns)
-> score from 0 to 100 (trend, strength, volume, risk/reward)
-> position size by risk (each trade risks 1% of the account)
-> send the order, place the stop, message me
The heart of it is a decision table. The market regime decides which strategies are allowed and how much risk to take:
| Market regime | Strategies allowed | Risk |
|---|---|---|
| Uptrend (above the 200-day average, 50-day rising) | all four | 100% |
| Undecided | pullback and mean reversion only | 50% |
| Downtrend | none (the bot only buys) | 0% |
And each strategy is a simple statistical pattern with its own way in and out:
| Strategy | When it buys | How it gets out |
|---|---|---|
| Trend pullback | price dips to its 20-day average in an uptrend | partial profit, then a trailing exit |
| Breakout | first close above the 20-day high, with strong volume | a profit target or a trailing stop |
| Mean reversion | a short-term oversold reading (RSI) above the 200-day average | back above the 5-day average, or after 10 days |
| Moving average cross | the 20-day average crosses above the 50-day | a profit target or the cross back down |
None of these are secret. They are classic, well-known setups, and that's the point: I wanted to know whether old ideas, executed with perfect discipline by a machine, could earn anything.
The bot ran by itself on a small server, 24 hours a day. It was designed to check every market close, follow the rules the same way each time and place a protective stop on every trade, without my emotions in the loop. That discipline is the one thing a machine does better than me: it doesn't hesitate, chase a loss or move a stop because of a feeling.
One month with real money
Then I let it trade. Real money, no manual overrides, for one month.
| What | Result |
|---|---|
| My account | -2.2% |
| A global ETF, bought and left alone | +0.3% |
| Closed trades | 17 |
| Trades that won | 41% |
A 2.2% loss is not a disaster in money terms, because each trade only risked 1% of the account. But the shape of the result told the real story: the wins were small and the losses were full. Every winning trade closed early with a little profit; most losing trades took the whole planned loss.
And one detail hurt more than the number: six of the 17 trades were stopped out and then recovered above the entry price within ten days. The bot sold inside normal price noise, exactly the kind of mistake I built it to avoid.
Seventeen trades is too few to judge any strategy. But it was enough to make me ask the harder question.
The test that made me stop
Instead of tweaking settings until the chart looked nice (the easiest way to fool yourself in trading), I did the opposite. With the AI's help, I wrote down the rules of the test before looking at any result:
- Eight versions of the bot, listed in advance.
- Pick the best one on one stretch of history.
- Check it on a different stretch it wasn't chosen on.
- One rule to pass: beat a global ETF that you simply buy and hold, without falling more than 10% along the way.
Here's what came back:
| Version | Bot | Global ETF |
|---|---|---|
| The original rules | -4.3% | +21.9% |
| The best version, on the stretch it was chosen on | +22.0% | +21.9% |
| The best version, on a different stretch | +26.0% | +40.3% |
The best version made 26%. It was profitable, it never fell more than 10%, and it stayed profitable even when I doubled the trading costs. By most hobby standards, that's a win.
I rejected it anyway. It made about 14 percentage points less than doing nothing with an index fund, with far more work and more risk. A strategy that loses to "buy and forget" isn't an edge. It's a hobby.
One more honest caveat: those historical tests use today's list of stocks, which quietly leaves out companies that collapsed or disappeared. That's survivorship bias, and it can make historical results look better than they really were.
Better AI, better code. Not better odds.
So, can a better AI fix it? Partly, maybe. The strategy can clearly improve: rank each strategy on its own, give trades more room instead of tight stops, let winners run instead of cashing them early, test on a list of stocks that includes the losers.
Using the best AI models available, one to build and one to review, gave me far better software than I would have built alone in a month. I'd do it again.
But the AI improved the engineering. It didn't improve the odds. The market doesn't care which model wrote your code. You're competing with funds that have better data, faster execution and full teams of quants, and with your own temptation to change the rules after a bad week.
The responsible conclusion is not "AI can't trade". It's narrower: AI made it cheap to build and test a trading idea, and the test said the idea wasn't good enough. That's still a useful answer, and it cost me 2.2% instead of years.
AI made the system fast to build. Python made the decisions consistent. Automation took my emotions out of the execution.
But none of that created an edge. Automating a strategy doesn't make it a good strategy.
FAQ
Did the AI pick the trades?
No. That was the whole design. The AI wrote the code; fixed statistical rules picked the trades.
Why not let ChatGPT or Claude decide?
Because I couldn't test it fairly on history, it doesn't decide the same way twice, and it may already know what happened in the past it's being tested on.
Is 2.2% in a month a lot?
In money, not here, because each trade risked 1%. As a signal, yes: small wins and full losses is a losing shape, even with only 17 trades.
Is the bot still trading?
It stopped opening new trades. It only looks after what was already open.
Can I get the code?
Not for now. It's tied to my own accounts, and I don't want anyone running it with real money because of one blog post.
Takeaway
- AI can build a real, automated trading system fast. Statistics, a decision table, orders and alerts, running on its own.
- Keep the LLM out of the decisions if you want to test them honestly. Rules can be replayed on history; opinions can't.
- One month of real money: -2.2%, while a global ETF did +0.3%. Small wins, full losses.
- The best version made +26% in tests and still lost to the ETF's +40%. Beating zero isn't the bar; beating "buy and forget" is.
- Better AI gave me better code, not better odds. And none of this is investment advice: markets are aggressive.
Would you let an AI near your money: as the builder, as the decision maker, or not at all? Tell me in the comments.
I'm Diogo Soares, a Staff AI Engineer working on AI agents and legacy modernization. If this was useful, follow me here on DEV.to and on Instagram at @diogosoares.dev, where this experiment becomes a 5-slide carousel you can save. This article also has a video walkthrough on my YouTube channel, Diogo Soares Dev, so subscribe there for the next experiments. Let's also connect on LinkedIn, or check out diogosoares.dev.
Top comments (0)