Inspiration
I create trading tools for different platforms. The same trading rule may need to exist in Pine Script for TradingView, MQL5 for MetaTrader, and Python for research. Keeping separate implementations consistent is difficult: a small difference in logic can produce different events.
Existing code converters can help translate between languages, but compilation alone does not prove that the implementations behave the same way. I wanted a way to describe a rule once and make differences visible.
What it does
Séance takes a trading rule written once as data and generates three implementations:
- a Python reference;
- an MQL5 expert;
- a TradingView Pine v6 indicator.
It compares the Python event stream with a recorded MQL5 run on the same synthetic candles, event by event, in order and by bar time. On the included example, they match on all 618 events.
Pine was compiled and checked manually by event counts. It is not part of the automated event-by-event comparison.
The rule language supports comparisons, logical operators, parentheses, integers, parameters and a fixed set of bar-related terms. Unsupported expressions are rejected with an error rather than silently accepted.
How I built it
The project uses a spec-driven approach with Kiro. The repository contains the problem, scope and trading rule specifications in the .kiro/specs folder. A fourth specification describes the next planned improvement.
Three custom Kiro agents were configured as read-only reviewers: a spec auditor, a QA reviewer and a product reviewer. They helped examine the architecture, verification and user experience.
Challenges I ran into
The first comparison used market data that could not be included in the public repository. To make the example reproducible, the project now includes synthetic candles generated from a fixed seed.
MetaTrader cannot run inside the browser, so the demo compares the live Python result with a recorded output from the generated MQL5 expert. The page clearly labels that limitation.
Accomplishments I'm proud of
The verification checks that changes to the rule's predicates reach all three generated targets. A deliberately altered copy of the project was used to check that the acceptance tests could detect problems.
On the included data, the Python and recorded MQL5 results match on 618 events with no discrepancies. The acceptance suite passes 9 out of 9 checks, and the expression equivalence test passes 468 cases.
What I learned
A useful comparison needs clear boundaries. Matching results on one example does not prove that every rule will agree, and an implementation that was checked manually should be described as such.
What's next
The next planned step is to generate the instrumented Pine probe from the rule skeleton instead of editing it by hand. This improvement is specified in .kiro/specs/04-probe-variant.md but is not implemented yet.
Built With
- kiro
- mql5
- pine
- python
- script