
With Trade Stories You’ll Power Through Your Trading Strategy Backtesting
In a nutshell, the Trade Story format is a Domain Specific Language (DSL) for defining trading strategies. It’s semi-prescriptive, in the sense that it allows enough leeway for traders to write “natural language” trade setups that they’ll understand AND find useful, while still retaining enough structure and common understanding to be processed by automated tools and AI agents.
Just want to get up-to-speed quickly with Trade Stories? Read this first!
If you’re a trader (Futures trader, Options trader, Swing trader, Day trader, Scalp trader, you name it…), chances are you already have a trading system set up — or you’re in the process of setting one up.
By trading system I mean a collection of a few strategies/trade setups that are consistent, repeatable and measurable.
A trading system is widely recognised as a structured, rule-based framework that dictates when to enter and exit trades, how much capital to risk, and under what conditions to stay on the sidelines. Following a fully backtested trading system removes the emotional bias from your trading.
Trade setups when defined properly can be reliably backtested, so that when you start to live trade with them — and execute each trade consistently according to the setup’s rules — you’ll already have some reliable stats showing the anticipated win rate, drawdown, profit margin etc, all based on historical data and market conditions.
Until now, there hasn’t really been a “semi-prescriptive” notation for defining trade setups: a format that could be handed to an AI agent, for example, so that the agent will quickly understand what the setup rules mean (and what they don’t).
This is where Trade Stories come in.
I started to formulate them as a lightweight DSL while looking at ways to automate the whole backtesting process, so that I could hand the backtesting off to Claude Code — which would then write a TradingView strategy in Pine Script from each story. (Watch for a new article on that topic very soon).
But the story format is applicable to a wider array of use cases than that.
The format’s conciseness means that Trade Stories are easily “digested” by people as well as AIs. They’re a handy way to store, categorise and share trade setups, and to remind traders to think about certain things when writing them — like risk management and exit criteria.

Why “semi-prescriptive”?
Traders aren’t necessarily coders — and neither should we be. We want to focus our efforts on actually trading and backtesting, not on debugging a Python script or deciphering an overly rigid, arcane definition language. Instead, we’d much rather write a trade setup in plain English (or German or whatever).
But we don’t want the definitions to be too loosely worded either, as it all becomes prone to ambiguity and misinterpretation, and even “semantic drift”, where the same phrase or sentence starts to mean subtly different things across different documents.
Semi-prescriptive, it turns out, is a potent middle-ground where the stories are written in natural language, but with certain style and formatting conventions to keep it all consistent and precise. This approach also provides just enough discipline to put you in the mindset of being precise with your wording, and sticking to a particular set of definitions.
Why “Trade Stories”?
As I have a software engineering background, I’ve seen my fair share of user stories — each user story is a functional requirement, and together they define an IT system that the developers will then team together and build.
User stories are often written in the Gherkin format to make them more “machine-readable” while still being clear and expressive enough to be useful to humans.
User stories follow this format (assuming the user is trapped in the 1980s):
Pretty clear and straightforward — and also just formal enough that software testers can write automated test suites based on these user stories.
But what does that have to do with trading??
Here’s a Trade Story
So a Trade Story follows a similar pattern, though extended:
That’s quite a lot of stuff to go into defining one trade setup, and not all of it is necessary every time.
BUT the following clauses should always be there (these are all defined further down the page:
- Story — basic identifier
- Trading — literally, what are you trading, so you know what security, TF etc to have open
- Given —if this isn’t true, don’t even consider taking the trade!
- When — the core premise. Without this, nothing will ever happen
- Then — this is what to do, so kind of needs to be there
- Until/Taking — without this pair of clauses, the trade would never close in profit
Everything else is largely about risk management — stop loss details, position size, “emergency” close (the Unless clause), or invalidation before the position’s been opened (Except). Still vital, but you might have defaults for these so they don’t have to be specified every time, or certain details just may not be relevant.
But the main thing is not to feel like you must fill in details for every single clause.
Only add the clauses that your Trade Story needs.
If you’re using Trade Story System (which is 100% free and open source), it guides you through writing and disambiguating your trade setups, so everything becomes precise and locked-down.
What are the benefits?
I’ve mentioned a few benefits already, but perhaps chief among them is this. Using the same consistent clause names — Given, When, Then, Until, etc — means the same common markup language will be understood across any number of trading strategies, and by traders/colleagues who you share them with. Automated tools, AI agents in particular, will instantly understand too.
e.g. if you’re using Codex, Gemini CLI or some other AI coding agent, just give it this page’s URL telling it to absorb these details and the DSL as a set of strategy rules, and prompt it with things like:
- “Analyse these Trade Stories I’ve written and look for gaps”
- “Turn this strategy into a Trade Story, then backtest it for me in TradingView”
- “Write a TradingView strategy which implements this Trade Story in Pine Script”
If you’re using Claude Code, install Trade Story System at once! It automates huge parts of this for you, and creates an instructive environment that guides you through writing trade strategies and backtesting them. It also writes your TradingView Pine strategies directly from your Trade Stories, and will tell you where details are missing or could be pinned down.
You might also have defaults set up — e.g. always the same initial equity, position size (5% of equity, or 500 USD), whether to close the whole position or 40% of it and then add a trailing stop, etc.
You can add details and disambiguations into the Notes section underneath; but generally it’s good to keep each Trade Story pretty minimal, only specifying what’s absolutely needed, and preferably in a terse format within the Given/When/Then/etc clauses. You should find this makes the stories far easier to work directly from, to change (especially during backtesting), and to share with others.
The Trade Stories DSL page describes the domain-specific language in detail.
Where to from here?
Watch this space for an article soon about incorporating Trade Stories into an AI-driven trading setup, using Claude Code and TradingView.
If you’re interested to chat with other traders about Trade Stories, join the SaveWithCrypto Discord group, where I’m often hanging about or posting trade setups too.
Also, I would love to hear about how you’re using Trade Stories — and to get your feedback and ideas for improvements. It’s early days, and we want to make the DSL genuinely useful for traders.
I appear regularly on SaveWithCrypto livestreams on YouTube, and we also broadcast the same livestream to my X account at x.com/mafftopia. We’ll also announce Trade Story updates and related projects there too, especially on the AI trading side of things.
Also check out my own YouTube channel where I upload Science and Technology News reactions every few days. Lots of stuff about AI, genetics, quantum computing and of course automated futures trading, Bitcoin and crypto in general.