pub struct StrategyBuilder<E = (), X = ()> { /* private fields */ }Expand description
Builder for creating custom strategies with entry/exit conditions.
The builder enforces that both entry and exit conditions are provided before a strategy can be built.
An optional regime filter can be set at any point in the chain via
.regime_filter(). When set, the filter
is evaluated on every bar; if it returns false, all entry signals are
suppressed. Exit signals are never blocked by the regime filter.
Implementations§
Source§impl StrategyBuilder<(), ()>
impl StrategyBuilder<(), ()>
Source§impl<X> StrategyBuilder<(), X>
impl<X> StrategyBuilder<(), X>
Source§impl<E> StrategyBuilder<E, ()>
impl<E> StrategyBuilder<E, ()>
Source§impl<E, X> StrategyBuilder<E, X>
impl<E, X> StrategyBuilder<E, X>
Sourcepub fn regime_filter<C: Condition>(self, condition: C) -> Self
pub fn regime_filter<C: Condition>(self, condition: C) -> Self
Set a market regime filter.
When set, entry signals (long and short) are suppressed on any bar
where the filter evaluates to false. Exit signals are never
blocked by the regime filter, ensuring open positions can always be
closed regardless of market conditions.
The regime filter’s indicators are included in required_indicators()
and therefore pre-computed by the engine like any other indicator.
§Example
use finance_query::backtesting::strategy::StrategyBuilder;
use finance_query::backtesting::refs::*;
// Only trade when price is above the 200-period SMA
let strategy = StrategyBuilder::new("Trend Following")
.regime_filter(sma(200).above_ref(sma(400)))
.entry(ema(10).crosses_above_ref(ema(30)))
.exit(ema(10).crosses_below_ref(ema(30)))
.build();Source§impl<E: Condition, X: Condition> StrategyBuilder<E, X>
impl<E: Condition, X: Condition> StrategyBuilder<E, X>
Sourcepub fn with_short<SE: Condition, SX: Condition>(
self,
entry: SE,
exit: SX,
) -> Self
pub fn with_short<SE: Condition, SX: Condition>( self, entry: SE, exit: SX, ) -> Self
Sourcepub fn warmup(self, bars: usize) -> Self
pub fn warmup(self, bars: usize) -> Self
Override the automatic warmup period with an explicit bar count.
By default the warmup period is inferred from each indicator’s
Indicator::warmup_bars() method. Use this override when the
automatic value doesn’t match your specific needs.
§Example
let strategy = StrategyBuilder::new("MACD + RSI")
.entry(macd(12, 26, 9).crosses_above_zero())
.exit(rsi(14).crosses_above(70.0))
.warmup(36) // explicit override
.build();Sourcepub fn build(self) -> CustomStrategy<E, X>
pub fn build(self) -> CustomStrategy<E, X>
Auto Trait Implementations§
impl<E, X> Freeze for StrategyBuilder<E, X>
impl<E = (), X = ()> !RefUnwindSafe for StrategyBuilder<E, X>
impl<E, X> Send for StrategyBuilder<E, X>
impl<E, X> Sync for StrategyBuilder<E, X>
impl<E, X> Unpin for StrategyBuilder<E, X>
impl<E, X> UnsafeUnpin for StrategyBuilder<E, X>where
E: UnsafeUnpin,
X: UnsafeUnpin,
impl<E = (), X = ()> !UnwindSafe for StrategyBuilder<E, X>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more