Strategies¶
Strategies implement decision logic and are called by the engine through StrategyContext. Built-in strategies are registered in src/strategy/strategies/register_builtin.cpp and are created through strategy::StrategyFactory.
Strategy Lifecycle¶
initialize(ctx)is called once at startup.on_start()andon_stop()are called when the engine starts or stops.- Market callbacks:
on_bar,on_tick,on_order_book,on_quote. - Execution callbacks:
on_order_update,on_fill. - Regime callback:
on_regime_change. - Utility callbacks:
on_end_of_day,on_timer.
Built-In Strategies¶
buy_and_hold¶
Parameters:
symboloptional fixed symbol. If empty, the first bar’s symbol is used.quantityorder size. If<= 0, defaults to 1 when no position exists.
moving_average_cross¶
Parameters:
fast_periodinteger, default 10.slow_periodinteger, default 30. Iffast_period >= slow_period, slow is set tofast_period + 1.quantityorder size. If<= 0, defaults to 1.
pairs_trading¶
Parameters:
symbol_aandsymbol_brequired symbols.lookbackinteger, minimum 30.entry_zdouble, minimum 0.5.exit_zdouble, minimum 0.1.max_zdouble, minimumentry_z.allow_shortboolean.base_qtyinteger, minimum 1.min_qty_scaledouble, minimum 0.1.max_qty_scaledouble, minimummin_qty_scale.cooldown_barsinteger, minimum 0.
harmonic_pattern¶
Parameters:
symbolrequired symbol.pivot_threshold_pctminimum 0.001.tolerancerange 0.0 to 0.5.min_barsinteger, minimum 30.cooldown_barsinteger, minimum 0.use_limitboolean.limit_offset_bpsdouble, minimum 0.0.vol_threshold_pctdouble, minimum 0.0.min_confidencerange 0.0 to 1.0.min_qty_scaledouble, minimum 0.1.max_qty_scaledouble, minimummin_qty_scale.aggressive_confidence_thresholdrange 0.0 to 1.0.venue_switch_confidencerange 0.0 to 1.0.passive_venue_weightrange 0.0 to 1.0.aggressive_venue_weightrange 0.0 to 1.0.allow_shortboolean.order_qtyinteger, minimum 1.
Python Strategies¶
Python strategies must subclass regimeflow.Strategy and implement the same callbacks. You can pass the strategy class via module:Class in the CLI.
Example:
.venv/bin/python -m regimeflow.cli \
--config quickstart.yaml \
--strategy my_strategies:MyStrategy
Next Steps¶
guide/regime-detection.mdguide/risk-management.mdreference/configuration.md