52#include <pineforge/version.h>
56#if defined(_WIN32) || defined(__CYGWIN__)
57 #if defined(PINEFORGE_BUILD_SHARED)
58 #define PF_API __declspec(dllexport)
60 #define PF_API __declspec(dllimport)
62#elif defined(__GNUC__) || defined(__clang__)
63 #define PF_API __attribute__((visibility("default")))
83typedef enum pf_magnifier_distribution_e {
95typedef struct pf_bar_s {
107typedef struct pf_trade_s {
123typedef struct pf_security_diag_s {
135typedef struct pf_trace_entry_s {
153typedef struct pf_report_s {
256 const char* input_tf,
257 const char* script_tf,
259 int magnifier_samples,
331typedef struct pf_version_s {
void strategy_set_override(pf_strategy_t s, const char *key, const char *value)
Override a strategy(...) declaration parameter.
void strategy_set_input(pf_strategy_t s, const char *key, const char *value)
Override a Pine input.
void strategy_set_magnifier_volume_weighted(pf_strategy_t s, int on)
Toggle volume-weighted bar-magnifier sampling.
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_trace_enabled(pf_strategy_t s, int on)
Toggle per-bar trace recording.
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 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_distribution_t
Bar-magnifier sub-bar sampling distribution.
@ PF_MAGNIFIER_FRONT_LOADED
Sample density biased toward bar open.
@ PF_MAGNIFIER_COSINE
Cosine-tapered density.
@ PF_MAGNIFIER_ENDPOINTS
Default — exact O,H,L,C points plus uniform fill between.
@ PF_MAGNIFIER_BACK_LOADED
Sample density biased toward bar close.
@ PF_MAGNIFIER_TRIANGLE
Triangle-tapered density.
@ PF_MAGNIFIER_UNIFORM
Uniform spacing across the parent bar.
pf_version_t pf_version_get(void)
const char * pf_version_string(void)
Full git-derived version descriptor.
void * pf_strategy_t
Opaque handle to a compiled strategy instance.
Single OHLCV bar pushed into the engine.
int64_t timestamp
Bar open time, Unix milliseconds.
Backtest report filled by run_backtest / run_backtest_full.
int input_tf_seconds
Detected/configured input timeframe (seconds).
int security_diag_len
Length of security_diag.
int64_t security_feeds_total
Total higher-TF feed bars across all security sites.
int bar_magnifier_enabled
1 if magnifier was active for this run.
pf_trace_entry_t * trace
Per-bar trace records (empty unless tracing enabled).
int trace_names_len
Length of trace_names.
int64_t input_bars_processed
Source-feed bars consumed.
int script_tf_seconds
Script timeframe (seconds).
double net_profit
Sum of all closed-trade PnL.
int trades_len
Length of trades.
int trace_len
Length of trace.
int64_t script_bars_processed
Script-timeframe bars evaluated.
int64_t magnifier_sample_ticks_total
Sample ticks visited by the magnifier.
int total_trades
Closed-trade count (== trades_len).
int64_t security_partial_total
Total partial-bar evals across all security sites.
pf_security_diag_t * security_diag
One entry per request.security site.
int64_t magnifier_sub_bars_total
Sub-bars synthesized by the magnifier.
const char ** trace_names
Names indexed by pf_trace_entry_t::name_id.
int64_t security_complete_total
Total complete-bar evals across all security sites.
int script_tf_ratio
script_tf_seconds / input_tf_seconds.
int needs_aggregation
1 if input → script TF aggregation was performed.
pf_trade_t * trades
Heap array of closed trades.
Per-request.security() site diagnostic counters.
int sec_id
Stable id for the request.security site.
int64_t feed_count
Higher-TF feed bars consumed.
int64_t complete_count
Evaluations on completed parent bars.
int64_t partial_count
Evaluations on still-forming parent bars.
Single per-bar trace entry.
double value
Traced expression value on this bar.
int64_t timestamp
Bar timestamp (Unix ms).
int32_t name_id
Index into pf_report_t::trace_names.
int32_t bar_index
Zero-based bar index.
Closed-trade record returned in pf_report_t::trades.
double pnl_pct
Net realized PnL as a percentage of entry capital.
double exit_price
Exit fill price (incl.
double pnl
Net realized PnL in account currency.
int is_long
1 if long, 0 if short.
double max_drawdown
Peak adverse price travel during the trade ($/unit qty).
double qty
Filled quantity.
double max_runup
Peak favorable price travel during the trade ($/unit qty).
int64_t entry_time
Entry fill time (Unix ms).
double entry_price
Entry fill price (incl.
int64_t exit_time
Exit fill time (Unix ms).
Runtime version descriptor returned by pf_version_get.
const char * commit_sha
Short git commit SHA, or "" if unknown.