DEV Community

HRK MYO
HRK MYO

Posted on • Originally published at note.com

How I Built an Automated Stock Trading System with Claude Code (82% Win Rate, +10% in 2 Days)

How I Built an Automated Stock Trading System with Claude Code (82% Win Rate, +10% in 2 Days)

I'm not a professional programmer. I've never learned Python or JavaScript formally. But in 2 days, I built a fully automated stock trading system using Claude Code — and it achieved an 82% win rate with +10% return in its first live run.

This is the story of how I did it.

What I Built

A fully automated trading system that:

  • Screens all 4,370 stocks listed on the Tokyo Stock Exchange
  • Places orders automatically when conditions are met
  • Cuts losses and takes profits without any manual intervention
  • Runs 24/7 without me touching it

The first 2 days of live trading:

  • Confirmed profit: +¥12,700 (+10.0%)
  • Win rate: 82%

Why Claude Code?

I've tried coding with ChatGPT before. It's good at explaining concepts, but when you need to build a real, working system with multiple files, error handling, and API integrations — it falls apart.

Claude Code is different. You work with it like a senior engineer on your team:

  • It reads your existing files before making changes
  • It runs commands and checks the results
  • It catches its own mistakes and fixes them
  • It asks for clarification when something is ambiguous

I gave it a clear goal: "Build me an automated stock trading system for the Tokyo Stock Exchange." What came out was production-quality code.

The Architecture

The system has 4 main components:

1. Screener (screener.py)

Pulls real-time data for all TSE-listed stocks and applies filters:

  • Price momentum (short-term trend)
  • Volume spike detection
  • Moving average crossover signals

Runs every morning before market open.

2. Order Manager (order_manager.py)

When the screener flags a stock:

  • Calculates position size based on available capital
  • Places market or limit orders via the brokerage API
  • Logs every action with timestamps

3. Risk Manager (risk_manager.py)

Monitors all open positions in real time:

  • Stop loss: Automatically exits if price drops X%
  • Take profit: Locks in gains when target is hit
  • Max drawdown: Pauses all new orders if daily loss exceeds threshold

4. Dashboard (dashboard.py)

A simple terminal UI showing:

  • Current positions and P&L
  • Today's completed trades
  • System health status

The Prompt That Started It All

Here's roughly what I typed to Claude Code:

I want to build a stock trading bot for the Tokyo Stock Exchange.
Requirements:
- Screen all TSE stocks daily for momentum signals
- Auto-place orders through [brokerage] API
- Stop loss at -3%, take profit at +5%
- Log everything
- I want to be able to run it with a single command

Start by reading the brokerage API documentation I've attached, then plan the architecture before writing any code.
Enter fullscreen mode Exit fullscreen mode

That's it. Claude Code read the docs, planned the architecture, asked me 3 clarifying questions, then started building.

The Key Insight: Treat It Like a Junior Engineer

The biggest mistake people make with AI coding tools is treating them like search engines — asking one-off questions and then stitching the answers together yourself.

Instead, I gave Claude Code ownership of the project:

  1. Context first: I shared the API docs, my goals, and constraints upfront
  2. Let it plan: I reviewed and approved the architecture before any code was written
  3. Iterative testing: After each component, we tested it together and fixed issues
  4. Real feedback: When something didn't work, I pasted the error and said "fix this"

The result was a coherent system, not a pile of disconnected scripts.

Results After 2 Days

Metric Value
Total trades 17
Winning trades 14
Win rate 82.4%
Total return +10.0%
Max drawdown -1.2%
Avg hold time 4.3 hours

Not financial advice. Past performance doesn't guarantee future results. But as a proof of concept for what AI-assisted development can achieve — I'm pretty happy with it.

What I Learned

1. You don't need to be a programmer
The hardest part wasn't the code — it was understanding what I wanted to build well enough to explain it clearly.

2. The bottleneck is your thinking, not your typing
Claude Code can write the code. What it can't do is decide what to build. That's still on you.

3. Iteration beats perfection
The first version was rough. We went through 8 iterations over 2 days, fixing edge cases and adding features. That's normal.

4. Test in production (carefully)
I started with the minimum position size my broker allowed. Real market conditions reveal bugs that backtesting misses.

Full Walkthrough

I documented the complete process — every prompt I used, the full architecture, all the code, and the live trading logs — in a paid article on note.com.

👉 Full article (Japanese) — ¥1,980

It includes:

  • The complete prompt sequence I used with Claude Code
  • Full source code for all 4 components
  • Backtest results vs live results comparison
  • The 3 bugs that almost cost me money and how we fixed them

Built with Claude Code. No prior programming experience required.

claudecode #algorithmictrading #python #automation #AI

Top comments (0)