#[non_exhaustive]pub struct StrategyContext<'a> {
pub candles: &'a [Candle],
pub index: usize,
pub position: Option<&'a Position>,
pub equity: f64,
pub indicators: &'a HashMap<String, Vec<Option<f64>>>,
}Expand description
Context passed to strategy on each candle.
Provides access to historical data, current position, and pre-computed indicators.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.candles: &'a [Candle]All candles up to and including current
index: usizeCurrent candle index (0-based)
position: Option<&'a Position>Current position (if any)
equity: f64Current portfolio equity
indicators: &'a HashMap<String, Vec<Option<f64>>>Pre-computed indicator values (keyed by indicator name)
Implementations§
Source§impl<'a> StrategyContext<'a>
impl<'a> StrategyContext<'a>
Sourcepub fn current_candle(&self) -> &Candle
pub fn current_candle(&self) -> &Candle
Get current candle
Sourcepub fn previous_candle(&self) -> Option<&Candle>
pub fn previous_candle(&self) -> Option<&Candle>
Get previous candle (None if at start)
Sourcepub fn candle_at(&self, index: usize) -> Option<&Candle>
pub fn candle_at(&self, index: usize) -> Option<&Candle>
Get candle at specific index (None if out of bounds)
Sourcepub fn indicator_at(&self, name: &str, index: usize) -> Option<f64>
pub fn indicator_at(&self, name: &str, index: usize) -> Option<f64>
Get indicator value at specific index
Sourcepub fn indicator_prev(&self, name: &str) -> Option<f64>
pub fn indicator_prev(&self, name: &str) -> Option<f64>
Get indicator value at previous index
Sourcepub fn has_position(&self) -> bool
pub fn has_position(&self) -> bool
Check if we have a position
Sourcepub fn crossed_above(&self, fast_name: &str, slow_name: &str) -> bool
pub fn crossed_above(&self, fast_name: &str, slow_name: &str) -> bool
Check if crossover occurred (fast crosses above slow)
Sourcepub fn crossed_below(&self, fast_name: &str, slow_name: &str) -> bool
pub fn crossed_below(&self, fast_name: &str, slow_name: &str) -> bool
Check if crossover occurred (fast crosses below slow)
Sourcepub fn indicator_crossed_above(&self, name: &str, threshold: f64) -> bool
pub fn indicator_crossed_above(&self, name: &str, threshold: f64) -> bool
Check if indicator crossed above a threshold
Sourcepub fn indicator_crossed_below(&self, name: &str, threshold: f64) -> bool
pub fn indicator_crossed_below(&self, name: &str, threshold: f64) -> bool
Check if indicator crossed below a threshold
Auto Trait Implementations§
impl<'a> Freeze for StrategyContext<'a>
impl<'a> RefUnwindSafe for StrategyContext<'a>
impl<'a> Send for StrategyContext<'a>
impl<'a> Sync for StrategyContext<'a>
impl<'a> Unpin for StrategyContext<'a>
impl<'a> UnsafeUnpin for StrategyContext<'a>
impl<'a> UnwindSafe for StrategyContext<'a>
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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