pub trait Condition:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn evaluate(&self, ctx: &StrategyContext<'_>) -> bool;
fn required_indicators(&self) -> Vec<(String, Indicator)>;
fn description(&self) -> String;
// Provided methods
fn htf_requirements(&self) -> Vec<HtfIndicatorSpec> { ... }
fn and<C: Condition>(self, other: C) -> And<Self, C>
where Self: Sized { ... }
fn or<C: Condition>(self, other: C) -> Or<Self, C>
where Self: Sized { ... }
fn not(self) -> Not<Self>
where Self: Sized { ... }
}Expand description
A condition that can be evaluated on each candle.
Conditions are the building blocks of trading strategies.
They can be combined using and(), or(), and not() operations.
§Example
use finance_query::backtesting::condition::Condition;
fn my_custom_condition(ctx: &StrategyContext) -> bool {
// Custom logic here
true
}Required Methods§
Sourcefn evaluate(&self, ctx: &StrategyContext<'_>) -> bool
fn evaluate(&self, ctx: &StrategyContext<'_>) -> bool
Evaluate the condition with the current strategy context.
Returns true if the condition is met, false otherwise.
Sourcefn required_indicators(&self) -> Vec<(String, Indicator)>
fn required_indicators(&self) -> Vec<(String, Indicator)>
Get the indicators required by this condition.
The backtest engine will pre-compute these indicators before running the strategy.
Sourcefn description(&self) -> String
fn description(&self) -> String
Get a human-readable description of this condition.
This is used for logging, debugging, and signal reporting.
Provided Methods§
Sourcefn htf_requirements(&self) -> Vec<HtfIndicatorSpec>
fn htf_requirements(&self) -> Vec<HtfIndicatorSpec>
Get any higher-timeframe indicators required by this condition.
The engine resamples candles to each unique interval, computes the
listed indicators on the resampled data, and stores stretched
(base-timeframe-length) arrays in StrategyContext::indicators
under the htf_key names. HtfCondition
implements this automatically; all other conditions return vec![].
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.