17 void on_native_run_begin()
override { bars_ = 0; }
21 void on_native_bar(
const pineforge::Bar&,
22 const pineforge::NativeDecisionContext&)
override {
25 submit_market({pineforge::order_action::Transact{1.0},
"hello-long",
""});
26 }
else if (bars_ == 3) {
27 submit_market({pineforge::execution::Flatten{},
"hello-flat",
""});
51 spec.
fee_kind = pineforge::NativeFeeKind::Percent;
58 {100.0, 102.0, 99.0, 101.0, 4.0, 0},
59 {102.0, 103.0, 101.0, 102.0, 4.0, 300000},
60 {103.0, 104.0, 102.0, 103.5, 4.0, 600000},
61 {103.5, 105.0, 103.0, 104.0, 4.0, 900000},
69 if (host.configure_native(
make_spec()).status
70 != pineforge::NativeSetupStatus::Applied) {
71 std::cerr <<
"configure: " << host.last_error() <<
'\n';
76 if (host.native_state().kind != pineforge::NativeLifecycleKind::Completed) {
77 std::cerr <<
"run: " << host.last_error() <<
'\n';
81 std::cout <<
"closed trades: " << host.trade_count() <<
'\n';
82 for (
int i = 0; i < host.trade_count(); ++i) {
83 const auto& trade = host.get_trade(i);
84 std::cout <<
" " << (trade.is_long ?
"long " :
"short")
85 <<
" qty=" << trade.qty
86 <<
" entry=" << trade.entry_price
87 <<
" exit=" << trade.exit_price
88 <<
" pnl=" << trade.pnl <<
'\n';
90 return host.trade_count() > 0 ? 0 : 1;
The public native host: an abstract subclass of BacktestEngine with no PineScript on it.
static const pf_bar_t kBars[]
static pf_native_run_spec_v1 make_spec(void)
One complete setup value, staged/copied by NativeStrategyHost before it is applied at begin.
native_order::RunIdentity identity