13#include <unordered_map>
14#include <unordered_set>
43#define PINEFORGE_NO_STRATEGY_DECLS
50#define PINEFORGE_HAS_SCRIPT_RUN_PREPARE_V1 1
51#define PINEFORGE_HAS_NATIVE_LIVE_V1 1
76enum class DualEntryStopPathWinner : int;
140 std::numeric_limits<double>::quiet_NaN();
309using InputsMap = std::unordered_map<std::string, std::string>;
327 uint64_t
h = 1469598103934665603ULL;
329 void bytes(
const void* p,
size_t n) {
330 const unsigned char* c =
static_cast<const unsigned char*
>(p);
331 for (
size_t i = 0;
i < n; ++
i) {
h ^= c[
i];
h *= 1099511628211ULL; }
335 if (v == 0.0) v = 0.0;
336 if (v != v) v = std::numeric_limits<double>::quiet_NaN();
340 void i(int64_t v) {
bytes(&v,
sizeof v); }
341 void u(uint64_t v) {
bytes(&v,
sizeof v); }
342 void b(
bool v) {
const unsigned char c = v ? 1 : 0;
bytes(&c, 1); }
343 void s(
const std::string& v) {
u(v.size());
bytes(v.data(), v.size()); }
478 std::unordered_map<std::string, std::string>
inputs_;
492 std::string
get_input_string(
const std::string& key,
const std::string& default_val)
const;
1013 const double inv_int = std::floor(inv + 0.5);
1014 if (inv_int > 0.0 && std::abs(inv - inv_int) <= 1e-6 * inv_int) {
1054 for (
int n = 0; n <= 10; ++n) {
1055 const double k = std::floor(scaled + 0.5);
1056 if (k >= 1.0 && std::abs(scaled - k) <= 1e-6 * k)
return n;
1062 if (std::isnan(level) || !std::isfinite(level))
return level;
1064 if (n < 0)
return level;
1065 double pricescale = 1.0;
1066 for (
int i = 0; i < n; ++i) pricescale *= 10.0;
1072 const double pointsize = 1.0 / pricescale;
1073 const double p = level / pointsize;
1074 const double k = std::floor(p + 0.5);
1076 return k / pricescale;
1106 return fill_price * qty *
syminfo_.pointvalue
1128 if (units <= 0.0)
return 0.0;
1130 return units >= pe.
qty ? paid : paid * (units / pe.
qty);
1164 if (
qty_step_ <= 0.0 || !std::isfinite(qty) || qty <= 0.0)
return qty;
1166 return floored < qty ? floored : qty;
1189 if (
qty_step_ <= 0.0 || !std::isfinite(qty) || qty <= 0.0)
return qty;
1191 return floored < qty ? floored : qty;
1204 double available_qty)
const {
1207 && requested_qty > 0.0
1402 if (n <= 0)
return 0.0;
1404 for (
const auto& t :
trades_) s += t.pnl_pct;
1405 return s / (double)n;
1417 for (
const auto& t :
trades_) {
1418 if (t.pnl > 0.0) { s += t.pnl_pct; ++c; }
1420 return (c > 0) ? (s / (double)c) : 0.0;
1426 for (
const auto& t :
trades_) {
1427 if (t.pnl < 0.0) { s += t.pnl_pct; ++c; }
1429 return (c > 0) ? (s / (double)c) : 0.0;
1483 gmtime_r(&secs, &tm_buf);
1485 bt.
year = tm_buf.tm_year + 1900;
1486 bt.
month = tm_buf.tm_mon + 1;
1488 bt.
hour = tm_buf.tm_hour;
1489 bt.
minute = tm_buf.tm_min;
1490 bt.
second = tm_buf.tm_sec;
1492 bt.
weekofyear = (tm_buf.tm_yday + 7 - ((tm_buf.tm_wday + 6) % 7)) / 7;
1746 value.store(
false, std::memory_order_relaxed);
1750 value.store(
false, std::memory_order_relaxed);
1753 bool load(std::memory_order order)
const {
return value.load(order); }
1754 void store(
bool v, std::memory_order order) {
value.store(v, order); }
1787 const std::string& input_tf);
1883 if (index >= 0 && index < (
int)
trades_.size())
1888 if (idx < 0 || idx >= (
int)
trades_.size())
return std::numeric_limits<double>::quiet_NaN();
1892 if (idx < 0 || idx >= (
int)
trades_.size())
return std::numeric_limits<double>::quiet_NaN();
1893 return trades_[idx].commission;
1897 return trades_[idx].entry_bar_index;
1901 return trades_[idx].exit_bar_index;
1904 if (idx < 0 || idx >= (
int)
trades_.size())
return std::string();
1905 return trades_[idx].entry_comment;
1908 if (idx < 0 || idx >= (
int)
trades_.size())
return std::string();
1909 return trades_[idx].exit_comment;
1912 if (idx < 0 || idx >= (
int)
trades_.size())
return std::string();
1916 if (idx < 0 || idx >= (
int)
trades_.size())
return std::string();
1920 if (idx < 0 || idx >= (
int)
trades_.size())
return 0;
1921 return trades_[idx].entry_incarnation;
1924 if (idx < 0 || idx >= (
int)
trades_.size())
return std::numeric_limits<double>::quiet_NaN();
1925 return trades_[idx].entry_price;
1928 if (idx < 0 || idx >= (
int)
trades_.size())
return std::numeric_limits<double>::quiet_NaN();
1929 return trades_[idx].exit_price;
1932 if (idx < 0 || idx >= (
int)
trades_.size())
return 0;
1933 return trades_[idx].entry_time;
1936 if (idx < 0 || idx >= (
int)
trades_.size())
return 0;
1937 return trades_[idx].exit_time;
1940 if (idx < 0 || idx >= (
int)
trades_.size())
return std::numeric_limits<double>::quiet_NaN();
1944 if (idx < 0 || idx >= (
int)
trades_.size())
return 0.0;
1945 return trades_[idx].max_runup;
1952 if (idx < 0 || idx >= (
int)
trades_.size())
return 0.0;
1954 double cost = t.entry_price * t.qty *
syminfo_.pointvalue;
1955 return (cost > 0.0) ? (t.max_runup / cost) * 100.0 : 0.0;
1958 if (idx < 0 || idx >= (
int)
trades_.size())
return 0.0;
1959 return trades_[idx].max_drawdown;
1962 if (idx < 0 || idx >= (
int)
trades_.size())
return 0.0;
1964 double cost = t.entry_price * t.qty *
syminfo_.pointvalue;
1965 return (cost > 0.0) ? (t.max_drawdown / cost) * 100.0 : 0.0;
1970 if (idx < 0 || idx >= (
int)
trades_.size())
return "";
1971 return trades_[idx].is_long ?
"long" :
"short";
2043 struct NativeSettlementStage;
2044 struct NativeSettlementRows;
2047 NativeSettlementStage& stage,
2049 double& remaining)
const;
2053 const NativeSettlementStage& stage,
const execution::Fill& fill)
const;
2055 const NativeSettlementStage& stage,
const execution::Fill& fill)
const;
2063 NativeSettlementRows& rows)
const;
2067 NativeSettlementRows& rows)
const;
2069 const NativeSettlementStage& stage,
2071 const NativeSettlementRows& rows);
2076 NativeSettlementRows& rows);
2082 NativeSettlementStage& stage,
2089 NativeSettlementStage& stage,
2115 const std::vector<double>& closed_units,
double opening_units,
2124 double fill_price,
bool was_long,
double entry_commission,
2125 double exit_commission,
2167 bool count_miss =
true);
2170#ifdef PINEFORGE_HAS_AUX_SECURITY_FEED_V1
2213 mutable std::unique_ptr<IExecutionConsumer>
ptr;
2216 :
native(other.native) {}
2218 if (
this != &other) {
2228 if (
this != &other) {
2257 const std::string& input_tf,
2258 const std::string& script_tf,
2259 bool bar_magnifier =
false,
2260 int magnifier_samples = 4,
2263#ifdef PINEFORGE_HAS_AUX_SECURITY_FEED_V1
2268 const std::string& input_tf);
2276 const Bar* bars,
int n);
2301 const std::string& input_tf,
2302 const std::string& script_tf =
"");
2327 const double* rates,
int n);
2330 const std::string& input_tf,
2331 const std::string& script_tf,
2332 const std::unordered_map<std::string, std::string>& inputs,
2338 const void* overrides =
nullptr,
2339 bool bar_magnifier =
false,
2340 int magnifier_samples = 4,
2364 const int n_closed = (int)
trades_.size();
2365 return i < n_closed ?
trades_[(size_t)i]
2400 void set_input(
const std::string& key,
const std::string& value) {
2492 if (value.empty())
return false;
2493 if (key ==
"type") {
syminfo_.type = value;
return true; }
2494 if (key ==
"ticker") {
syminfo_.ticker = value;
return true; }
2495 if (key ==
"tickerid") {
syminfo_.tickerid = value;
return true; }
2496 if (key ==
"currency") {
syminfo_.currency = value;
return true; }
2497 if (key ==
"basecurrency") {
syminfo_.basecurrency = value;
return true; }
2498 if (key ==
"description") {
syminfo_.description = value;
return true; }
2499 if (key ==
"volumetype") {
syminfo_.volumetype = value;
return true; }
2516 if (pv > 0.0) {
syminfo_.pointvalue = pv; }
2727 int* close_only,
int* partition)
const;
2731 double* trail_activation)
const;
2821 void trace(
const std::string& name,
double value);
2822 void trace(
const std::string& name,
bool value) {
trace(name, value ? 1.0 : 0.0); }
2823 void trace(
const std::string& name,
int value) {
trace(name,
static_cast<double>(value)); }
bool set_native_security_feed(const std::string &timeframe, const Bar *bars, int n)
broker::OpeningObligations opening_obligations_
virtual void hash_source_extension(BrokerStateHashSink &) const
double closed_trade_profit(int index) const
double get_syminfo_metadata(const std::string &key) const
void set_path_order(int mode)
double account_currency_fx_at(int64_t timestamp_ms) const
std::vector< std::string > trace_names_
std::vector< double > quote_execution_commissions(const std::vector< double > &closed_units, double opening_units, const execution::Fill &fill) const
void stage_native_settlement(NativeSettlementStage &stage, const execution::Action &action, const execution::Fill &fill, execution::CloseScope book_or_opening, const execution::SelectedOpeningSet *selected, const execution::LifecycleEffects *lifecycle) const
int64_t position_entry_time_
virtual ~BacktestEngine()
std::vector< int64_t > account_currency_fx_timestamps_
execution::Result settle_with_context_scoped(const execution::Action &action, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::PhysicalExecutionContext &context, execution::CloseScope scope)
execution::Result settle_native_reversal_at_v1(const execution::ReverseTo &reversal, const execution::Fill &fill, const execution::PhysicalExecutionContext &context)
double open_trade_max_runup_percent(int idx) const
double account_currency_fx_broker_rate_
bool stream_has_input_bar_
double trail_best_price() const
const StreamOrderAction & stream_order_action_at(int i) const
int64_t closed_trade_exit_time(int idx) const
void trace(const std::string &name, double value)
void set_trace_enabled(bool on)
bool account_currency_fx_broker_epoch_initialized_
uint64_t next_order_incarnation_
void trace(const std::string &name, bool value)
bool stream_has_last_price_
const Trade & get_trade(int i) const
double stream_last_price_
StreamPhase stream_phase_
bool stream_end(bool finalize_partial_input_bar=false)
double closed_trade_max_runup_percent(int idx) const
uint64_t stream_state_hash() const
double avg_trade_percent() const
static constexpr double kLevelGridBandPoints
const Trade & closed_trade(std::size_t i) const
virtual void commit_script_state()
execution::AccountEffectProjection project_native_settlement_stage(const NativeSettlementStage &stage, const execution::Fill &fill) const
bool substitute_native_security_bar(SecurityEvalState &state, Bar &bar, bool count_miss=true)
std::uint64_t broker_state_hash_from_execution_hash(std::uint64_t) const
uint64_t stream_action_sequence_
const std::string & main_period() const
void stream_order_actions_clear()
execution::Status prepare_native_settlement_commit(const NativeSettlementStage &stage, const execution::Fill &fill, const execution::PhysicalExecutionContext &context, NativeSettlementRows &rows) const
virtual bool set_aux_security_feed(const Bar *bars, int n, const std::string &input_tf)
virtual void set_syminfo_metadata(const std::string &key, double value)
double net_profit_roundoff_value_
virtual int observe_pending_effective_levels(int index, double *stop, double *limit, double *trail_activation) const
double open_profit(double current_price) const
void update_equity_extremes()
execution::Result settle_execution_selected_with_lifecycle(const execution::Action &action, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::SelectedOpeningSet &selection)
execution::Result settle_with_context_selected(const execution::Action &action, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::PhysicalExecutionContext &context, const execution::SelectedOpeningSet &selection)
int diag_script_tf_ratio_
std::vector< SecurityEvalState > security_eval_states_
std::string closed_trade_exit_comment(int idx) const
BacktestEngine(NativeConsumerBindTag)
int64_t position_cycle_seq() const
execution::AccountEffectProjection project_native_settlement_scoped_v1(const execution::Action &action, const execution::Fill &fill, execution::CloseScope scope) const
std::vector< pf_equity_point_t > equity_curve_
double open_trade_profit(int idx) const
static void free_report(ReportC *report)
std::string security_input_tf_
std::vector< TraceEntryC > trace_buffer_
std::string open_trade_entry_id(int idx) const
virtual int observe_pending_level_resolved(int index) const
int open_trade_entry_bar_index(int idx) const
void trace(const std::string &name, int value)
bool session_template_knows_early_close() const
Whether TradingView's session template for this symbol carries the exchange's early closes and holida...
double calc_commission(double fill_price, double qty) const
double max_contracts_held_short_
bool get_input_bool(const std::string &key, bool default_val) const
bool stream_push_ticks(const TradeTick *ticks, int n)
void stream_refresh_action_metadata(size_t first_action, size_t first_trade)
int64_t stream_next_input_open_ms_
double tick_grid_price(double price) const
const std::string & last_error() const
double open_trade_size(int idx) const
double account_currency_fx_
int closed_trade_entry_bar_index(int idx) const
virtual std::uint64_t broker_state_hash_projection() const
virtual void source_stream_entry_comment(const PyramidEntry &, std::string &) const
virtual int observe_pending_copy_v1(int index, pf_pending_order_v1_t *out) const
double net_profit_roundoff_bound_
std::vector< StreamOrderAction > stream_order_actions_
bool broker_state_hash_recording_
std::string get_input_string(const std::string &key, const std::string &default_val) const
double closed_trade_profit_percent(int idx) const
StreamInputMode stream_input_mode_
void set_trade_start_time(int64_t timestamp_ms)
std::vector< PyramidEntry > pyramid_entries_
bool diag_needs_aggregation_
void set_magnifier_volume_weighted(bool on)
const IExecutionConsumer & execution_consumer() const
void build_native_settlement_close_rows(const NativeSettlementStage &stage, const execution::Fill &fill, const execution::PhysicalExecutionContext &context, NativeSettlementRows &rows) const
uint64_t stream_last_sequence_
NativeDayPartition chart_day_partition_
void stream_observe_entry(const PyramidEntry &pe)
void dispatch_security_eval(SecurityEvalState &state, const Bar &bar, bool publish, int64_t bar_index)
bool stream_is_realtime() const
bool chart_day_partition_installed() const
int64_t prev_bar_timestamp_
double open_trade_max_drawdown_percent(int idx) const
double get_input_double(const std::string &key, double default_val) const
double open_trade_profit_percent(int idx) const
uint64_t last_script_continuation_hash_
virtual int observe_pending_count_v1() const
int64_t closed_trade_entry_time(int idx) const
virtual void clear_security(int sec_id)
virtual void evaluate_security(int sec_id, const Bar &bar, bool is_complete)
int price_grid_decimals() const
int stream_order_actions_len() const
friend class NativeExecutionConsumer
double max_contracts_held_all() const
execution::Result settle_with_membership(const execution::Action &action, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::PhysicalExecutionContext &context, execution::CloseScope book_or_opening, const execution::SelectedOpeningSet *selected)
void fill_report(ReportC *out) const
execution::AccountEffectProjection project_native_reversal_v1(const execution::ReverseTo &reversal, const execution::Fill &fill) const
bool magnifier_volume_weighted_
execution::Result settle_source_staged_execution(NativeSettlementStage &stage, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::PhysicalExecutionContext &context)
void record_equity_point(int64_t script_bar_ts)
double closed_trade_commission(int idx) const
virtual bool set_probe_suppress_tail_logic(bool on)
double round_to_mintick(double price) const
double closed_trade_max_drawdown(int idx) const
uint64_t broker_state_hash() const
double gross_loss() const
void fill_trades_section(ReportC *out) const
bool bar_magnifier_enabled_
int report_trade_count() const
PositionSide position_side_
execution::AccountEffectProjection project_native_settlement_v1(const execution::Action &action, const execution::Fill &fill) const
virtual void on_bar(const Bar &bar)=0
execution::Result settle_reversal_with_lifecycle_v1(const execution::ReverseTo &reversal, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle)
double grossprofit_percent() const
execution::SettlementInspection inspect_native_reversal_v1(const execution::ReverseTo &reversal, const execution::Fill &fill) const
double position_entry_price_
bool set_syminfo_string(const std::string &key, const std::string &value)
double open_trade_commission(int idx) const
broker::PositionCloseObligation position_close_obligation_
double closed_trade_max_drawdown_percent(int idx) const
void append_quoted_lot(PyramidEntry lot, double total_qty, double average_price)
void set_syminfo_session(const std::string &s)
double max_contracts_held_long_
std::vector< uint64_t > broker_state_hashes_
MagnifierDistribution magnifier_dist_
std::string chart_timezone_
execution::Result commit_native_settlement_stage(NativeSettlementStage &stage, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::PhysicalExecutionContext &context)
execution::Result settle_native_execution_selected_at(const execution::Action &action, const execution::Fill &fill, const execution::PhysicalExecutionContext &context, const execution::SelectedOpeningSet &selection)
AbortFlag abort_requested_
execution::AccountEffectProjection project_with_membership(const execution::Action &action, const execution::Fill &fill, execution::CloseScope book_or_opening, const execution::SelectedOpeningSet *selected) const
double grossloss_percent() const
friend class NativeStrategyHost
execution::Result settle_native_execution_scoped_at(const execution::Action &action, const execution::Fill &fill, const execution::PhysicalExecutionContext &context, execution::CloseScope scope)
std::size_t closed_trade_count() const noexcept
execution::Result settle_native_execution_at(const execution::Action &action, const execution::Fill &fill, const execution::PhysicalExecutionContext &context)
void snapshot_entry_commission(PyramidEntry &pe) const
bool aux_security_feed_enabled() const
virtual int observe_last_bar_dual_entry_path_v1() const
execution::Status preview_native_settlement_commit(const execution::Action &action, const execution::Fill &fill, const execution::PhysicalExecutionContext &context, execution::CloseScope scope, const execution::SelectedOpeningSet *selected, execution::AccountEffectProjection &account, std::vector< double > &row_pnl) const
execution::SettlementInspection inspect_native_settlement_scoped(const execution::Action &action, const execution::Fill &fill, execution::CloseScope scope) const
int execution_contract() const
void set_chart_timezone(const std::string &tz)
ExecutionConsumerSlot execution_consumer_slot_
int64_t bar_time_memo_ts_
std::string closed_trade_exit_id(int idx) const
int _bar_dayofweek() const
void run(const Bar *bars, int n)
std::vector< Trade > range_end_trades_
bool native_bound() const
void reset_position_state_to_flat()
double open_entry_commission(const PyramidEntry &pe) const
execution::Status preview_native_settlement_commit(const execution::ReverseTo &reversal, const execution::Fill &fill, const execution::PhysicalExecutionContext &context, execution::AccountEffectProjection &account, std::vector< double > &row_pnl) const
std::size_t account_currency_fx_broker_epoch_
int64_t native_security_substitutions() const
CommissionType commission_type_
std::string closed_trade_entry_comment(int idx) const
void guard_native_mutation(const char *operation)
double active_account_currency_fx() const
int last_run_status() const
int64_t trade_start_time_
double live_current_equity() const
int64_t next_position_cycle_seq_
void stream_observe_exit(size_t trade_index)
int stream_next_script_bar_index_
double max_drawdown_percent() const
std::unordered_map< std::string, double > syminfo_metadata_
double gross_profit() const
bool stream_push_bar(const Bar &bar)
virtual void source_aux_security_input_view(const Bar *&bars, int &n) const
std::string open_trade_entry_comment(int idx) const
std::unordered_map< std::string, std::string > inputs_
int position_entry_count_
double max_contracts_held_all_
double avg_losing_trade_percent() const
double closed_trade_exit_price(int idx) const
double bar_fill_price(double raw_bar_price) const
execution::Result settle_with_context(const execution::Action &action, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::PhysicalExecutionContext &context)
bool stream_script_bar_had_tick_
double avg_winning_trade_percent() const
double level_on_price_grid(double level) const
int32_t intern_trace_name(const std::string &name)
execution::Status preflight_native_settlement_effects(const NativeSettlementStage &stage, const execution::LifecycleEffects &lifecycle, const NativeSettlementRows &rows)
double net_profit() const
virtual bool source_aux_security_feed_enabled() const
double avg_winning_trade() const
int count_wintrades() const
bool trace_enabled() const
double closed_trade_max_runup(int idx) const
virtual double live_position_size() const
uint64_t closed_trade_entry_incarnation(int idx) const
virtual bool set_realtime_tail(bool on, int horizon_bars)
double current_equity() const
execution::SettlementInspection inspect_native_settlement_selected(const execution::Action &action, const execution::Fill &fill, const execution::SelectedOpeningSet &selection) const
execution::Status allocate_native_settlement_closes(NativeSettlementStage &stage, const execution::CloseScope &book_or_opening, double &remaining) const
void open_quoted_position(PositionSide requested, PyramidEntry lot)
bool stream_push_tick(const TradeTick &tick)
void feed_security_eval_state(SecurityEvalState &state, const Bar &input_bar)
double max_contracts_held_long() const
int64_t diag_native_security_substitutions_
void fill_security_diag_section(ReportC *out) const
int64_t stream_last_tick_ms_
bool stream_begin(const Bar *warmup_bars, int n_warmup, const std::string &input_tf, const std::string &script_tf="")
const std::string & chart_timezone() const
virtual int observe_probe_fill_qty(int index, double fill_price, double *qty, int *close_only, int *partition) const
int _bar_weekofyear() const
double max_contracts_held_short() const
void set_syminfo_mintick(double m)
void run(const Bar *input_bars, int n_input, const std::string &input_tf, const std::string &script_tf, bool bar_magnifier=false, int magnifier_samples=4, MagnifierDistribution magnifier_dist=MagnifierDistribution::ENDPOINTS)
void stage_native_settlement(NativeSettlementStage &stage, const execution::ReverseTo &reversal, const execution::Fill &fill, const execution::LifecycleEffects *lifecycle) const
double open_trade_max_runup(int idx) const
std::string position_entry_name() const
LotExcursionHook lot_excursion_hook_
void prepare_chart_day_partition(const Bar *input_bars, int n_input)
int64_t security_next_input_ms_
uint64_t broker_fill_event_seq_
int64_t open_trade_entry_time(int idx) const
double closed_trade_size(int idx) const
execution::Status validate_native_settlement_book(double &held) const
virtual void hash_host_extension(BrokerStateHashSink &) const
double position_avg_price() const
bool last_script_continuation_valid_
execution::AccountEffectProjection project_native_settlement_selected_v1(const execution::Action &action, const execution::Fill &fill, const execution::SelectedOpeningSet &selection) const
void set_syminfo_timezone(const std::string &tz)
std::vector< NativeSecurityFeed > native_security_feeds_
bool native_security_feed_enabled() const
bool stream_advance_time(int64_t timestamp_ms)
virtual void snapshot_script_state()
execution::Result commit_prepared_native_settlement_stage(NativeSettlementStage &stage, const execution::Fill &fill, const execution::LifecycleEffects &lifecycle, const execution::PhysicalExecutionContext &context, NativeSettlementRows &rows)
execution::SettlementInspection inspect_with_membership(const execution::Action &action, const execution::Fill &fill, execution::CloseScope book_or_opening, const execution::SelectedOpeningSet *selected) const
double avg_losing_trade() const
double apply_percent_exit_qty_step(double requested_qty, double available_qty) const
void run(const Bar *input_bars, int n_input, const std::string &input_tf, const std::string &script_tf, const std::unordered_map< std::string, std::string > &inputs, const SymInfo &syminfo, const void *overrides=nullptr, bool bar_magnifier=false, int magnifier_samples=4, MagnifierDistribution magnifier_dist=MagnifierDistribution::ENDPOINTS)
Trade build_close_trade_with_costs(const PyramidEntry &pe, double close_qty, double fill_price, bool was_long, double entry_commission, double exit_commission, const execution::PhysicalExecutionContext &context) const
bool stream_seen_sequence_
int get_input_int(const std::string &key, int default_val) const
const Trade & get_report_trade(int i) const
virtual void prepare_script_run(const Bar *, int, bool)
void fill_metrics_section(ReportC *out) const
double fold_exit_trail_peak_
void set_input(const std::string &key, const std::string &value)
std::vector< double > account_currency_fx_rates_
int64_t native_security_misses() const
execution::SettlementInspection inspect_native_settlement_stage(const NativeSettlementStage &stage, const execution::Fill &fill) const
int64_t get_input_int64(const std::string &key, int64_t default_val) const
TimeframeAggregator script_tf_agg_
std::unordered_map< std::string, int32_t > trace_name_index_
int64_t diag_magnifier_sub_bars_processed_
double open_trade_entry_price(int idx) const
void finish_native_settlement_stage(NativeSettlementStage &stage, const execution::Fill &fill) const
int _bar_dayofmonth() const
void set_broker_state_hash_recording(bool on)
virtual void restore_script_state()
double marked_equity(double price) const
bool set_account_currency_fx_series(const int64_t *timestamps_ms, const double *rates, int n)
void append_same_side_fill(PyramidEntry lot)
int64_t diag_input_bars_processed_
void fill_trace_section(ReportC *out) const
std::vector< Trade > trades_
int closed_trade_exit_bar_index(int idx) const
double closed_trade_entry_price(int idx) const
std::string closed_trade_entry_id(int idx) const
void register_security_eval(int sec_id, const std::string &requested_tf, const std::string &input_tf)
execution::SettlementInspection inspect_native_settlement(const execution::Action &action, const execution::Fill &fill) const
bool chart_bar_ismarket(int64_t bar_ms) const
int64_t diag_native_security_misses_
int64_t position_cycle_seq_
int64_t diag_script_bars_processed_
BarTime _decompose_bar_time() const
void settle_position_after_partial_exit(PositionReductionCause cause)
bool host_mutation_guard_inert_
bool stream_script_tick_seen_
int64_t script_bars_processed() const
double max_runup_percent() const
virtual double observe_trail_best_price_v1() const
int closed_trade_close_cause(int i) const
virtual void configure_security_evaluators()
double open_trade_max_drawdown(int idx) const
void fold_equity_extreme(double eq)
std::string closed_trade_direction(int idx) const
double allocated_entry_commission(const PyramidEntry &pe, double units) const
void prepare_native_security_feeds(const Bar *input_bars, int n_input)
int64_t diag_magnifier_sample_ticks_processed_
double apply_exit_qty_step(double qty) const
void set_syminfo_pointvalue(double pv)
bool stream_observe_actions_
int64_t stream_input_tf_ms_
void validate_close_trade_counters(const Trade *rows, size_t count) const
void record_close_trade(Trade trade)
int count_losstrades() const
std::string open_trade_direction(int idx) const
void set_syminfo_type(const std::string &t)
Bar broker_tick_bar(const Bar &bar) const
virtual void finalize_bar()
double apply_qty_step(double qty) const
double open_trades_capital_held() const
IExecutionConsumer & execution_consumer()
virtual std::uint64_t broker_state_hash_projection() const =0
virtual ~BrokerStateHashProvider()=default
void bytes(const void *p, size_t n)
void s(const std::string &v)
std::variant< Book, OpeningExposure > CloseScope
std::variant< Flatten, order_action::Reduce, order_action::Transact > Action
exit_legs::Lifecycle ExitLegLifecycle
std::function< ClosedLotExcursion(const ClosedLotExcursionFacts &)> LotExcursionHook
std::unordered_map< std::string, std::string > InputsMap
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).
Composite metrics container: trade stats (all / long / short) + equity-curve stats.
bool entry_bar_high_masked
bool entry_bar_low_masked
uint64_t entry_incarnation
uint64_t entry_incarnation
std::string entry_comment
double entry_commission_account
int64_t magnifier_sample_ticks_total
int bar_magnifier_enabled
SecurityDiagC * security_diag
int64_t security_feeds_total
int64_t magnifier_sub_bars_total
pf_equity_point_t * equity_curve
int64_t broker_state_hash_len
int64_t input_bars_processed
int64_t security_eval_complete_total
uint64_t * broker_state_hash
const char ** trace_names
int64_t script_bars_processed
int64_t security_eval_partial_total
int64_t eval_partial_count
int64_t eval_complete_count
size_t closed_trade_index
uint64_t entry_incarnation
execution::CloseCause close_cause
uint64_t entry_incarnation
std::string entry_comment
void store(bool v, std::memory_order order)
AbortFlag & operator=(AbortFlag &&) noexcept
AbortFlag & operator=(const AbortFlag &) noexcept
AbortFlag(const AbortFlag &) noexcept
bool load(std::memory_order order) const
std::atomic< bool > value
AbortFlag(AbortFlag &&) noexcept
ExecutionConsumerSlot & operator=(ExecutionConsumerSlot &&other) noexcept
ExecutionConsumerSlot(ExecutionConsumerSlot &&other) noexcept
ExecutionConsumerSlot & operator=(const ExecutionConsumerSlot &other) noexcept
ExecutionConsumerSlot(const ExecutionConsumerSlot &other) noexcept
ExecutionConsumerSlot()=default
std::unique_ptr< IExecutionConsumer > ptr
NativeConsumerBindTag()=default
std::unordered_map< int64_t, Bar > native_bars_by_label
int64_t eval_partial_count
int64_t eval_complete_count
int current_sub_bar_count
TimeframeAggregator aggregator