|
PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
|
Load N different compiled strategies, run them in parallel against the same OHLCV feed, and rank by net PnL.
The PineForge ABI is pure C with no global state beyond what each .so keeps internally — different strategy handles never collide, even across .so files compiled at different runtime versions.
The macd_cross row is the tutorial MACD on the tutorial feed; the other rows are illustrative, standing in for your own strategies.
.so exports only its PF_API C symbols and one toolchain symbol, std::piecewise_construct (the inventory is on ABI stability). Internal C++ classes (BacktestEngine, ta::*) stay hidden. No symbol clashes between strategies..so — each .so carries its own copy of the runtime, so .so files built against different engine releases load side by side. pf_report_t grows with the ABI (4 in v1.0.0, 3 in v0.13.1), so check each one's pf_abi_version() before handing it the ReportC below (see ABI stability).One handle per thread. A single pf_strategy_t is not thread-safe — its internal state machine assumes serial advance. But N handles on N threads is fine.
Save it two directories below the repository root (for example demo/python/multi.py in a clone): the ROOT and sys.path lines assume that depth.
ctypes releases the GIL across the C call. Multiple Python threads running run_backtest_full concurrently do execute in parallel inside the runtime — the bottleneck is real CPU, not the GIL.
For embarrassingly-parallel workloads (e.g. 1000-strategy comparison sweeps), ThreadPoolExecutor keeps one backtest running per worker.