PineForge v0.10.12
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
pineforge.h File Reference
#include <stdint.h>
#include <stddef.h>
#include <pineforge/version.h>
Include dependency graph for pineforge.h:

Go to the source code of this file.

Data Structures

struct  pf_bar_t
 Single OHLCV bar pushed into the engine. More...
 
struct  pf_trade_t
 Closed-trade record returned in pf_report_t::trades. More...
 
struct  pf_trade_stats_t
 Trade-level statistics block — computed once each for all / long / short. More...
 
struct  pf_equity_stats_t
 Equity-curve-derived statistics (all-trades only, like TV). More...
 
struct  pf_metrics_t
 Composite metrics container: trade stats (all / long / short) + equity-curve stats. More...
 
struct  pf_equity_point_t
 Single per-script-bar equity point. More...
 
struct  pf_security_diag_t
 Per-request.security() site diagnostic counters. More...
 
struct  pf_trace_entry_t
 Single per-bar trace entry. More...
 
struct  pf_report_t
 Backtest report filled by run_backtest / run_backtest_full. More...
 
struct  pf_version_t
 Runtime version descriptor returned by pf_version_get. More...
 

Macros

#define PF_API
 
#define PF_ABI_VERSION   2
 Monotonic ABI version of pf_report_t / pf_trade_t layout.
 

Typedefs

typedef void * pf_strategy_t
 Opaque handle to a compiled strategy instance.
 

Enumerations

enum  pf_magnifier_distribution_t {
  PF_MAGNIFIER_UNIFORM = 0 ,
  PF_MAGNIFIER_COSINE = 1 ,
  PF_MAGNIFIER_TRIANGLE = 2 ,
  PF_MAGNIFIER_ENDPOINTS = 3 ,
  PF_MAGNIFIER_FRONT_LOADED = 4 ,
  PF_MAGNIFIER_BACK_LOADED = 5
}
 Bar-magnifier sub-bar sampling distribution. More...
 

Functions

pf_strategy_t strategy_create (const char *params_json)
 Allocate a new strategy instance.
 
void strategy_free (pf_strategy_t s)
 Release a strategy handle previously returned by strategy_create.
 
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 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.
 
void report_free (pf_report_t *report)
 Free heap arrays attached to a filled report.
 
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_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.
 
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.
 
pf_version_t pf_version_get (void)
 
int pf_abi_version (void)
 
const char * pf_version_string (void)
 Full git-derived version descriptor.
 

Macro Definition Documentation

◆ PF_API

◆ PF_ABI_VERSION

#define PF_ABI_VERSION   2

Monotonic ABI version of pf_report_t / pf_trade_t layout.

Bumped whenever a caller-visible struct grows. Consumers MUST verify pf_abi_version() == PF_ABI_VERSION before calling run_backtest. pf_report_t is caller-allocated: growth causes silent stack corruption in old callers that under-size the struct. pf_trade_t is runtime- allocated: growth causes array-stride misindexing in old readers that iterate the trades array with the stale sizeof. Value 2 = first versioned layout (metrics + equity curve); .so files predating this macro have no pf_abi_version symbol — treat dlsym failure as version 1.

Definition at line 78 of file pineforge.h.

Typedef Documentation

◆ pf_strategy_t

typedef void* pf_strategy_t

Opaque handle to a compiled strategy instance.

Definition at line 353 of file pineforge.h.