|
PineForge v0.1.2-7-ga095e36
Deterministic PineScript v6 backtest runtime — C ABI reference
|
A PineForge backtest is a four-step pipeline. Each step maps to one function in <pineforge/pineforge.h>.
The argument is reserved for future use; pass NULL today. Each handle owns its own state machine and is not thread-safe — one handle per worker thread.
Override Pine input.*() values, strategy(...) declaration params, or runtime knobs before calling run_backtest. Calls made after a run are accepted but only take effect on subsequent runs.
Full list of recognised override keys is on the Configuration page.
Or for the common case of "auto-detect timeframe, no magnifier":
The runtime fills r in place — the pf_report_t struct itself is caller-owned (typically stack-allocated), but the arrays it points to (trades, security_diag, trace, trace_names) are heap-allocated inside the runtime.
See Report schema for every field. Quick summary:
Both calls are mandatory and idempotent. Order matters: free the report first, then the handle — the report's trace_names strings are owned by the live handle.
strategy_free() while r.trace_names is still in use leaves dangling pointers — the trace name string table lives on the strategy, not the report.A pf_strategy_t carries closed-trade history, equity curve, and position state. Calling run_backtest twice on the same handle accumulates trades from both runs into the second report — the state machine never rewinds.
For parameter sweeps, walk-forward windows, or any A/B comparison, create a fresh handle per run:
This is the canonical sweep loop. See tutorial/run_advanced.py for the Python equivalent and Parameter sweep for the annotated walkthrough.
The C ABI does not return error codes. Instead:
strategy_create returns NULL. Always check.n == 0) is valid — the report is filled with zero counts and an empty trade list.request.security symbol) emit a pine_runtime_error log line and either skip the offending evaluation or terminate the strategy bar — never the host process.If you need finer-grained error reporting, attach a logger via the runtime's internal log hook (closed-source-only API; not part of the public ABI).