pub struct TimeBasedStop { /* private fields */ }Expand description
Time-Based Stop — exits a position purely on elapsed bars, independent of price.
bars_held increments by 1 each bar (since the last reset)
progress = min(bars_held / max_bars, 1.0) in [0, 1]
stop fires when progress == 1.0 (bars_held >= max_bars)Some setups should not be given unlimited time to work: a mean-reversion entry
that has not reverted within max_bars, or an event trade whose catalyst has
passed, is best closed regardless of price. This indicator is a pure timer —
it ignores the candle’s prices entirely and reports the fraction of the
holding window that has elapsed, reaching 1.0 (the stop) after max_bars
bars. Call reset on each new entry so the timer
restarts from the position open.
Each update is O(1) and the first bar already emits a value
(1 / max_bars).
§Example
use wickra_core::{Candle, Indicator, TimeBasedStop};
let mut indicator = TimeBasedStop::new(5).unwrap();
let c = Candle::new(100.0, 101.0, 99.0, 100.0, 1.0, 0).unwrap();
// Five bars reach the stop.
let mut last = 0.0;
for _ in 0..5 {
last = indicator.update(c).unwrap();
}
assert_eq!(last, 1.0);Implementations§
Trait Implementations§
Source§impl Clone for TimeBasedStop
impl Clone for TimeBasedStop
Source§fn clone(&self) -> TimeBasedStop
fn clone(&self) -> TimeBasedStop
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 TimeBasedStop
impl Debug for TimeBasedStop
Source§impl Indicator for TimeBasedStop
impl Indicator for TimeBasedStop
Source§type Input = Candle
type Input = Candle
Type of one input data point (typically
f64 for a price, or Candle / Tick).Source§fn update(&mut self, _candle: Candle) -> Option<f64>
fn update(&mut self, _candle: Candle) -> Option<f64>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for TimeBasedStop
impl RefUnwindSafe for TimeBasedStop
impl Send for TimeBasedStop
impl Sync for TimeBasedStop
impl Unpin for TimeBasedStop
impl UnsafeUnpin for TimeBasedStop
impl UnwindSafe for TimeBasedStop
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
Run the indicator over a slice of inputs in order, returning one output (or
None during warmup) per input.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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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