Marco Nicola Messina

Leggi in italiano →

Trading & prop firms

How I built a trading bot with Claude on cTrader

#trading . #trading-bot . #claude

A trading chart on a platform, the kind of live market a bot connects to through an API.
The live market a bot plugs into. The chart is the easy part.

In the prop firm piece I said the real way out of the casino is to stop renting someone else’s rigged game and build your own bot on your own account. Fair enough, but “just build a bot” is the kind of line that sounds easy and isn’t. So here is how I actually did it. Not the strategy, that stays mine, and not a fake equity curve. Just the process, and the part nobody warns you about.

Why cTrader and its API, not MetaTrader

Most retail bots are MetaTrader EAs. I don’t build them that way. MetaTrader is clunky and slow for anything past a simple rule, and it ties you to a terminal running on a desktop.

I build on cTrader through its Open API instead. The strategy runs as real code on a small server, connects straight to the broker, and executes on its own: no terminal, no EA, no machine I have to leave switched on in a corner. It is the difference between a macro glued onto a chart and an actual program.

Where Claude changed everything

The old bottleneck was translation: you have a strategy in your head, and turning it into correct, tested code took months, or a developer you had to trust and pay.

With Claude that collapses into a handful of sessions. You describe the logic, it writes the code, you check it, you tighten it, you go again. I am not a developer, and I built a live-trading system on a proper API. The barrier that kept trading automation locked to quants and programmers is basically gone: if you can explain your rules clearly, you can get them into code.

The backtest is the whole point

Here is the discipline that matters more than the code. Before a single euro is live, the strategy gets backtested over five to ten years of real data.

That backtest is the only honest thing in trading. It tells you the truth a live “feeling” never will: this logic is strong on these instruments and worthless on those. So the bot only ever trades the handful the data actually proved out, and ignores the rest. If it does not survive the backtest, it does not go live. That is the entire filter.

Hardening: proving the strategy is real, not a mirage

A single backtest is not enough, because most trading ideas are mirages. They look brilliant on the exact history you tuned them on and fall apart the moment the market shifts an inch. So before anything touches real money it has to survive a battery of tests designed to break it. If it breaks, good: better my own laptop kills it than the market does. This is the part that turns a lucky-looking chart into something you can actually trust.

The core tests I put every strategy through:

  • Out-of-sample and walk-forward. You never trust a backtest on the same data you built the strategy on. You tune on one slice of history, then test on years the strategy has never seen, rolling the window forward. Most ideas die right here. I have killed whole families of entry filters that looked perfect in-sample and collapsed on walk-forward: they were mirages, not edges. This is the single most important defence against fooling yourself.
  • Monte Carlo. Take the trades and reshuffle them thousands of times, randomise the order, resample, and look at the whole distribution of outcomes instead of the one lucky path that happened. It shows you the realistic range of drawdowns and equity curves, not just the pretty one. A strategy that only survives one specific sequence of trades is not a strategy.
  • A hard pass/fail gate. Every candidate has to clear a checklist before it goes near real capital, the same kind of thresholds a strict prop firm would use, turned against my own strategy on purpose: max drawdown under a set ceiling, profit factor above about 1.4, Calmar above 2 (annual return against the worst drawdown), a capped losing streak, a minimum win rate. Fail a single line and it is dead, no matter how good the headline return looks. I have had candidates fail four of seven thresholds and go straight to the graveyard.

Then the part that answers the broker question directly.

Hardening against the broker’s shenanigans

A strategy that is profitable in a clean backtest can still be robbed at execution. The broker is not neutral: spreads widen at exactly the wrong moment, slippage eats your fills, and a data feed can aggregate ticks slightly differently from the tape you tested on. If your edge only exists on paper-perfect fills, it does not exist. So the backtest has to be run dirty, on purpose:

  • Realistic and widened spreads. I test with spreads wider than the broker advertises, because the live spread is what actually hits you. I once had a strategy whose tight stops were fine in the backtest and got eaten alive by the real spread on a live CFD feed. The fix was to widen the stops so a normal spread spike cannot knock me out. If the edge survives a fat spread, it is real.
  • Slippage and commission baked in. Every fill costs more than the mid price. Model it, or you are trading a fantasy that quietly bleeds in the real world.
  • Feed versus execution mismatch. The data you backtest on and the broker you execute on are not the same tape. A strategy can pass walk-forward on a clean institutional feed and still fail on a retail broker’s aggregated ticks. You measure the offset between the two and account for it, or you discover it live with real money.

The whole approach is adversarial: assume the market is random and the broker is quietly against you, and keep only what still makes money under those assumptions. What survives is not a guess. It is the closest thing to proof this game allows, and it is exactly what the prop firms do not want you to have, because a proven, automated edge on your own account is the one thing their model cannot tax.

Going live is the easy 20%

Once it is proven, it goes on a live account, my own capital, on a small server, connected to the broker, and it runs. No 1% rule someone else invented, no forced asset rotation, no risk department. And no emotion: the bot does not get scared after a losing streak and does not get greedy after a good week. It just executes what the data already proved.

Building the bot, though, is maybe 20% of the job.

The 80% nobody tells you about: keeping it alive

A live bot is not “set it and forget it.” It is a piece of software talking to a broker’s servers over the internet, and both of those things break.

I learned this the hard way. One weekend my broker ran maintenance, my bot tried to reconnect, the authentication failed in a way it did not recover from, and it sat dead for three days. The signals kept generating, but not a single order actually went to market. From the outside everything looked fine. That is the nightmare: silent failure.

So now most of the engineering is not the strategy, it is the survival kit around it:

  • A watchdog that every couple of minutes does not just ping the process but does a real check: it asks the broker for the live account balance. A fake “still running” is worse than a clean crash.
  • Automatic restart with sensible limits, and a Telegram alert the moment it goes dark and again when it recovers, so I always know.
  • And the part I love: a Claude agent that, if a restart does not fix it, can read the logs, patch the code itself, bring it back, and message me what it did. An AI that repairs the trading bot another AI helped me write.

Building the thing that makes money is the fun 20%. The 80% is making sure it is still running at 3am on a Sunday when a broker on the other side of the world reboots a server.

What I am not going to show you

I am not going to post a screenshot of a P&L and tell you to trust it. Half of trading Instagram is fake numbers, and the prop-firm piece was about exactly that dishonesty. The point of the bot was never a magic return. It is that the game is finally mine: no rigged rules, no emotion, no company on the other side that needs me to lose.

If you have got a real edge and you are tired of renting it to a prop firm, this is the path. Prove it on ten years of data, put it in code with Claude, run it on your own account, and then spend most of your time making sure it never quietly dies. If you want the why behind all this, it is in the prop firm piece, and how I run everything else this way is in AI for solopreneurs.

More from the diary