PineForge exposes three configuration surfaces:
- Pine inputs — anything declared with
input.*() in the source script.
- Strategy declaration overrides — fields of the script's
strategy(...) call.
- Runtime knobs — bar magnifier, trade-start gating, trace recording.
All three are set on the strategy handle, before calling run_backtest. Calls made after a run are queued for the next run.
Pine inputs
void strategy_set_input(pf_strategy_t s, const char *key, const char *value)
Override a Pine input.
| Pine type | Serialized form |
int | decimal string, e.g. "21" |
float | decimal string, e.g. "0.04" (use . always — no locale) |
bool | "true" / "false" |
string | the string itself (no quoting) |
source | one of "open", "high", "low", "close", "hl2", "hlc3", "ohlc4", "hlcc4" |
color | hex "#RRGGBB" or "#AARRGGBB" |
timeframe | TV-style — "1", "5", "60", "1D", "1W" |
The key is the input's title, exactly as it appears in the Pine title= argument. If no title was given, the runtime falls back to the variable identifier.
- Note
- Unknown keys are silently accepted and ignored. This lets harnesses set a superset of inputs across multiple strategies without per-strategy gating.
Strategy declaration overrides
void strategy_set_override(pf_strategy_t s, const char *key, const char *value)
Override a strategy(...) declaration parameter.
These mirror the parameters of Pine's strategy(...) declaration. Setting them via the C ABI overrides the script-defined defaults for this run.
Runtime knobs
Bar magnifier
Configured per-call on run_backtest_full:
1, 4,
void run_backtest_full(pf_strategy_t s, pf_bar_t *bars, int n, const char *input_tf, const char *script_tf, int bar_magnifier, int magnifier_samples, pf_magnifier_distribution_t magnifier_dist, pf_report_t *out)
Run a backtest with explicit timeframe and magnifier configuration.
@ PF_MAGNIFIER_ENDPOINTS
Default — exact O,H,L,C points plus uniform fill between.
Volume-weighted sampling is a separate sticky toggle:
void strategy_set_magnifier_volume_weighted(pf_strategy_t s, int on)
Toggle volume-weighted bar-magnifier sampling.
See Bar magnifier for the sampling model.
Trace recording
void strategy_set_trace_enabled(pf_strategy_t s, int on)
Toggle per-bar trace recording.
Captures // @pf-trace name=expr pragma values per bar into pf_report_t::trace. Zero-cost when disabled. See Report schema § Trace records.
Trade start gate
void strategy_set_trade_start_time(pf_strategy_t s, int64_t timestamp_ms)
Set the earliest Unix-ms timestamp at which strategy order commands may fire.
Earlier bars still execute user code and warm TA / series state. Only order commands are ignored. Use this to leave room for indicators to stabilize before trades start.
Configuration is per-handle
Configuration values stick to the handle, not the run. They apply to every run_backtest on that handle until overwritten or strategy_free is called.
For parameter sweeps, create a fresh handle per run — a handle's trade history accumulates across runs (see Lifecycle):
for (int len = 10; len <= 30; len += 2) {
char buf[16]; snprintf(buf, sizeof buf, "%d", len);
}
pf_strategy_t strategy_create(const char *params_json)
Allocate a new strategy instance.
void run_backtest(pf_strategy_t s, pf_bar_t *bars, int n, pf_report_t *out)
Run a backtest with auto-detected timeframe and no bar magnifier.
void strategy_free(pf_strategy_t s)
Release a strategy handle previously returned by strategy_create.
void report_free(pf_report_t *report)
Free heap arrays attached to a filled report.
void * pf_strategy_t
Opaque handle to a compiled strategy instance.
Backtest report filled by run_backtest / run_backtest_full.