How I Designed an AI-Assisted Trading Strategy Architecture

Building an AI-assisted trading system sounds simple: give an AI model a trading strategy, generate code, run a backtest, and return the results. But there is a problem: how can we make sure the generated code actually matches what the user intended?
My approach is to use a Strategy AST (Abstract Syntax Tree) as the source of truth instead of letting AI directly generate executable trading code.
The architecture looks like this:
User → AI Assistant → Strategy AST → Validation → Backtest Engine → Results
The AI is responsible for understanding natural language and helping users create or modify strategies. For example, a user might say: "Buy when RSI is below 30 and sell when RSI goes above 70." The AI converts this intent into a structured AST that contains indicators, operators, parameters, entry rules, exit rules, and risk management.
The important part is that the AST is validated before reaching the backtest engine. The system can check schema validity, logical conditions, indicator parameters, and risk constraints. This helps prevent invalid strategies from being executed.
Another benefit is versioning. If a user changes RSI from 30 to 25 or adds an EMA filter, the system can track exactly what changed between strategy versions. ASTs can also be normalized and hashed to identify identical or structurally similar strategies.
I also prefer using AI as an assistant rather than the execution engine. The flow becomes:
AI → AST → Validator → Execution Engine
Instead of:
AI → Generated Code → Execution
This creates a clear separation between probabilistic AI behavior and deterministic system behavior. AI is good at understanding intent, explaining strategies, and analyzing results. Deterministic software is better for validation, calculations, risk controls, and execution.
The main lesson I learned is that AI does not need to control everything. A reliable AI-assisted trading system should combine the strengths of both approaches: let AI handle natural language and reasoning, while structured software handles validation and execution.
For me, the Strategy AST is the bridge between human intent and deterministic trading infrastructure.
All rights reserved