pub struct RenkoTrailingStop { /* private fields */ }Expand description
Renko Trailing Stop — a trailing stop that follows a Renko-style brick
anchor: the stop only moves when price has advanced (or fallen) by at least
one full block_size, and then jumps the same fixed distance.
long: advance = floor((close − anchor) / block_size)
if advance ≥ 1 -> anchor += advance · block_size
stop = anchor − block_size
flip-to-short on close < stop -> anchor = close, stop = anchor + block_size
short: advance = floor((anchor − close) / block_size)
if advance ≥ 1 -> anchor −= advance · block_size
stop = anchor + block_size
flip-to-long on close > stop -> anchor = close, stop = anchor − block_sizeLike a Renko chart the stop ignores intra-block noise — it sits one full block behind the last “printed” brick and only ratchets in whole-block increments. The first input seeds a long anchor at the close.
§Example
use wickra_core::{Indicator, RenkoTrailingStop};
let mut indicator = RenkoTrailingStop::new(1.0).unwrap();
let mut last = None;
for i in 0..20 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl RenkoTrailingStop
impl RenkoTrailingStop
Sourcepub fn new(block_size: f64) -> Result<Self>
pub fn new(block_size: f64) -> Result<Self>
Construct a Renko Trailing Stop with an explicit block size.
§Errors
Returns Error::NonPositiveMultiplier if block_size is not strictly
positive and finite.
Sourcepub const fn block_size(&self) -> f64
pub const fn block_size(&self) -> f64
Configured block size.
Trait Implementations§
Source§impl Clone for RenkoTrailingStop
impl Clone for RenkoTrailingStop
Source§fn clone(&self) -> RenkoTrailingStop
fn clone(&self) -> RenkoTrailingStop
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 RenkoTrailingStop
impl Debug for RenkoTrailingStop
Source§impl Indicator for RenkoTrailingStop
impl Indicator for RenkoTrailingStop
Source§fn update(&mut self, close: f64) -> Option<f64>
fn update(&mut self, close: f64) -> 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 RenkoTrailingStop
impl RefUnwindSafe for RenkoTrailingStop
impl Send for RenkoTrailingStop
impl Sync for RenkoTrailingStop
impl Unpin for RenkoTrailingStop
impl UnsafeUnpin for RenkoTrailingStop
impl UnwindSafe for RenkoTrailingStop
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