3#include <pineforge/pineforge.h>
30 const std::filesystem::path&
path() const noexcept {
return path_; }
32 int abi_version() const noexcept {
return abi_version_value_; }
43 void set_input(pf_strategy_t strategy,
const std::string& key,
const std::string& value)
const;
48 const std::string& key,
49 const std::string& value)
const;
66 const std::string& input_timeframe,
67 const std::string& script_timeframe,
69 int magnifier_samples,
70 pf_magnifier_distribution_t magnifier_distribution,
71 pf_report_t* report)
const;
80 using StrategyCreateFn = pf_strategy_t (*)(
const char*);
81 using StrategyFreeFn = void (*)(pf_strategy_t);
82 using StrategySetInputFn = void (*)(pf_strategy_t,
const char*,
const char*);
83 using StrategySetOverrideFn = void (*)(pf_strategy_t,
const char*,
const char*);
84 using StrategySetChartTimezoneFn = void (*)(pf_strategy_t,
const char*);
85 using RunBacktestFullFn = void (*)(pf_strategy_t,
92 pf_magnifier_distribution_t,
94 using StrategyGetLastErrorFn =
const char* (*)(pf_strategy_t);
95 using ReportFreeFn = void (*)(pf_report_t*);
96 using AbiVersionFn = int (*)();
98 void close() noexcept;
100 std::filesystem::
path path_;
101 void* library_handle_ =
nullptr;
102 int abi_version_value_ = 0;
103 StrategyCreateFn strategy_create_ =
nullptr;
104 StrategyFreeFn strategy_free_ =
nullptr;
105 StrategySetInputFn strategy_set_input_ =
nullptr;
106 StrategySetOverrideFn strategy_set_override_ =
nullptr;
107 StrategySetChartTimezoneFn strategy_set_chart_timezone_ =
nullptr;
108 RunBacktestFullFn run_backtest_full_ =
nullptr;
109 StrategyGetLastErrorFn strategy_get_last_error_ =
nullptr;
110 ReportFreeFn report_free_ =
nullptr;
111 AbiVersionFn pf_abi_version_ =
nullptr;
RAII wrapper around one compiled PineForge strategy plugin.
StrategyPlugin & operator=(StrategyPlugin &&other) noexcept
void set_chart_timezone(pf_strategy_t strategy, const std::string &timezone) const
Sets the chart timezone when non-empty and supported by the plugin.
pf_strategy_t create_strategy() const
Creates a fresh strategy handle owned by the caller.
const std::filesystem::path & path() const noexcept
Returns the dynamic-library path supplied at construction.
std::string last_error(pf_strategy_t strategy) const
Returns the plugin's last error for strategy, or an empty string when none exists.
void free_report(pf_report_t *report) const noexcept
Releases report-owned allocations populated by run_backtest_full().
void run_backtest_full(pf_strategy_t strategy, const pf_bar_t *bars, int bar_count, const std::string &input_timeframe, const std::string &script_timeframe, bool bar_magnifier, int magnifier_samples, pf_magnifier_distribution_t magnifier_distribution, pf_report_t *report) const
Invokes the plugin's full backtest entry point using immutable OHLCV input.
void free_strategy(pf_strategy_t strategy) const noexcept
Releases a handle returned by create_strategy(); safe to call during cleanup.
int abi_version() const noexcept
Returns the ABI version reported by the validated plugin.
void set_input(pf_strategy_t strategy, const std::string &key, const std::string &value) const
Applies one serialized Pine input before the backtest starts.
StrategyPlugin(std::filesystem::path path)
Loads path and resolves the required PineForge strategy symbols.
StrategyPlugin(StrategyPlugin &&other) noexcept
void set_override(pf_strategy_t strategy, const std::string &key, const std::string &value) const
Applies one serialized runtime strategy override before the backtest starts.
StrategyPlugin & operator=(const StrategyPlugin &)=delete
StrategyPlugin(const StrategyPlugin &)=delete