I compiled TradingView’s PineScript to native C++ for backtesting — 104× faster than the Python tools, deterministic, bit-for-bit parity with TradingView (231/232)
PineScript is the de-facto language retail traders use to write trading strategies — but it only runs inside TradingView’s closed sandbox. You can’t run it locally, can’t run it at scale, and can’t independently verify the backtest it shows you. I spent \~5 months building a transpiler (Pine v6 → C++) plus a native runtime to fix that. It’s open source. A few problems that were fun to solve, and where I’d genuinely like scrutiny:
Determinism. To match a reference implementation trade-for-trade, the same input has to produce a byte-identical trade list every run — so floating-point operation order is fixed and reproducible across runs. No -ffast-math reordering surprises.
Matching a spec I can’t see (clean-room). TradingView’s broker emulator — fill ordering, margin handling, bar-magnifier intrabar logic — isn’t documented. I implemented from the public Pine grammar, then reverse-engineered the emulator’s behavior by hand-exporting its “List of Trades” and diffing against my output across \~312K trades / 232 strategies spanning 22 feature categories (TA, brackets, OCA, MTF/LTF, matrices, UDTs, sessions…). 231/232 match exactly. The one outlier is TradingView’s own non-determinism at a 1× equity-margin boundary — mine is deterministic and, I’d argue, the correct one (documented in the repo).
Performance. Median backtest 9.7 ms vs 1,070 ms for PyneCore (Python, GIL + IPC overhead) → \~104×; \~6.7× vs vectorbt (Numba). \~17M bars/sec. A big chunk of the optimization-workflow win is dlopen + run, so sweeping parameters doesn’t recompile.
Benchmark honesty: “104×” is median single-backtest vs PyneCore; full methodology + run_corpus.sh to reproduce all 232 probes is in the repo. Engine is Apache-2.0, corpus is public, transpiler source is available.
Background: solo, came from a CFD / numerical-computing background, which is where the determinism + perf obsession comes from.
Repo: https://github.com/pineforge-4pass/pineforge-engine
Happy to get torn apart on the numerical approach or the benchmark setup — that’s why I’m posting.
https://redd.it/1tw1lno
@r_cpp
Post #25365
16