51#if defined(__cplusplus)
52#define PF_STATIC_ASSERT(condition) static_assert((condition), #condition)
53#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
54#define PF_STATIC_ASSERT(condition) _Static_assert((condition), #condition)
56#define PF_STATIC_ASSERT_JOIN_(a, b) a##b
57#define PF_STATIC_ASSERT_JOIN(a, b) PF_STATIC_ASSERT_JOIN_(a, b)
58#define PF_STATIC_ASSERT(condition) \
59 typedef char PF_STATIC_ASSERT_JOIN(pf_static_assertion_, __LINE__)[(condition) ? 1 : -1]
65#include <pineforge/version.h>
74#if defined(_WIN32) || defined(__CYGWIN__)
75 #if defined(PINEFORGE_BUILD_SHARED)
76 #define PF_API __declspec(dllexport)
78 #define PF_API __declspec(dllimport)
80#elif defined(__GNUC__) || defined(__clang__)
81 #define PF_API __attribute__((visibility("default")))
99#define PF_ABI_VERSION 5
103#define PINEFORGE_HAS_AUX_SECURITY_FEED_V1 1
107#define PINEFORGE_HAS_NATIVE_SECURITY_FEED_V1 1
111#define PINEFORGE_HAS_NATIVE_FX_CURVE_V1 1
128typedef enum pf_magnifier_distribution_e {
140typedef struct pf_bar_s {
156typedef struct pf_trade_tick_s {
166typedef struct pf_trade_s {
209typedef struct pf_trade_stats_s {
272typedef struct pf_equity_stats_s {
317typedef struct pf_metrics_s {
326typedef struct pf_equity_point_s {
335typedef struct pf_security_diag_s {
347typedef struct pf_trace_entry_s {
366typedef struct pf_report_s {
456typedef enum pf_execution_contract_e {
469typedef enum pf_native_spec_optional_e {
529typedef enum pf_native_fx_curve_error_e {
575#ifndef PINEFORGE_NO_STRATEGY_DECLS
618 const char* input_tf,
619 const char* script_tf,
621 int magnifier_samples,
712 uint64_t* arena_bytes);
727 uint64_t* allocation_bypass_count);
820 const char* input_tf,
821 const char* script_tf);
831typedef struct pf_stream_order_action {
911#define PINEFORGE_HAS_SCRATCH_TABLES_V1 1
913#define PINEFORGE_HAS_CACHE_POLICY_V1 1
921#define PF_CACHE_KIND_LEDGER_CACHE 1u
922#define PF_CACHE_KIND_TRADE_PAGES 2u
923#define PF_CACHE_KIND_DEPENDENCY_PAGES 3u
924#define PF_CACHE_KIND_EXIT_PAGES 4u
925#define PF_CACHE_KIND_BOOK_PAGES 5u
926#define PF_CACHE_KIND_RETAINED_SEQUENCE_PAGES 6u
927#define PF_CACHE_KIND_COHORT_ID_PAGES 7u
928#define PF_CACHE_KIND_EXIT_RANK_PAGES 8u
929#define PF_CACHE_KIND_ERASED_MINIMA_PAGES 9u
930#define PF_CACHE_KIND_CONSUMED_CYCLE_PAGES 10u
931#define PF_CACHE_KIND_POSITION_TAIL_PAGES 11u
932#define PF_CACHE_KIND_SUCCESSOR_ROOT_PAGES 12u
933#define PF_CACHE_KIND_RECEIPT_TAIL_PAGES 13u
934#define PF_CACHE_KIND_CHAIN_SEGMENT_PAGES 14u
935#define PF_CACHE_KIND_EQUITY_CURVE_PAGES 15u
936#define PF_CACHE_KIND_TA_HISTORY_PAGES 16u
937#define PF_CACHE_KIND_FEED_CALENDAR_PAGES 17u
938#define PF_CACHE_KIND_RECORDED_SERIES_PAGES 18u
939#define PF_CACHE_KIND_PROJECTION_EXIT_PAGES 19u
1001typedef enum pf_scratch_table_backend_e {
1258#define PF_STATE_QUERY_ALLOWED_V1 0
1259#define PF_STATE_QUERY_SELECTED_WINDOW_AFTER_SEAL_V1 1
1260#define PF_STATE_QUERY_INVALID_HANDLE_V1 2
1329typedef enum pf_fill_qty_partition_e {
1399 double* qty,
int* close_only,
int* partition);
1425 double* limit,
double* trail_activation);
1468typedef enum pf_close_cause_e {
1661 const double* account_per_quote,
int n);
1663#ifdef PINEFORGE_HAS_AUX_SECURITY_FEED_V1
1679 const char* input_tf);
1682#ifdef PINEFORGE_HAS_NATIVE_SECURITY_FEED_V1
1707 const char* timeframe,
1722#define PINEFORGE_HAS_SYMBOL_FEED_V1 1
1724#define PINEFORGE_HAS_SYMBOL_FEED_COLUMN_V1 1
1726#define PINEFORGE_HAS_SYMBOL_FACTS_V1 1
1728#define PINEFORGE_HAS_RECORDED_SERIES_V1 1
1730#ifdef PINEFORGE_HAS_SYMBOL_FEED_V1
1750 const pf_bar_t* bars,
const int64_t* close_ms,
int n);
1753#ifdef PINEFORGE_HAS_SYMBOL_FEED_COLUMN_V1
1764 const char* timeframe,
const char* name,
1765 const double* values,
int n);
1768#ifdef PINEFORGE_HAS_SYMBOL_FACTS_V1
1785#ifdef PINEFORGE_HAS_RECORDED_SERIES_V1
1796 const int64_t* chart_open_ms,
const double* values,
1821#define PINEFORGE_HAS_RUN_FAILURE_CODES_V1 1
1855typedef struct pf_version_s {
1886#define PF_SETTINGS_API_VERSION 1u
1889#define PF_CAPABILITIES_API_VERSION 1u
1903#ifndef PINEFORGE_NO_STRATEGY_DECLS
1924 size_t capacity,
size_t* required,
1925 char* error,
size_t error_capacity);
1935 char* error,
size_t error_capacity);
1945 const char* value,
char* error,
1946 size_t error_capacity);
1952 const char* value,
char* error,
1953 size_t error_capacity);
1964 size_t capacity,
size_t* required,
1965 char* error,
size_t error_capacity);
1974 const char* input_tf,
const char* script_tf,
1975 int bar_magnifier,
int magnifier_samples,
1978 size_t error_capacity);
2005#define PINEFORGE_HAS_OUTPUTS_V1 1
2007#define PF_OUTPUTS_API_VERSION 1u
2010typedef enum pf_output_phase_e {
2020typedef struct pf_output_event_v1_s {
2063 int64_t* open_ms, int64_t* close_ms,
2064 int64_t capacity, int64_t* written);
2069 double* out, int64_t capacity, int64_t* written);
2087#ifndef PINEFORGE_NO_STRATEGY_DECLS
2094 size_t* required,
char* error,
2095 size_t error_capacity);
2100 size_t* required,
char* error,
2101 size_t error_capacity);
2107#define PINEFORGE_HAS_SYMBOL_FEED_BORROWED_V1 1
2114 const pf_bar_t* bars,
const int64_t* close_ms,
int n);
2118#define PF_STREAM_ENGINE_LAYOUT_VERSION 2u
2141 char* error,
size_t error_capacity);
2163#define PINEFORGE_HAS_REPORT_SINK_V1 1
const char * strategy_get_last_error_args(pf_strategy_t s)
The typed arguments of the failure strategy_get_last_error_code names, as one canonical JSON object: ...
void strategy_set_syminfo_timezone(pf_strategy_t s, const char *tz)
Plumb the symbol's exchange timezone (IANA string) into syminfo.
const char * strategy_get_last_error_code(pf_strategy_t s)
Stable code of the most recent failure on s: lower snake_case ASCII matching ^[a-z][a-z0-9_]{2,...
void strategy_set_syminfo_mintick(pf_strategy_t s, double mintick)
Set the instrument tick size (syminfo.mintick, default 0.01).
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.
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 s...
int strategy_set_native_security_feed(pf_strategy_t s, const char *timeframe, const pf_bar_t *bars, int n)
Copy the exchange's OWN bars of one higher timeframe for same-symbol request.security calls that requ...
void strategy_set_syminfo_session(pf_strategy_t s, const char *session)
Set the symbol's session string (e.g.
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 multi...
void strategy_set_chart_timezone(pf_strategy_t s, const char *tz)
Set the strategy's chart timezone (IANA / POSIX TZ string).
int strategy_set_symbol_feed_column(pf_strategy_t s, const char *key, const char *timeframe, const char *name, const double *values, int n)
Copy one named column of an installed symbol feed: n values, one per bar of the feed of (key,...
int strategy_set_symbol_facts(pf_strategy_t s, const char *key, const char *field, const char *value)
Set one fact of the symbol a request site names by key: field is one of "canonical",...
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.
void strategy_set_magnifier_volume_weighted(pf_strategy_t s, int on)
Toggle volume-weighted bar-magnifier sampling.
int strategy_set_recorded_series(pf_strategy_t s, const char *key, const int64_t *chart_open_ms, const double *values, int n)
Copy a recorded request series: the values a request returned on the chart bars that opened at chart_...
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.
int strategy_set_symbol_feed(pf_strategy_t s, const char *key, const char *timeframe, const pf_bar_t *bars, const int64_t *close_ms, int n)
Copy another symbol's own bars of one timeframe, keyed by the exact symbol string a request site pass...
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.
void strategy_set_trace_enabled(pf_strategy_t s, int on)
Toggle per-bar trace recording.
int strategy_set_syminfo_string(pf_strategy_t s, const char *key, const char *value)
Set one of the remaining string members of syminfo by Pine member name: "ticker", "tickerid",...
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.
void strategy_set_syminfo_type(pf_strategy_t s, const char *type)
Set the instrument class (syminfo.type: "forex", "stock", "crypto", "futures", "index",...
int strategy_declares_bar_magnifier(void)
Report the script's strategy(..., use_bar_magnifier = true) declaration.
int pf_run_abort_requested_v1(void)
Read the invocation stop flag: 0 or 1.
int strategy_execution_contract(pf_strategy_t s)
Native execution contract query: a pf_execution_contract_t, or -1 for a NULL handle.
uint64_t strategy_closed_trade_entry_incarnation(pf_strategy_t s, int trade_index)
Return the physical entry incarnation for one closed-trade row.
int strategy_configure_native_fx_curve_v1(pf_strategy_t s, const pf_native_fx_curve_v1 *curve)
Stage an immutable account-currency FX curve on a Ready native handle.
pf_execution_contract_t
What strategy_execution_contract answers for a valid handle.
pf_strategy_t strategy_create(const char *params_json)
Allocate a new strategy instance.
int strategy_require_report_scratch_arena_v1(pf_strategy_t s)
Admit a jailed handle only with an attached scratch arena.
pf_native_fx_curve_error_t
Why a native FX curve was refused — the C twin of pineforge::NativeFxCurveError.
int strategy_configure_native_fx_curve_ext_v1(pf_strategy_t s, const pf_native_fx_curve_v1 *curve, pf_native_fx_curve_error_t *error, uint64_t *index)
Typed additive spelling of strategy_configure_native_fx_curve_v1.
int pf_run_abort_install_sigterm_v1(void)
Install the invocation's cooperative SIGTERM handler.
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.
int strategy_report_sink_diagnostics_v1(pf_strategy_t s, struct pf_report_sink_diagnostics_v1 *out)
Read bounded sink provenance without reading the sink or replaying rows.
int pf_report_scratch_arena_stats(uint64_t *high_water_bytes, uint64_t *arena_bytes)
Read process-wide scratch-arena diagnostics, outside canonical report bytes.
void report_free(pf_report_t *report)
Free heap arrays attached to a filled report.
int strategy_configure_native_v1(pf_strategy_t s, const pf_native_run_spec_v1 *spec)
Apply a native v1 specification.
int pf_report_cache_stats(pf_strategy_t s, uint64_t *resident_bytes, uint64_t *allocation_bypass_count)
Read the handle's admitted-run command-cache and trade-ledger diagnostics.
pf_native_spec_optional_t
The bits of pf_native_run_spec_v1::optional_mask: each names the one optional field it makes meaningf...
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.
int pf_run_abort_restore_sigterm_v1(void)
Restore the disposition saved by pf_run_abort_install_sigterm_v1.
@ PF_EXECUTION_CONTRACT_LEGACY
The retired legacy execution path.
@ PF_EXECUTION_CONTRACT_NATIVE_MARKET_V1
The native market kernel; every handle this runtime creates.
@ PF_NATIVE_FX_CURVE_ERROR_NOT_FINITE_POSITIVE
@ PF_NATIVE_FX_CURVE_ERROR_NOT_STRICTLY_INCREASING
@ PF_NATIVE_FX_CURVE_ERROR_ALLOCATION_FAILURE
@ PF_NATIVE_FX_CURVE_ERROR_LENGTH_MISMATCH
@ PF_NATIVE_FX_CURVE_ERROR_WRONG_PHASE
@ PF_NATIVE_FX_CURVE_ERROR_NONE
@ PF_NATIVE_SPEC_OPTIONAL_MAX_ABS_UNITS
max_abs_units.
@ PF_NATIVE_SPEC_OPTIONAL_MAX_OPEN_LOTS
max_open_lots.
@ PF_NATIVE_SPEC_OPTIONAL_INITIAL_MARGIN_FRACTION
initial_margin_fraction.
@ PF_NATIVE_SPEC_OPTIONAL_QUANTITY_GRID
quantity_grid.
double strategy_net_profit_sum(pf_strategy_t s)
Raw whole-lot realized P&L, excluding initial capital and report-only terminal rows.
double strategy_current_equity(pf_strategy_t s)
Task 9: initial capital plus realized net profit (strategy.initial_capital + strategy....
pf_scratch_table_backend_t
Storage policy for the nine historical scratch-table regions.
void strategy_set_probe_suppress_tail_logic(pf_strategy_t s, int on)
Live probe tail suppression (spec §3.2): the LAST script bar of the array fed to every subsequent run...
const char * strategy_closed_trade_exit_id(pf_strategy_t s, int trade_index)
See strategy_closed_trade_entry_id for the row-space/lifetime/NULL contract.
pf_state_query_status_v1_t strategy_state_query_status_v1(pf_strategy_t s)
The current eligibility of BOTH strategy_broker_state_hash and strategy_stream_state_hash on s,...
void strategy_set_path_order(pf_strategy_t s, int mode)
Force this run's intrabar path order (ABI v4 live-runtime surface): the leg order every modeled OHLC ...
int64_t strategy_script_bars_processed(pf_strategy_t s)
Task 9: total SCRIPT bars dispatched by the most recent run() (mirrors pf_report_t::script_bars_proce...
void strategy_request_abort(pf_strategy_t s)
Request cooperative abort of the run in progress (see c_abi.cpp).
int strategy_closed_trade_close_cause(pf_strategy_t s, int trade_index)
Task 9: why the trade_index-th REPORT-row closed trade exited, a pf_close_cause_t.
uint32_t pf_cache_kind_t
Append-only cache-kind vocabulary.
int32_t pf_state_query_status_v1_t
What strategy_state_query_status_v1 answers: whether the two state queries, strategy_broker_state_has...
int strategy_set_scratch_tables_v1(pf_strategy_t s, const pf_scratch_tables_v1 *config)
Copy scratch-table configuration while idle; NULL restores disk defaults.
double strategy_position_avg_price(pf_strategy_t s)
The live position's volume-weighted average entry price (position_entry_price_).
const char * strategy_closed_trade_entry_id(pf_strategy_t s, int trade_index)
Task 9: closed-trade id / exit-comment string accessors, indexing the same REPORT row space as strate...
const char * strategy_closed_trade_exit_comment(pf_strategy_t s, int trade_index)
See strategy_closed_trade_entry_id.
int strategy_pending_orders_len(pf_strategy_t s)
Number of orders resting in the engine's pending-order book after the most recent run() (ABI v4 live-...
int64_t strategy_position_cycle_seq(pf_strategy_t s)
The live position's cycle id (position_cycle_seq_): 0 when flat, a fresh nonzero id per open or rever...
int strategy_pending_order_effective_levels(pf_strategy_t s, int index, double *stop, double *limit, double *trail_activation)
The price levels the index-th resting order would fire at, as the engine's fill path resolves them (A...
int strategy_pending_order_level_resolved(pf_strategy_t s, int index)
1 when the index-th resting order's entry-relative offsets (profit_ticks / loss_ticks / trail_points)...
pf_fill_qty_partition_t
Which sizing rule strategy_pending_order_fill_qty's quantity came from, written to its partition out-...
int strategy_pending_order_fill_qty(pf_strategy_t s, int index, double fill_price, double *qty, int *close_only, int *partition)
Engine-computed fill quantity of the index-th resting order (ABI v4 live-runtime surface,...
int strategy_last_bar_dual_entry_path(pf_strategy_t s)
The dual-entry-stop arbitration decided on the LAST bar the most recent run() dispatched: a flat posi...
double strategy_position_size(pf_strategy_t s)
Task 9: the script-facing signed position size (strategy.position_size; Freeze-aware – while a same-b...
int strategy_pending_order_get(pf_strategy_t s, int index, void *out, size_t size_in)
Copy the index-th resting order (0-based, the engine's own book order – insertion order; broker fill ...
double strategy_report_pointvalue(pf_strategy_t s)
Effective symbol pointvalue used by the engine report.
int strategy_set_report_replay_v1(pf_strategy_t s, const char *path, const char *run_id)
Opt in to the separate pf-report-replay/v1 companion before a run.
const pf_field_desc_t * strategy_pending_order_layout(int *count)
The field table of pf_pending_order_v1_t as THIS runtime compiled it – one pf_field_desc_t {name,...
int strategy_set_cache_policy_v1(pf_strategy_t s, const pf_cache_policy_v1 *policy)
Copy cache settings before run admission; NULL restores internal defaults.
int strategy_last_run_status(pf_strategy_t s)
0 = completed, 1 = NOT_COMPLETED (aborted), -1 = s is NULL.
double strategy_trail_best_price(pf_strategy_t s)
The trail extreme the exit trail legs ride (trail_best_price_: the running high of a long / low of a ...
pf_close_cause_t
Why a closed report row exited — execution::CloseCause, the value strategy_closed_trade_close_cause a...
double strategy_initial_capital(pf_strategy_t s)
ABI v4 live-runtime surface (1.8.0): the configured run's initial capital, before realized or open pr...
void strategy_set_broker_state_hash_recording(pf_strategy_t s, int on)
Toggle per-report-point broker-state hash recording (spec §3.4, ABI v4).
uint64_t strategy_broker_state_hash(pf_strategy_t s)
Return the broker-state hash of the FINAL state after the most recent run() (see strategy_set_broker_...
void strategy_set_realtime_tail(pf_strategy_t s, int on, int horizon_bars)
Live-runtime tail semantics (spec §3.1): the LAST bar of the array fed to every subsequent run() is a...
@ PF_SCRATCH_TABLE_BOUNDED_MEMORY
@ PF_SCRATCH_TABLE_DISK_SCRATCH
@ PF_FILL_QTY_PARTITION_EXIT
An exit: no partition.
@ PF_FILL_QTY_PARTITION_DEFAULT_STOP_PLACEMENT
@ PF_FILL_QTY_PARTITION_EXPLICIT
@ PF_FILL_QTY_PARTITION_FROZEN_PLACEMENT
@ PF_FILL_QTY_PARTITION_AT_FILL
@ PF_CLOSE_CAUSE_LIQUIDATION
A margin-call liquidation slice (MARGIN_CALL).
@ PF_CLOSE_CAUSE_RANGE_END
The range-end close of a position still open.
@ PF_CLOSE_CAUSE_SCRIPT
A market close or a reversal.
@ PF_CLOSE_CAUSE_RISK_LIMIT
A risk-limit flatten (INTRADAY_LOSS_CAP).
@ PF_CLOSE_CAUSE_BRACKET
A bracket leg.
@ PF_CLOSE_CAUSE_UNSPECIFIED
No cause recorded (UNKNOWN).
@ PF_CLOSE_CAUSE_FILL_CAP
A filled-order cap (INTRADAY_FILL_CAP).
int strategy_outputs_set_enabled(pf_strategy_t s, int on)
Turn recording on (on nonzero) or off.
int strategy_outputs_manifest(pf_strategy_t s, char *json, size_t capacity, size_t *required, char *error, size_t error_capacity)
Part A: the module's outputs manifest, canonical JSON (pineforge-outputs-manifest/v1): what every out...
int64_t strategy_outputs_bars_len(pf_strategy_t s)
Rows recorded: one per bar the module published this run.
void strategy_outputs_events_clear(pf_strategy_t s)
Drop the queued events, in every mode; rows and the sequence are kept.
pf_output_phase_t
The run phase an event was recorded in.
int strategy_outputs_series_count(pf_strategy_t s)
Series slots per row; 0 while recording is off.
int strategy_outputs_bar_times_copy(pf_strategy_t s, int64_t from_bar, int64_t *open_ms, int64_t *close_ms, int64_t capacity, int64_t *written)
Copy the open and close times (Unix ms) of rows from from_bar on.
int strategy_signal_safety_receipt(pf_strategy_t s, char *json, size_t capacity, size_t *required, char *error, size_t error_capacity)
Part A: the module's signal-safety receipt, canonical JSON (pineforge-signal-safety/v1),...
int strategy_outputs_series_copy(pf_strategy_t s, int series, int64_t from_bar, double *out, int64_t capacity, int64_t *written)
Copy one slot's values (NaN = na) of rows from from_bar on, as strategy_outputs_bar_times_copy does; ...
uint32_t strategy_outputs_api_version(void)
Part A: PF_OUTPUTS_API_VERSION.
int strategy_outputs_constants_copy(pf_strategy_t s, double *out, int capacity)
Copy the run constants (NaN = na, or not written this run) into out: the first min(capacity,...
int strategy_outputs_events_len(pf_strategy_t s)
Events queued since the run began or since the last clear.
int strategy_outputs_event_get(pf_strategy_t s, int index, void *out, size_t size_in)
Copy event index into out: min(size_in, sizeof(pf_output_event_v1_t)) bytes, so an older or newer cal...
@ PF_OUTPUT_PHASE_REALTIME
a stream after its warm-up
@ PF_OUTPUT_PHASE_BATCH
a batch run
@ PF_OUTPUT_PHASE_WARMUP
a stream's warm-up, inside strategy_stream_begin
pf_settings_status_t
Status codes for the opt-in generated-strategy settings extension.
@ PF_SETTINGS_UNSUPPORTED
@ PF_SETTINGS_BUFFER_TOO_SMALL
@ PF_SETTINGS_INVALID_ARGUMENT
int strategy_stream_begin(pf_strategy_t s, const pf_bar_t *warmup_bars, int n_warmup, const char *input_tf, const char *script_tf)
Warm a strategy with confirmed OHLCV, then switch the same instance to a realtime trade stream withou...
int strategy_stream_push_tick(pf_strategy_t s, const pf_trade_tick_t *tick)
Push one normalized realtime trade.
int strategy_stream_order_actions_len(pf_strategy_t s)
Queued physical fills since the last clear, in execution order.
int strategy_stream_push_ticks(pf_strategy_t s, const pf_trade_tick_t *ticks, int n)
Push an ordered batch of realtime trades.
uint64_t strategy_stream_state_hash(pf_strategy_t s)
Versioned deterministic fingerprint of observable broker/stream state.
int strategy_stream_api_version(void)
Native live extension version (1).
int strategy_stream_advance_time(pf_strategy_t s, int64_t timestamp_ms)
Advance the stream clock and close every input bar whose end is <= the supplied time.
int strategy_stream_push_bar(pf_strategy_t s, const pf_bar_t *bar)
Consume one confirmed input-timeframe bar.
int strategy_stream_end(pf_strategy_t s, int finalize_partial_input_bar)
End a realtime stream.
int strategy_stream_fill_report(pf_strategy_t s, pf_report_t *out)
Snapshot the cumulative warmup + realtime report.
int strategy_stream_order_action_get(pf_strategy_t s, int index, pf_stream_order_action_t *out)
Copy one action; return 0 on success, -1 on invalid handle/index/output.
void strategy_stream_order_actions_clear(pf_strategy_t s)
Clear observed events after the caller durably journals them.
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 version descriptor, the PINEFORGE_VERSION_FULL of the generated pineforge/version....
void * pf_strategy_t
Opaque handle to a compiled strategy instance.
int pf_output_series_limit_set_checked(const int64_t *maximum, char *error, size_t error_capacity)
Set this module's creation-time recorded-series limit on the calling thread.
int strategy_set_input_checked(pf_strategy_t s, const char *key, const char *value, char *error, size_t error_capacity)
Validate and install a declared input before execution.
int run_backtest_full_checked(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, char *error, size_t error_capacity)
Exception-contained counterpart of run_backtest_full.
int strategy_get_effective_settings(pf_strategy_t s, char *json, size_t capacity, size_t *required, char *error, size_t error_capacity)
Read a deterministic UTF-8 JSON receipt of effective settings.
uint32_t strategy_capabilities_api_version(void)
Compiled execution-capabilities extension version (currently 1).
int strategy_create_checked(const char *params_json, pf_strategy_t *out, char *error, size_t error_capacity)
Allocate a strategy without allowing any exception across the C boundary.
int strategy_set_symbol_feed_borrowed_v1(pf_strategy_t s, const char *key, const char *timeframe, const pf_bar_t *bars, const int64_t *close_ms, int n)
Install another symbol's bars without copying them.
#define PF_STATIC_ASSERT(condition)
uint32_t strategy_stream_engine_layout_version(void)
Optional module declaration that its strategy handles point directly to a BacktestEngine with the ret...
int strategy_capabilities_receipt(pf_strategy_t s, char *json, size_t capacity, size_t *required, char *error, size_t error_capacity)
Read immutable canonical JSON describing compiled execution declarations and analyzed request/data re...
uint32_t strategy_settings_api_version(void)
Generated-strategy settings extension version (currently 1).
int strategy_set_override_checked(pf_strategy_t s, const char *key, const char *value, char *error, size_t error_capacity)
Validate and install a supported strategy override before execution.
int pf_output_series_limit_failure(int64_t *maximum)
Read an outputs_limit / too_many_series declaration refusal even when a factory returned NULL.
Single OHLCV bar pushed into the engine.
int64_t timestamp
Bar open time, Unix milliseconds.
One optional resident cache size.
Versioned resident cache policy.
const pf_cache_policy_entry_v1 * entries
Single per-script-bar equity point.
double open_profit
Mark-to-market open P&L at bar close.
double equity
initial_capital + net_profit + open_profit.
int64_t time_ms
Script-bar OPEN timestamp (Unix ms).
Equity-curve-derived statistics (all-trades only, like TV).
double sharpe_monthly
Month-end-resampled equity simple returns (chart timezone, open-time bucketing), risk-free 2%/yr (2/1...
double time_in_market_pct
PERCENT (0-100) of script bars with an open position at bar close.
double max_equity_drawdown_pct
max_equity_drawdown relative to the peak in effect (PERCENT 0-100).
double max_equity_drawdown
Peak-to-trough equity drop, positive currency magnitude.
double max_equity_runup_pct
max_equity_runup relative to that trough (PERCENT 0-100).
double buy_hold_return
initial_capital * (last_close/first_open - 1), currency.
double open_pl
Mark-to-market open profit at the final bar.
double max_equity_runup
Trough-to-peak rise where the trough resets on each new equity peak (mirrors the engine's intra-run e...
double cagr
PERCENT per year: 100*((final_equity/initial_capital)^(1/years)-1).
double recovery_factor
net_profit / max_equity_drawdown (currency / currency).
double calmar
cagr / max_equity_drawdown_pct — BOTH IN PERCENT, so the ratio is dimensionless.
double buy_hold_return_pct
buy_hold_return as PERCENT.
double sharpe_bar
Per-script-bar returns, annualized by observed bar density (bars per year = (len-1)/calendar span),...
double sortino_monthly
Same resampling as sharpe_monthly; uses population downside deviation vs the monthly risk-free.
double sortino_bar
Same construction as sharpe_bar over per-bar returns; uses population downside deviation.
Composite metrics container: trade stats (all / long / short) + equity-curve stats.
Immutable timestamped account-currency FX curve for a native run.
const int64_t * effective_from_ms
const double * account_per_quote
Versioned native run specification.
uint32_t allowed_open_directions
const char * basecurrency
double initial_margin_fraction
const char * chart_timezone
One recorded event, copied by strategy_outputs_event_get.
int64_t bar_close_ms
the row's close, Unix ms; INT64_MIN when unknown
uint32_t ordinal_in_bar
per output, from 0 within the row
double value
the event's value; NaN = na
uint32_t size
sizeof(pf_output_event_v1_t) as the runtime compiled it
int32_t bar_index
the row, 0-based
uint64_t sequence
1-based per run; once cleared, never issued again
const char * message
NUL-terminated, or NULL without one: a message holding a NUL byte reads to its first NUL,...
int64_t bar_open_ms
the row's open, Unix ms
uint32_t phase
a pf_output_phase_t
int32_t output_index
the output, as the manifest's outputs[].index
uint32_t confirmed
0 when recorded on a partially finalized bar
uint64_t message_hash64
FNV-1a 64 of every byte the module recorded as the message; 0 without one.
Fixed-size annualization provenance from the emitted v1 records.
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
Resident length of trades, not the logical total.
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
Logical closed-trade count, including the range-end close of a position still open after the final ba...
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.
int64_t broker_state_hash_len
uint64_t * broker_state_hash
const char ** trace_names
Names indexed by pf_trace_entry_t::name_id.
pf_equity_point_t * equity_curve
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; script-driven exits first, then the range-end rows (open_at_end=1).
Version 1 scratch-table admission maxima, in keys/rows and key bytes.
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.
One physical emulator lot action.
uint64_t entry_incarnation
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.
Trade-level statistics block — computed once each for all / long / short.
double avg_win_pct
Mean of per-trade pnl_pct over winning trades.
double avg_win
gross_profit / num_wins.
double net_profit_pct
net_profit as a percent of initial capital (0-100 scale).
double largest_loss_pct
Maximum of -pnl_pct over losing trades (positive magnitude) — an INDEPENDENT maximum,...
int32_t num_losses
Trades with pnl < 0.
double gross_profit
Sum of winning pnl.
int32_t max_consecutive_losses
Longest losing run; even trades reset both streaks.
double avg_loss_pct
Mean of the NEGATED pnl_pct of the losing trades.
double commission_paid
Sum of pf_trade_t::commission in the block.
double percent_profitable
100 * num_wins / num_trades, in PERCENT (0-100).
double largest_win_pct
Maximum pnl_pct over winning trades — an INDEPENDENT maximum, not the pct of the largest-USD win (TV ...
double gross_loss
Sum of |losing pnl| — POSITIVE magnitude (TV display convention).
double gross_profit_pct
gross_profit as a percent of initial capital (0-100 scale).
double largest_loss
Single largest |pnl| among losing trades (positive magnitude).
double avg_bars_in_wins
Mean bar duration of winning trades, inclusive of the entry bar (TV convention, validated 2026-06-12)...
double avg_bars_in_losses
Mean bar duration of losing trades, inclusive of the entry bar (TV convention, validated 2026-06-12).
double profit_factor
gross_profit / gross_loss.
double avg_loss
gross_loss / num_losses (positive magnitude).
double largest_win
Single largest pnl among winning trades.
double avg_bars_in_trade
Mean of (exit_bar_index - entry_bar_index + 1) in SCRIPT bars, over all trades — inclusive of the ent...
double gross_loss_pct
gross_loss as a percent of initial capital (0-100 scale).
int32_t max_consecutive_wins
Longest winning run; even trades reset both streaks.
double expectancy
(num_wins/num_trades)*avg_win - (num_losses/num_trades)*avg_loss, account currency per trade.
double net_profit
Sum of pnl (account currency, net of commission).
int32_t num_trades
Closed trades in this block (all / long-only / short-only).
double avg_trade_pct
Mean of per-trade pnl_pct over all trades.
double ratio_avg_win_avg_loss
avg_win / avg_loss.
double avg_trade
net_profit / num_trades.
int32_t num_even
Trades with pnl == 0.0 exactly; breaks both win and loss streaks; excluded from win/loss averages.
int32_t num_wins
Trades with pnl > 0.
Closed-trade record returned in pf_report_t::trades.
int32_t exit_bar_index
Script-bar index of the exit fill (0-based).
double pnl_pct
Net return-on-cost in percent: pnl (NET of commission) / entry cost (entry_price * qty * pointvalue) ...
double exit_price
Exit fill price (incl.
int32_t open_at_end
1 when this row is the RANGE-END close of a position that was still open after the final bar; 0 for a...
int32_t entry_bar_index
Script-bar index of the entry fill (0-based).
double commission
Entry+exit commission actually deducted from pnl (account currency).
double pnl
Net realized PnL in account currency (commission-inclusive).
int is_long
1 if long, 0 if short.
double max_drawdown
Peak adverse whole-trade excursion, account currency, net of entry fees.
double qty
Filled quantity.
double max_runup
Peak favorable whole-trade excursion, account currency, net of entry fees.
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).
One provider-neutral realtime executed-trade update.
double quantity
Traded quantity in symbol volume units (>= 0).
uint64_t sequence
Normalized per-stream sequence, or 0.
int64_t timestamp
Source event time, Unix milliseconds.
double price
Executed trade price (> 0).
Runtime version descriptor returned by pf_version_get.
const char * commit_sha
Short git commit SHA, or "" if unknown.