|
PineForge v0.10.1-13-gd771a78
Deterministic PineScript v6 backtest runtime — C ABI reference
|
Trade-level statistics block — computed once each for all / long / short. More...
#include <pineforge.h>
Data Fields | |
| int32_t | num_trades |
| Closed trades in this block (all / long-only / short-only). | |
| int32_t | num_wins |
| Trades with pnl > 0. | |
| int32_t | num_losses |
| Trades with pnl < 0. | |
| int32_t | num_even |
| Trades with pnl == 0.0 exactly; breaks both win and loss streaks; excluded from win/loss averages. | |
| double | percent_profitable |
| 100 * num_wins / num_trades, in PERCENT (0-100). | |
| double | net_profit |
| Sum of pnl (account currency, net of commission). | |
| double | net_profit_pct |
| net_profit as a percent of initial capital (0-100 scale). | |
| double | gross_profit |
| Sum of winning pnl. | |
| double | gross_profit_pct |
| gross_profit as a percent of initial capital (0-100 scale). | |
| double | gross_loss |
| Sum of |losing pnl| — POSITIVE magnitude (TV display convention). | |
| double | gross_loss_pct |
| gross_loss as a percent of initial capital (0-100 scale). | |
| double | profit_factor |
| gross_profit / gross_loss. | |
| double | avg_trade |
| net_profit / num_trades. | |
| double | avg_trade_pct |
| Mean of per-trade pnl_pct over all trades. | |
| double | avg_win |
| gross_profit / num_wins. | |
| double | avg_win_pct |
| Mean of per-trade pnl_pct over winning trades. | |
| double | avg_loss |
| gross_loss / num_losses (positive magnitude). | |
| double | avg_loss_pct |
| Mean of the NEGATED pnl_pct of the losing trades. | |
| double | ratio_avg_win_avg_loss |
| avg_win / avg_loss. | |
| double | largest_win |
| Single largest pnl among winning trades. | |
| double | largest_win_pct |
| Maximum pnl_pct over winning trades — an INDEPENDENT maximum, not the pct of the largest-USD win (TV convention, validated 2026-06-12 vs TV export). | |
| double | largest_loss |
| Single largest |pnl| among losing trades (positive magnitude). | |
| double | largest_loss_pct |
| Maximum of -pnl_pct over losing trades (positive magnitude) — an INDEPENDENT maximum, not the pct of the largest-USD loss (TV convention, validated 2026-06-12 vs TV export: All "Largest loss %" came from a different trade than the largest USD loss). | |
| double | commission_paid |
| Sum of pf_trade_t::commission in the block. | |
| double | expectancy |
| (num_wins/num_trades)*avg_win - (num_losses/num_trades)*avg_loss, account currency per trade. | |
| int32_t | max_consecutive_wins |
| Longest winning run; even trades reset both streaks. | |
| int32_t | max_consecutive_losses |
| Longest losing run; even trades reset both streaks. | |
| double | avg_bars_in_trade |
| Mean of (exit_bar_index - entry_bar_index + 1) in SCRIPT bars, over all trades — inclusive of the entry bar (TV convention, validated 2026-06-12). | |
| 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). | |
Trade-level statistics block — computed once each for all / long / short.
Loss-side fields (gross_loss, avg_loss, largest_loss) are positive magnitudes (absolute values of the underlying negative PnL).
Definition at line 147 of file pineforge.h.
| int32_t pf_trade_stats_t::num_trades |
Closed trades in this block (all / long-only / short-only).
Definition at line 148 of file pineforge.h.
| int32_t pf_trade_stats_t::num_wins |
Trades with pnl > 0.
Definition at line 149 of file pineforge.h.
| int32_t pf_trade_stats_t::num_losses |
Trades with pnl < 0.
Definition at line 150 of file pineforge.h.
| int32_t pf_trade_stats_t::num_even |
Trades with pnl == 0.0 exactly; breaks both win and loss streaks; excluded from win/loss averages.
Invariant: num_trades == num_wins + num_losses + num_even.
Definition at line 151 of file pineforge.h.
| double pf_trade_stats_t::percent_profitable |
100 * num_wins / num_trades, in PERCENT (0-100).
NaN when num_trades == 0.
Definition at line 154 of file pineforge.h.
| double pf_trade_stats_t::net_profit |
Sum of pnl (account currency, net of commission).
Definition at line 156 of file pineforge.h.
| double pf_trade_stats_t::net_profit_pct |
net_profit as a percent of initial capital (0-100 scale).
NaN when initial capital <= 0.
Definition at line 157 of file pineforge.h.
| double pf_trade_stats_t::gross_profit |
Sum of winning pnl.
Definition at line 159 of file pineforge.h.
| double pf_trade_stats_t::gross_profit_pct |
gross_profit as a percent of initial capital (0-100 scale).
NaN when initial capital <= 0.
Definition at line 160 of file pineforge.h.
| double pf_trade_stats_t::gross_loss |
Sum of |losing pnl| — POSITIVE magnitude (TV display convention).
Definition at line 162 of file pineforge.h.
| double pf_trade_stats_t::gross_loss_pct |
gross_loss as a percent of initial capital (0-100 scale).
NaN when initial capital <= 0.
Definition at line 163 of file pineforge.h.
| double pf_trade_stats_t::profit_factor |
| double pf_trade_stats_t::avg_trade |
| double pf_trade_stats_t::avg_trade_pct |
Mean of per-trade pnl_pct over all trades.
NaN when num_trades == 0.
Definition at line 167 of file pineforge.h.
| double pf_trade_stats_t::avg_win |
| double pf_trade_stats_t::avg_win_pct |
Mean of per-trade pnl_pct over winning trades.
NaN when num_wins == 0.
Definition at line 170 of file pineforge.h.
| double pf_trade_stats_t::avg_loss |
gross_loss / num_losses (positive magnitude).
NaN when num_losses == 0.
Definition at line 172 of file pineforge.h.
| double pf_trade_stats_t::avg_loss_pct |
Mean of the NEGATED pnl_pct of the losing trades.
Since pnl_pct is net return-on-cost (sign matches pnl), this is a genuinely POSITIVE magnitude. Basis = pf_trade_t::pnl_pct. NaN when num_losses == 0.
Definition at line 174 of file pineforge.h.
| double pf_trade_stats_t::ratio_avg_win_avg_loss |
| double pf_trade_stats_t::largest_win |
Single largest pnl among winning trades.
NaN when num_wins == 0.
Definition at line 179 of file pineforge.h.
| double pf_trade_stats_t::largest_win_pct |
Maximum pnl_pct over winning trades — an INDEPENDENT maximum, not the pct of the largest-USD win (TV convention, validated 2026-06-12 vs TV export).
NaN when num_wins == 0.
Definition at line 181 of file pineforge.h.
| double pf_trade_stats_t::largest_loss |
Single largest |pnl| among losing trades (positive magnitude).
NaN when num_losses == 0.
Definition at line 185 of file pineforge.h.
| double pf_trade_stats_t::largest_loss_pct |
Maximum of -pnl_pct over losing trades (positive magnitude) — an INDEPENDENT maximum, not the pct of the largest-USD loss (TV convention, validated 2026-06-12 vs TV export: All "Largest loss %" came from a different trade than the largest USD loss).
NaN when num_losses == 0.
Definition at line 187 of file pineforge.h.
| double pf_trade_stats_t::commission_paid |
Sum of pf_trade_t::commission in the block.
Definition at line 192 of file pineforge.h.
| double pf_trade_stats_t::expectancy |
(num_wins/num_trades)*avg_win - (num_losses/num_trades)*avg_loss, account currency per trade.
NaN when num_trades == 0.
Definition at line 193 of file pineforge.h.
| int32_t pf_trade_stats_t::max_consecutive_wins |
Longest winning run; even trades reset both streaks.
Definition at line 195 of file pineforge.h.
| int32_t pf_trade_stats_t::max_consecutive_losses |
Longest losing run; even trades reset both streaks.
Definition at line 196 of file pineforge.h.
| double pf_trade_stats_t::avg_bars_in_trade |
Mean of (exit_bar_index - entry_bar_index + 1) in SCRIPT bars, over all trades — inclusive of the entry bar (TV convention, validated 2026-06-12).
NaN when num_trades == 0.
Definition at line 197 of file pineforge.h.
| double pf_trade_stats_t::avg_bars_in_wins |
Mean bar duration of winning trades, inclusive of the entry bar (TV convention, validated 2026-06-12).
NaN when num_wins == 0.
Definition at line 201 of file pineforge.h.
| double pf_trade_stats_t::avg_bars_in_losses |
Mean bar duration of losing trades, inclusive of the entry bar (TV convention, validated 2026-06-12).
NaN when num_losses == 0.
Definition at line 204 of file pineforge.h.