Zerodha Bot
- author ........
- Aryan Ramani
- domain ........
- Fintech
- role ..........
- Product owner, designer and builder. Claude Code was the engineering pair.
- team ..........
- Solo
- timeframe .....
- Since September 2026, ongoing
- published .....
- 2026-11-29
- updated .......
- 2026-11-29
- markdown ......
- /work/zerodha-bot.md
- human .........
- /work/zerodha-bot
It started by obeying one script. Now it reads the market, picks its stocks, questions Claude and grades itself every night.
── SUMMARY ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
- Problem: A system that can move real money has to be safe for an owner who is not an engineer.
- My role: Product, design and build, end to end. Claude Code was the engineering pair.
- Outcome: A bot that grew from obeying one script to planning its day, picking its stocks, consulting a scored Claude analyst and re-tuning itself, with every automatic change undoable. Paper and backtest only so far.
── CONTEXT ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
- product .......
- A trading engine for Indian markets, with a phone-first controller
- for ...........
- One owner: me, a designer with no engineering background
- role ..........
- Product owner, designer, builder
- team ..........
- Solo, with Claude Code as the engineering pair
- timeframe .....
- Since September 2026, ongoing
- status ........
- Backtest and paper. Live is locked
── PROBLEM ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
* The problem
Anyone can write a trading rule. The hard part is everything around it: what happens when the order half-sends, when the feed goes quiet, when the strategy is simply not good, when a tired owner taps the wrong thing on a phone.
I wanted one engine that runs the same strategy, risk, cost and ledger code in backtest, paper and live, and a controller I could run from my phone. I am a designer. I had never run a server.
So the design problem is not a chart. It is trust: what a system may do on its own, what a thumb may do to it, and how an owner can tell, without reading code, whether any of it is working.
── CONSTRAINTS ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
- An owner who is not an engineer — The first time I tried to enrol a passkey on the real server, the tool printed a link to localhost. On a phone, localhost is the phone. The output was correct and useless. Every guide since states where a command runs, what to fill in and what you should see.
- Real money behind a small screen — A phone makes every action cheap. A system that trades makes some actions expensive. The interface has to put the right amount of friction on each one, not the same amount on all of them.
- Costs and luck eat the edge — Indian equity charges are real, and a backtest can be bent until anything looks profitable. Any claim of an edge has to survive costs, data it has not seen, and the simple alternative of holding the market.
- A quiet system looks like a broken one — On the first real paper day the tradebook stayed empty for hours. The engine was healthy: strategies build their state from candles they have seen, and a live process starts having seen none. The fix was a warm-up, and a plain-words pulse that says what each strategy is waiting for.
── DECISIONS ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
* The decisions
* Write the bar before the test, then report what fails
I asked for ten profitable chart-pattern strategies. That deliverable is easy to fake with a curve-fitted backtest. Instead I wrote the bar down first: pre-committed pass criteria, an in-sample and out-of-sample split, a check that the strategy beats simply holding the market, and a second confirmation on years and stocks it had never seen.
Nineteen candidates went through it. None survived, and all nineteen were deleted with their numbers recorded. Two passed the first stage and failed the second, which is what chance looks like across about forty tests. The bot's one "proven" strategy failed a ten-year re-test.
The same rule applies to the bot's own signals. A confidence score that was re-checked after every trade let a strategy with no edge touch "proven" about half the time within 300 trades. I redesigned the thresholds until that fell to 8%, while a real edge was still recognised 89% of the time.
Not taken: Tune until ten strategies look good, and ship the backtest.
Not yet proven: The data was free Yahoo data, not the broker's, and nothing from that work was paper or live traded. A second round of twenty candidates is designed around what killed the first; its results are not in the notes.
Figure: The test lab's Trust section: the same trades at normal, 1.5 times and twice the costs, a first-70%-and-the-rest split, a thousand reshuffles of the trades, and settings sweeps labelled steady plateau or no steady plateau.
* Make safe things easy and risky things deliberate
Actions are tiered by what they do to risk. Stopping and killing reduce risk, so they are one gesture; the kill is a one-second hold, and a short press does nothing. Releasing a kill needs a passkey approval bound to that exact action, and a typed word. Anything that changes who can get in is possible only over SSH.
The trading rules follow the same direction. Tightening a rule is one tap. Loosening one needs the passkey and the word LOOSEN, and a change that mixes both is refused. Every limit is capped by a ceilings file that the web interface cannot write.
Not taken: One confirmation dialog for everything, which teaches an owner to tap through all of them.
Not yet proven: Proven in a real browser with a virtual passkey, and passkeys are enrolled on two real devices. Restart drills and the passkey inside the installed home-screen app are still unverified, and arming Live from the phone is not built.
Figure: The same trading rule on desktop and phone. On desktop, tightening the late-entries cutoff ends in a Tighten now button. On the phone, loosening it shows a warning that it needs the passkey and the word LOOSEN.
* An AI opinion has to earn its say
The tempting version of an AI trading bot lets the model trade because it sounds sure. I did the opposite: Claude’s calls are recorded and scored after the close, a kind of call earns a weight only by being right more than half the time, and that weight, fenced to a nudge and one small vote, is its whole influence on the money. The chapter on Claude above takes it apart.
The 21 trading rules work the same way. A blocked trade is still followed in a pretend account, so each rule shows in rupees what it cost or saved, with a range, and gets a verdict only after enough events.
Not taken: Let the model advise because it sounds sure.
Not yet proven: No real call has been scored yet. The screens show made-up data, and the weights are the design, not a result.
* Let the bot improve itself, and let me undo all of it
Every change the bot makes by itself, from starting or retiring a strategy to switching to a re-tuned version, goes into a journal with its reason and its evidence. One tap undoes it, or the passkey and the word UNDO when undoing would raise risk.
Re-tuning is an experiment, not a search for the best number. Settings are tested on nine months and judged on the next three it never saw, and only the middle of a steady plateau can become a challenger, which runs on paper beside the champion.
My own simulation said re-tuning on noise was safe, but I had only tried the easy case. A fresh reviewer ran the realistic one, a strategy that already works whose neighbouring settings are just as good, and found equal settings being promoted in 29 to 39% of simulated years. Two safeguards brought it to 4 to 6%, against a 10% limit.
Not taken: A bot that quietly adjusts itself and a dashboard that shows only the result.
Not yet proven: No real re-tuning search has run on the server with real history. The figures above are from simulation.
Figure: The Changes list: re-tuned versions, a strategy added from Claude, a retired strategy and an intraday-to-delivery switch, each with who made it and whether it can be undone, one marked Undo needs passkey.
── SOLUTION ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
* What shipped
A Python engine on the broker's API runs the same code in backtest, paper and live. A small controller supervises it as a separate process and serves a phone-first interface, signed in with a passkey over a private network, so nothing is exposed to the public internet. Upgrading or restarting the controller never interrupts a running engine.
The interface came from a critique of my own first version, which I rejected as cluttered and unclear. Several of the complaints turned out to be data problems: backtest fills were stamped with the time the replay ran, so no trade could be found on a chart, and stops and targets lived only in memory. I fixed the engine first, then drew the screens. Colour means only money or risk, so gains and losses are the loudest things on screen, and a poor record is shown beside a strategy's name rather than hidden.
Beside the controller sit a reader for a subset of TradingView's Pine Script that refuses, with a line number, anything it cannot honour; a test lab with a Trust section; a daily plan and evening review; and a stock picker that is graded every night against random stocks traded by the same strategy. If it is not beating chance after 60 trades, its picks freeze.
All screens on this page come from a throwaway harness with made-up data. They show the design, not a result.
* A trading day, as the bot lives it
The schedule is part of the product: the owner should be able to guess what the bot is doing at any hour.
- 08:45 — Today's plan: The market reading, each engagement's stocks and why, the risk budget, and what to avoid.
- 09:00 — Picks start: The stocks chosen the night before begin trading, on paper.
- 09:15 — Market opens: Morning checks first: trading day, broker login, run profile, books match the broker.
- 15:10 — Square-off: Intraday positions close. Stops and targets are managed by the bot throughout.
- 15:45 — Evening review: Profit by desk, strategy and rule, the plan against what happened, and questions for Claude.
- 16:30 — Claude is scored: Each of Claude's calls is checked against what the market did.
- 19:00 — Night scan: A low-priority job tests every strategy on the Nifty 100 and ten ETFs and picks tomorrow's stocks.
- Saturday — Weekly report: What worked, what changed, and proposals, written for the owner and for Claude's Monday brief.
- Figure: Three phone screens: open positions with a stop-loss and target bar for each, the sheet that asks for a passkey to loosen a rule, and a weekly summary of what the bot changed with proposals. (On the phone: open positions, a risky change that asks for more, and the week in plain words. Made-up data.)
── OUTCOME ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
- 19 of 19 — chart-pattern strategies rejected by the validation gate
- 21 — trading rules, each one measuring what it costs or saves
- 1 tap — to undo anything the bot changed by itself; the passkey too, when undoing would add risk
- 0 — live trades. Live stays locked until a strategy earns it
What I cannot show: profit and loss, usage, or a live result. There is none, and I would rather say so than show a number. Live trading is not enabled, and much of the newer work is built and tested but not yet deployed or verified in daily use. The figures above measure the thing itself, from my build notes of 23 October 2026.
── LOOKING_BACK ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
The lesson I keep is to read the engine before drawing the screen. Half of my complaints about the first interface were really missing data, and no amount of layout would have fixed them. A real browser run also found six defects that 1,500 tests had passed.
What I would do sooner: put real days on paper before building more. I built faster than I verified, and a large part of the bot is tested but not deployed. The next steps are a real paper week, then the one-share live test, before any of the cleverness gets a vote.