PineForge v0.12.3-30-g11e61d4
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
Per-strategy configuration

Override input. More...

Functions

void strategy_set_input (pf_strategy_t s, const char *key, const char *value)
 Override a Pine input.
 
void strategy_set_override (pf_strategy_t s, const char *key, const char *value)
 Override a strategy(...) declaration parameter.
 
void strategy_set_magnifier_volume_weighted (pf_strategy_t s, int on)
 Toggle volume-weighted bar-magnifier sampling.
 
void strategy_set_trace_enabled (pf_strategy_t s, int on)
 Toggle per-bar trace recording.
 
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.
 
void strategy_set_chart_timezone (pf_strategy_t s, const char *tz)
 Set the strategy's chart timezone (IANA / POSIX TZ string).
 
void strategy_set_syminfo_timezone (pf_strategy_t s, const char *tz)
 Plumb the symbol's exchange timezone (IANA string) into syminfo.
 
void strategy_set_syminfo_session (pf_strategy_t s, const char *session)
 Set the symbol's session string (e.g.
 
void strategy_set_syminfo_type (pf_strategy_t s, const char *type)
 Set the instrument class (syminfo.type: "forex", "stock", "crypto", "futures", "index", "fund", "cfd", ...; default "crypto").
 
int strategy_set_syminfo_string (pf_strategy_t s, const char *key, const char *value)
 Set one of the remaining string syminfo.
 
void strategy_set_syminfo_mintick (pf_strategy_t s, double mintick)
 Set the instrument tick size (syminfo.mintick, default 0.01).
 
void strategy_set_syminfo_pointvalue (pf_strategy_t s, double pointvalue)
 Set the instrument point value (syminfo.pointvalue, default 1.0) — the $-per-point-per-contract multiplier applied to every money path: realized PnL and MFE/MAE, open profit / mark-to-market equity (and the drawdown / runup extremes), percent-of-equity and cash position sizing, percent commission notionals, and the margin admission check.
 
void strategy_set_syminfo_metadata (pf_strategy_t s, const char *key, double value)
 Inject a fundamental/exchange metadata value by Pine member name (e.g.
 
int strategy_set_account_currency_fx_series (pf_strategy_t s, const int64_t *effective_from_ms, const double *account_per_quote, int n)
 Install a timestamped quote-to-account currency conversion curve.
 
int strategy_set_aux_security_feed (pf_strategy_t s, const pf_bar_t *bars, int n, const char *input_tf)
 Copy a finer feed used exclusively by same-symbol request.security calls.
 
const char * strategy_get_last_error (pf_strategy_t s)
 Returns the error message captured by the most recent run_backtest / run_backtest_full call on this strategy.
 

Detailed Description

Override input.

*() values, strategy(...) params, and runtime knobs.

Function Documentation

◆ strategy_set_input()

void strategy_set_input ( pf_strategy_t s,
const char * key,
const char * value )

Override a Pine input.

*() value before the next run.

Parameters
sStrategy handle.
keyThe input's title (or fallback identifier).
valueSerialized value — numbers as decimal strings, booleans as "true" / "false".

Calls after run_backtest are accepted but only take effect on subsequent runs.

References PF_API.

◆ strategy_set_override()

void strategy_set_override ( pf_strategy_t s,
const char * key,
const char * value )

Override a strategy(...) declaration parameter.

Recognised key values: initial_capital, commission_value, default_qty_value, pyramiding, slippage, process_orders_on_close, close_entries_rule, default_qty_type, commission_type.

References PF_API.

◆ strategy_set_magnifier_volume_weighted()

void strategy_set_magnifier_volume_weighted ( pf_strategy_t s,
int on )

Toggle volume-weighted bar-magnifier sampling.

Has no effect unless the bar magnifier is enabled in run_backtest_full.

References PF_API.

◆ strategy_set_trace_enabled()

void strategy_set_trace_enabled ( pf_strategy_t s,
int on )

Toggle per-bar trace recording.

Default off (zero-cost when off).

Enables capture for // @pf-trace name=expr pragmas already compiled into the strategy .so. Trace records appear in pf_report_t::trace.

References PF_API.

◆ strategy_set_trade_start_time()

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, but strategy.entry/order/exit/close commands are ignored.

References PF_API.

◆ strategy_set_chart_timezone()

void strategy_set_chart_timezone ( pf_strategy_t s,
const char * tz )

Set the strategy's chart timezone (IANA / POSIX TZ string).

Pine builtins hour, minute, second, dayofmonth, dayofweek, month, year and weekofyear return the wall-clock for the chart's timezone — TV exports trade rows in chart TZ too. Engine bars are stored as Unix-ms (UTC), so without this override these builtins return UTC and silently diverge from TV by N hours when the chart is on a non-UTC zone (Asia/Taipei = UTC+8 is the validator default).

Pass NULL, "", "UTC" or "Etc/UTC" for the legacy UTC behaviour (cheap, mutex-free). Any other value names a TZ resolved by the system tzdata; the per-bar decomposition then runs under a process-global mutex so multi-threaded harnesses don't corrupt each other's wall time.

Should be called before run_backtest / run_backtest_full. Persists across runs on the same strategy handle until overridden.

References PF_API.

◆ strategy_set_syminfo_timezone()

void strategy_set_syminfo_timezone ( pf_strategy_t s,
const char * tz )

Plumb the symbol's exchange timezone (IANA string) into syminfo.

Feeds session.ismarket / time(session) predicates. Defaults to "UTC" (crypto). Distinct from strategy_set_chart_timezone — the chart TZ drives wall-clock builtins and intraday-cap day rollover; this drives session membership. NULL is ignored. Call before run_backtest*.

References PF_API.

◆ strategy_set_syminfo_session()

void strategy_set_syminfo_session ( pf_strategy_t s,
const char * session )

Set the symbol's session string (e.g.

"0930-1600:23456", default "24x7"). Feeds session.ismarket / time(session). NULL ignored. Call before run_backtest*.

References PF_API.

◆ strategy_set_syminfo_type()

void strategy_set_syminfo_type ( pf_strategy_t s,
const char * type )

Set the instrument class (syminfo.type: "forex", "stock", "crypto", "futures", "index", "fund", "cfd", ...; default "crypto").

Scripts branch on it for instrument conventions (e.g. the forex pip size). NULL / empty ignored. Call before run_backtest*.

References PF_API.

◆ strategy_set_syminfo_string()

int strategy_set_syminfo_string ( pf_strategy_t s,
const char * key,
const char * value )

Set one of the remaining string syminfo.

* members by Pine member name: "ticker", "tickerid", "currency", "basecurrency", "description", "volumetype" (and "type"). Returns 0 when set, -1 for an unknown key, empty value or NULL. Call before run_backtest*.

References PF_API.

◆ strategy_set_syminfo_mintick()

void strategy_set_syminfo_mintick ( pf_strategy_t s,
double mintick )

Set the instrument tick size (syminfo.mintick, default 0.01).

Drives the directional stop-entry snap and slippage = N*mintick economics. Set per-instrument (e.g. 0.25 for ES, 0.00001 for FX). Non-positive ignored. Call before run_backtest*.

References PF_API.

◆ strategy_set_syminfo_pointvalue()

void strategy_set_syminfo_pointvalue ( pf_strategy_t s,
double pointvalue )

Set the instrument point value (syminfo.pointvalue, default 1.0) — the $-per-point-per-contract multiplier applied to every money path: realized PnL and MFE/MAE, open profit / mark-to-market equity (and the drawdown / runup extremes), percent-of-equity and cash position sizing, percent commission notionals, and the margin admission check.

Set per-instrument (e.g. 50 for ES). Non-positive ignored. Call before run_backtest*.

References PF_API.

◆ strategy_set_syminfo_metadata()

void strategy_set_syminfo_metadata ( pf_strategy_t s,
const char * key,
double value )

Inject a fundamental/exchange metadata value by Pine member name (e.g.

"shares_outstanding_total", "target_price_average"). These have no OHLCV source; reads of un-injected members return na. Call before run_backtest*.

References PF_API.

◆ strategy_set_account_currency_fx_series()

int strategy_set_account_currency_fx_series ( pf_strategy_t s,
const int64_t * effective_from_ms,
const double * account_per_quote,
int n )

Install a timestamped quote-to-account currency conversion curve.

Each value is account-currency units per one unit of the symbol's quote currency and becomes active, inclusively, at the corresponding Unix-ms timestamp. The latest active value carries forward; broker events before the first point use the scalar account_currency_fx metadata fallback. Installing a curve also selects the converted account-currency broker ledger, including during that pre-first fallback interval; it is not equivalent to a same-currency run merely because a rate happens to be 1. Arrays are copied. Timestamps must be strictly increasing and rates positive and finite. Pass n == 0 to clear the curve and restore scalar behavior. Timestamped curves currently support ordinary historical runs. Broker-open rate changes on margin-call-enabled carried positions are TV-pinned for 1x longs; carried shorts and leveraged positions fail closed at the crossing. Streaming, calc-on-order-fills, and bar-magnifier runs also fail closed.

Returns
0 on success, -1 for a null strategy or invalid arrays.

References PF_API.

◆ strategy_set_aux_security_feed()

int strategy_set_aux_security_feed ( pf_strategy_t s,
const pf_bar_t * bars,
int n,
const char * input_tf )

Copy a finer feed used exclusively by same-symbol request.security calls.

The next ordinary run_backtest_full call must receive native chart bars with input_tf equal to script_tf and bar magnifier disabled. Chart OHLCV, broker fills, and bar_index continue to advance only from that native chart feed; bars advance only request.security evaluators. Every auxiliary bar must map to exactly one native chart bar and every native chart bar must have at least one auxiliary bar, otherwise the run fails closed via strategy_get_last_error. Arrays are copied. Pass n == 0 to clear the auxiliary feed.

Returns
0 on success, -1 for a null strategy or invalid input.

References PF_API.

◆ strategy_get_last_error()

const char * strategy_get_last_error ( pf_strategy_t s)

Returns the error message captured by the most recent run_backtest / run_backtest_full call on this strategy.

Returns an empty string when the run completed normally, or NULL only when s itself is NULL. The pointer is owned by the engine and remains valid until the next run_backtest* call (which clears the captured error before it begins).

The runtime catches every std::exception derivative inside the engine's run loop so the C ABI never unwinds a C++ exception across the extern "C" boundary. Consumers must check this after every run to surface engine-rejected configurations such as a script timeframe finer than the input timeframe, a request.security timeframe below the chart timeframe without a supported lower-TF emulation, or a missing input timeframe when securities are registered.

References PF_API.