pub struct TrailingStopState {
pub highest_since_entry: f64,
pub lowest_since_entry: f64,
pub current_stop: f64,
pub direction: TrailingDirection,
pub active: bool,
}Expand description
State for a trailing stop attached to an open position.
Fields§
§highest_since_entry: f64§lowest_since_entry: f64§current_stop: f64§direction: TrailingDirection§active: boolImplementations§
Source§impl TrailingStopState
impl TrailingStopState
Sourcepub fn new(entry_price: f64, direction: TrailingDirection) -> Self
pub fn new(entry_price: f64, direction: TrailingDirection) -> Self
Create a new trailing stop state at the given entry price.
Sourcepub fn update(&mut self, current_price: f64, atr: f64, multiplier: f64)
pub fn update(&mut self, current_price: f64, atr: f64, multiplier: f64)
Update the trailing stop with the latest price and ATR.
For longs: track highest, stop = highest − multiplier × ATR For shorts: track lowest, stop = lowest + multiplier × ATR
Sourcepub fn is_triggered(&self, current_price: f64) -> bool
pub fn is_triggered(&self, current_price: f64) -> bool
Check whether the trailing stop has been triggered.
Trait Implementations§
Source§impl Clone for TrailingStopState
impl Clone for TrailingStopState
Source§fn clone(&self) -> TrailingStopState
fn clone(&self) -> TrailingStopState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TrailingStopState
impl Debug for TrailingStopState
Source§impl<'de> Deserialize<'de> for TrailingStopState
impl<'de> Deserialize<'de> for TrailingStopState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TrailingStopState
impl RefUnwindSafe for TrailingStopState
impl Send for TrailingStopState
impl Sync for TrailingStopState
impl Unpin for TrailingStopState
impl UnsafeUnpin for TrailingStopState
impl UnwindSafe for TrailingStopState
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