2727
2828#include < pineforge/bar.hpp>
2929#include < pineforge/engine.hpp>
30+ #include < pineforge/source/pine_strategy_host.hpp>
3031
3132using namespace pineforge ;
3233
@@ -57,7 +58,7 @@ namespace {
5758// because process_orders_on_close is on), then closes it on bar 1. Whether the
5859// entry survives the affordability gate is observable as trade_count() == 1 (or
5960// 0 if rejected).
60- class FxProbe : public BacktestEngine {
61+ class FxProbe : public pineforge ::source::PineStrategyHost {
6162public:
6263 explicit FxProbe (double fx_or_nan, double commission_percent = 0.0 ) {
6364 initial_capital_ = 1000.0 ;
@@ -70,7 +71,7 @@ class FxProbe : public BacktestEngine {
7071 if (!std::isnan (fx_or_nan))
7172 set_syminfo_metadata (" account_currency_fx" , fx_or_nan);
7273 }
73- void on_bar (const Bar& /* bar*/ ) override {
74+ void on_source_bar (const Bar& /* bar*/ ) override {
7475 if (bar_index_ == 0 )
7576 strategy_entry (" L" , true , kNaN , kNaN , 1.0 ); // qty=1 market long
7677 else if (bar_index_ == 1 )
@@ -84,7 +85,7 @@ class FxProbe : public BacktestEngine {
8485// A default 100%-of-equity order is placed under FX=1.0 and fills on the
8586// next bar after FX rolls to 1.001. TV admits the frozen signal snapshot, then
8687// revalues the live fill and emits a broker margin trim at the new rate.
87- class FrozenFxRolloverProbe : public BacktestEngine {
88+ class FrozenFxRolloverProbe : public pineforge ::source::PineStrategyHost {
8889public:
8990 FrozenFxRolloverProbe () {
9091 initial_capital_ = 10000.0 ;
@@ -96,7 +97,7 @@ class FrozenFxRolloverProbe : public BacktestEngine {
9697 qty_step_ = 0.0001 ;
9798 process_orders_on_close_ = false ;
9899 }
99- void on_bar (const Bar& /* bar*/ ) override {
100+ void on_source_bar (const Bar& /* bar*/ ) override {
100101 if (bar_index_ == 0 ) strategy_entry (" L" , true );
101102 }
102103 int trades () const { return trade_count (); }
@@ -109,7 +110,7 @@ class FrozenFxRolloverProbe : public BacktestEngine {
109110// A live 1x long crosses a timestamped FX epoch on bar 2. The broker must
110111// consume that epoch and emit any required trim at bar OPEN, before on_bar can
111112// observe the position or place another order.
112- class CarriedFxRolloverOrderingProbe : public BacktestEngine {
113+ class CarriedFxRolloverOrderingProbe : public pineforge ::source::PineStrategyHost {
113114public:
114115 CarriedFxRolloverOrderingProbe () {
115116 initial_capital_ = 10000.0 ;
@@ -120,7 +121,7 @@ class CarriedFxRolloverOrderingProbe : public BacktestEngine {
120121 qty_step_ = 0.0001 ;
121122 process_orders_on_close_ = true ;
122123 }
123- void on_bar (const Bar& /* bar*/ ) override {
124+ void on_source_bar (const Bar& /* bar*/ ) override {
124125 ++on_bar_calls_;
125126 if (bar_index_ == 0 ) {
126127 strategy_entry (" L" , true , kNaN , kNaN , 100.0 );
@@ -150,7 +151,7 @@ class CarriedFxRolloverOrderingProbe : public BacktestEngine {
150151// liquidation rule. They must reject before on_bar instead of silently
151152// falling through to the end-of-bar adverse-price pass. (1x short is
152153// supported by cell A1; keep this probe for leveraged-only fail-closed.)
153- class UnsupportedCarriedFxRolloverProbe : public BacktestEngine {
154+ class UnsupportedCarriedFxRolloverProbe : public pineforge ::source::PineStrategyHost {
154155public:
155156 UnsupportedCarriedFxRolloverProbe (bool is_long, double margin_pct)
156157 : is_long_(is_long) {
@@ -161,7 +162,7 @@ class UnsupportedCarriedFxRolloverProbe : public BacktestEngine {
161162 margin_short_ = is_long ? 100.0 : margin_pct;
162163 process_orders_on_close_ = true ;
163164 }
164- void on_bar (const Bar& /* bar*/ ) override {
165+ void on_source_bar (const Bar& /* bar*/ ) override {
165166 ++on_bar_calls_;
166167 if (bar_index_ == 0 ) {
167168 strategy_entry (is_long_ ? " L" : " S" , is_long_,
@@ -177,7 +178,7 @@ class UnsupportedCarriedFxRolloverProbe : public BacktestEngine {
177178
178179// Cell A1 dual of CarriedFxRolloverOrderingProbe: carried 1x short under a
179180// timestamped FX epoch change. Mirrors long sizing (qty=100, capital=10000).
180- class CarriedShortFxRolloverProbe : public BacktestEngine {
181+ class CarriedShortFxRolloverProbe : public pineforge ::source::PineStrategyHost {
181182public:
182183 CarriedShortFxRolloverProbe () {
183184 initial_capital_ = 10000.0 ;
@@ -189,7 +190,7 @@ class CarriedShortFxRolloverProbe : public BacktestEngine {
189190 qty_step_ = 0.0001 ;
190191 process_orders_on_close_ = true ;
191192 }
192- void on_bar (const Bar& /* bar*/ ) override {
193+ void on_source_bar (const Bar& /* bar*/ ) override {
193194 ++on_bar_calls_;
194195 if (bar_index_ == 0 ) {
195196 strategy_entry (" S" , /* is_long=*/ false , kNaN , kNaN , 100.0 );
@@ -221,7 +222,7 @@ class CarriedShortFxRolloverProbe : public BacktestEngine {
221222// crossed that epoch while still flat. The flat crossing must consume the
222223// rollover permanently: once margin calls are enabled after the fill, the next
223224// bar must not replay the old epoch against the newly opened position.
224- class FlatEpochConsumptionProbe : public BacktestEngine {
225+ class FlatEpochConsumptionProbe : public pineforge ::source::PineStrategyHost {
225226public:
226227 FlatEpochConsumptionProbe () {
227228 initial_capital_ = 10000.0 ;
@@ -233,7 +234,7 @@ class FlatEpochConsumptionProbe : public BacktestEngine {
233234 qty_step_ = 0.1 ;
234235 process_orders_on_close_ = false ;
235236 }
236- void on_bar (const Bar& /* bar*/ ) override {
237+ void on_source_bar (const Bar& /* bar*/ ) override {
237238 if (bar_index_ == 0 ) {
238239 // Signal under FX=1.0; the frozen admission tuple lets this fill at
239240 // the next open after FX=1.001 becomes effective.
@@ -263,7 +264,7 @@ class FlatEpochConsumptionProbe : public BacktestEngine {
263264// Entry fees are paid in account currency at the entry fill. A later FX epoch
264265// changes open gross PnL and exit-time trade reporting, but must not reprice the
265266// already-paid fee exposed by strategy.opentrades.* while the slice is live.
266- class EntryFeeAccessorLifecycleProbe : public BacktestEngine {
267+ class EntryFeeAccessorLifecycleProbe : public pineforge ::source::PineStrategyHost {
267268public:
268269 EntryFeeAccessorLifecycleProbe (CommissionType type, double value,
269270 double qty)
@@ -275,7 +276,7 @@ class EntryFeeAccessorLifecycleProbe : public BacktestEngine {
275276 margin_long_ = 0.0 ; // isolate accounting from broker liquidation
276277 process_orders_on_close_ = true ;
277278 }
278- void on_bar (const Bar& /* bar*/ ) override {
279+ void on_source_bar (const Bar& /* bar*/ ) override {
279280 if (bar_index_ == 0 ) {
280281 strategy_entry (" L" , true , kNaN , kNaN , qty_);
281282 } else if (bar_index_ == 1 ) {
@@ -299,7 +300,7 @@ class EntryFeeAccessorLifecycleProbe : public BacktestEngine {
299300
300301// Exercises lifecycle transitions that retain or replace PyramidEntry slices:
301302// a rate-1 entry, a rate-2 pyramid add, a FIFO partial exit, then a reversal.
302- class PyramidEntryFeeLifecycleProbe : public BacktestEngine {
303+ class PyramidEntryFeeLifecycleProbe : public pineforge ::source::PineStrategyHost {
303304public:
304305 PyramidEntryFeeLifecycleProbe () {
305306 initial_capital_ = 10000.0 ;
@@ -311,7 +312,7 @@ class PyramidEntryFeeLifecycleProbe : public BacktestEngine {
311312 process_orders_on_close_ = true ;
312313 pyramiding_ = 3 ;
313314 }
314- void on_bar (const Bar& /* bar*/ ) override {
315+ void on_source_bar (const Bar& /* bar*/ ) override {
315316 if (bar_index_ == 0 ) {
316317 strategy_entry (" L1" , true , kNaN , kNaN , 2.0 );
317318 } else if (bar_index_ == 1 ) {
@@ -355,7 +356,7 @@ class PyramidEntryFeeLifecycleProbe : public BacktestEngine {
355356// With a 2x FX rollover, repricing the old 10% entry fee would manufacture a
356357// broker-open deficit and an 0.08-contract margin row. The paid rate-1 fee
357358// leaves the carried 2.75-contract position affordable.
358- class CarriedEntryFeeSnapshotProbe : public BacktestEngine {
359+ class CarriedEntryFeeSnapshotProbe : public pineforge ::source::PineStrategyHost {
359360public:
360361 CarriedEntryFeeSnapshotProbe () {
361362 initial_capital_ = 600.0 ;
@@ -366,7 +367,7 @@ class CarriedEntryFeeSnapshotProbe : public BacktestEngine {
366367 qty_step_ = 0.01 ;
367368 process_orders_on_close_ = true ;
368369 }
369- void on_bar (const Bar& /* bar*/ ) override {
370+ void on_source_bar (const Bar& /* bar*/ ) override {
370371 if (bar_index_ == 0 ) {
371372 strategy_entry (" L" , true , kNaN , kNaN , 2.75 );
372373 } else if (bar_index_ == 1 ) {
@@ -385,7 +386,7 @@ class CarriedEntryFeeSnapshotProbe : public BacktestEngine {
385386// Post-fill affordability must sum each live slice's paid fee: rate-1 L1 costs
386387// 20 and rate-2 L2 costs 10. Repricing both at rate 2 would use 50 instead of
387388// 30 and manufacture a margin trim from an otherwise affordable position.
388- class PostFillEntryFeeSnapshotProbe : public BacktestEngine {
389+ class PostFillEntryFeeSnapshotProbe : public pineforge ::source::PineStrategyHost {
389390public:
390391 PostFillEntryFeeSnapshotProbe () {
391392 initial_capital_ = 540.0 ;
@@ -397,7 +398,7 @@ class PostFillEntryFeeSnapshotProbe : public BacktestEngine {
397398 process_orders_on_close_ = true ;
398399 pyramiding_ = 2 ;
399400 }
400- void on_bar (const Bar& /* bar*/ ) override {
401+ void on_source_bar (const Bar& /* bar*/ ) override {
401402 if (bar_index_ == 0 ) {
402403 strategy_entry (" L1" , true , kNaN , kNaN , 2.0 );
403404 } else if (bar_index_ == 1 ) {
@@ -816,7 +817,7 @@ int main() {
816817 };
817818 const int64_t timestamps[] = {1000 , 2000 };
818819 const double rates[] = {1.0 , 1.001 };
819- class FlatEpochShortProbe : public BacktestEngine {
820+ class FlatEpochShortProbe : public pineforge ::source::PineStrategyHost {
820821 public:
821822 FlatEpochShortProbe () {
822823 initial_capital_ = 10000.0 ;
@@ -829,7 +830,7 @@ int main() {
829830 qty_step_ = 0.1 ;
830831 process_orders_on_close_ = false ;
831832 }
832- void on_bar (const Bar& /* bar*/ ) override {
833+ void on_source_bar (const Bar& /* bar*/ ) override {
833834 if (bar_index_ == 0 ) {
834835 strategy_entry (" S" , /* is_long=*/ false );
835836 } else if (bar_index_ == 1 ) {
0 commit comments