Skip to main content

egui_charts/strategies/
mod.rs

1//! Strategies over historical and live bars, and the [`Backtest`] engine that runs them.
2//!
3//! A [`Strategy`] computes the studies it needs once, then decides on each closed bar by placing
4//! named entry and exit orders through a [`StrategyContext`]. [`Backtest::run`] fills those orders
5//! along each bar's price path and returns a [`StrategyReport`](crate::model::StrategyReport), so
6//! the report's metrics, its panel and its CSV export work on the result. Needs no egui, so a
7//! server can run the same code.
8//!
9//! [`StrategyFactory`] supplies ten price-action strategies and, with `studies`, twelve
10//! strategies using the chart studies' public values. Hosts can register their own constructors.
11//! Use [`Strategy::study_inputs`] and [`Strategy::set_input`] to edit bounded parameters before
12//! a run. Gap and inside/outside strategies take the host instrument's `tick_size` input; their
13//! exits are distances from the actual position fill price. The engine's settings supply size
14//! and pyramiding. Built-ins ignore fill callbacks; live tick recalculation follows the run settings.
15//!
16//! [`Backtest::update`] retains the execution state as the host appends bars or changes the
17//! forming bar, and returns [`StrategyFill`] events. [`Backtest::report`] exposes its report.
18//! Feed those events to `services::AlertEngine::strategy_fills` with both engine features enabled.
19//!
20//! [`optimise`] runs a lazy grid of input combinations on fresh strategies and yields each
21//! combination's [`StrategyTrial`], using the same bars and backtest settings throughout.
22
23mod backtest;
24mod library;
25mod optimize;
26
27pub use library::StrategyFactory;
28pub use optimize::{StrategyTrial, optimise};
29
30pub use backtest::{
31    Backtest, BacktestSettings, Commission, OrderSize, Slippage, Strategy, StrategyContext,
32    StrategyFill,
33};