TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25365 16
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
GitHub GitHub - pineforge-4pass/pineforge-engine: Open-source PineScript v6 backtest engine that reproduces TradingView trade-for-trade:… Open-source PineScript v6 backtest engine that reproduces TradingView trade-for-trade: 4,189/4,190 probes excellent-or-strong (312 open corpus + 413 community scripts on 15 markets), 2.8M trades ma...
More from @r_cpp
  1. Sep 29, 2026Boost.Graph 1.95 will be C++17 Dear Boost.Graph community, In two release cycles (Boost re…
  2. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  3. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  4. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  5. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  6. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →