Case Studies / Natural-Language-to-Multi-Platform Strategy Compiler

In ProgressApril 2026

Natural-Language-to-Multi-Platform Strategy Compiler

A microservices platform that turns a plain-language strategy description into a validated intermediate representation, then compiles it into MT4, MT5, Pine Script, and broker-native code from a single source of truth.

PythonFastAPIReactTypeScriptDockerKubernetesTerraformPostgreSQL

Problem

Every retail algorithmic trader eventually hits the same wall. A strategy idea lives in one platform's syntax, whether that's MQL4, MQL5, or Pine Script, and porting it to another platform means a manual, error-prone rewrite. Worse, describing a strategy precisely enough for someone (or something) else to implement correctly is its own skill. Most strategy descriptions are ambiguous, something like "buy on a pullback in an uptrend," in ways their author doesn't notice until the implementation and their mental model start to diverge.

The goal was a platform where a trader describes a strategy in plain language once, gets ambiguities surfaced and resolved before any code gets written, and receives working code for whichever platform or broker API they actually trade on. One definition, not several parallel ones slowly drifting apart.

Architecture

The backend is split into nine services behind a gateway.

LLM service. Parses a natural-language strategy description into structured entry, exit, and risk components, scores its own confidence per component, and generates targeted clarification questions for anything ambiguous instead of guessing.

Strategy engine. Owns the intermediate representation, or IR: a strategy graph with condition trees, a dependency sorter so indicators compute in the right order, a timeframe resolver, and a schema-versioned migrator (v1.0 to v1.1 to v2.0) so existing strategies survive changes to the IR itself.

Validation. A schema validator and conflict checker run before a strategy is ever compiled, catching contradictory rules, like an exit condition that can never be reached, at the IR level instead of at runtime.

Code generators. One generator per target (MT4, MT5, Pine Script, a generic broker API), each consuming the same validated IR and emitting idiomatic code for its target.

Backtesting and broker-execution services. The backtesting engine validates a strategy against historical data using the same IR the code generators consume. Broker-execution runs it live, with its own safety layer of a circuit breaker, kill switch, order deduplicator, and position reconciler sitting between the strategy runtime and the broker.

A React frontend and an API gateway front the whole system. Each service is containerized independently, with Kubernetes manifests and Terraform handling provisioning.

Implementation

The IR is the actual product. Everything else just consumes it. A strategy graph gets built from parsed natural-language components, validated for structural conflicts, and only then handed off to whichever code generator the trader wants output for. Because every generator reads the same graph, a strategy compiled to MT5 and one compiled to Pine Script are guaranteed to encode the same logic. There's no separate per-platform translation step to quietly drift out of sync.

The confidence scoring in the LLM service is what keeps the whole pipeline honest. Rather than silently picking an interpretation for an ambiguous phrase, low-confidence components get routed to a clarification generator that asks the trader a specific question instead of a generic "please clarify." Only components above a confidence threshold reach the strategy graph unprompted.

Schema migrations for the IR exist because the graph schema itself changed shape as new block types, filters and risk blocks among them, got added over time. The migrator lets strategies written against an older schema version keep compiling instead of breaking silently the next time someone touches them.

Challenges

Keeping code generation deterministic and idiomatic per target turned out harder than just getting it to compile. MT4 and MT5 output needed to read like something a human MQL developer would actually write: sensible variable names, no dead branches left over from IR nodes that always evaluate true or false. A literal transliteration of the graph wasn't good enough, so each generator ended up needing its own simplification pass over the IR before emitting anything.

Ordering indicator computation correctly across arbitrary condition trees took real work too. A condition can depend on another condition's output, which can depend on an indicator, which depends on a timeframe resolution. The dependency sorter had to do genuine topological sorting rather than assume a flat evaluation order, or it would recompute shared indicators redundantly or evaluate a condition before its dependency was even ready.

Results

A single natural-language description now produces validated, consistent code for four different execution targets, instead of several manually maintained ports of the same idea slowly falling out of sync. Structural conflicts that used to surface as runtime bugs now get caught by the validation layer before any code is generated at all. And the confidence-scoring and clarification loop turns an ambiguous strategy description into a precise one before compilation, rather than after a trader discovers the generated code doesn't match what they actually meant.