|
PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
|
Run a single compiled strategy.so over a 2-D grid of MACD periods. No recompile — every iteration creates a fresh handle, sets new inputs via the C ABI, and runs a clean backtest.
Numbers depend on the OHLCV snapshot — refresh with python3 tutorial/data/fetch_btcusdt.py for current Binance bars.
run_backtest resets per-run broker, trade, equity and report state before each one-shot run. Configuration persists on the handle, and so do the generated script's own members: the committed tutorial strategy reads its inputs and builds its TA objects once per handle. The example still creates a fresh handle per grid point so every configuration is explicit and the same pattern works safely with concurrent workers.
Do not use repeated one-shot calls to model a continuous session: use the streaming lifecycle, which deliberately preserves the warmed strategy and broker state across the data-source handoff.
Save it two directories below the repository root (for example demo/python/sweep.py in a clone): the ROOT and sys.path lines assume that depth.
Same fresh-handle pattern, sliced bar windows. It needs a feed longer than one window: on the tutorial's 672-bar CSV range(0, n - window, step) is empty and the loop never runs.
Each window starts cold — same equity, same TA seeds, no carry-over trades from the previous window.
strategy_create is cheap — it allocates one struct and zeros a few buffers. The expensive work happens inside run_backtest_full. On the tutorial's 672-bar feed, a fresh-handle MACD run takes ~0.5 ms — the sweep loop's dominant cost is Python-side argument marshalling, not the engine.
tutorial/run_advanced.py — the shipping reference implementation this example mirrors