pub struct AtrRatchet { /* private fields */ }Expand description
ATR Ratchet — Perry Kaufman’s time-based volatility stop that tightens by a fixed fraction of ATR every bar, whether or not price moves.
on entry (long): stop = close − start_mult · ATR
each later bar: stop = stop + increment · ATR (ratchets toward price)
flip to short when close < stop, reseeding stop = close + start_mult · ATRMost trailing stops only move when price makes a new extreme. Kaufman’s ratchet
instead advances the stop a little each bar — increment · ATR — so a trade
that stalls is squeezed out over time even in a flat market. The initial
distance (start_mult · ATR) gives the position room to breathe; the per-bar
increment controls how aggressively the leash shortens. When price closes
through the stop the system reverses and reseeds at the full initial distance.
The first stop lands once ATR is ready (atr_period inputs). Each update is
O(1).
§Example
use wickra_core::{Candle, Indicator, AtrRatchet};
let mut indicator = AtrRatchet::new(14, 4.0, 0.1).unwrap();
let mut last = None;
for i in 0..60 {
let base = 100.0 + f64::from(i);
let c = Candle::new(base, base + 2.0, base - 2.0, base + 1.0, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl AtrRatchet
impl AtrRatchet
Sourcepub fn new(atr_period: usize, start_mult: f64, increment: f64) -> Result<Self>
pub fn new(atr_period: usize, start_mult: f64, increment: f64) -> Result<Self>
Construct an ATR Ratchet stop.
§Errors
Returns Error::PeriodZero if atr_period == 0 and
Error::NonPositiveMultiplier if start_mult or increment is not
finite and positive.
Sourcepub const fn params(&self) -> (usize, f64, f64)
pub const fn params(&self) -> (usize, f64, f64)
Configured (atr_period, start_mult, increment).
Sourcepub const fn value(&self) -> Option<AtrRatchetOutput>
pub const fn value(&self) -> Option<AtrRatchetOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for AtrRatchet
impl Clone for AtrRatchet
Source§fn clone(&self) -> AtrRatchet
fn clone(&self) -> AtrRatchet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AtrRatchet
impl Debug for AtrRatchet
Source§impl Indicator for AtrRatchet
impl Indicator for AtrRatchet
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = AtrRatchetOutput
type Output = AtrRatchetOutput
Source§fn update(&mut self, candle: Candle) -> Option<AtrRatchetOutput>
fn update(&mut self, candle: Candle) -> Option<AtrRatchetOutput>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for AtrRatchet
impl RefUnwindSafe for AtrRatchet
impl Send for AtrRatchet
impl Sync for AtrRatchet
impl Unpin for AtrRatchet
impl UnsafeUnpin for AtrRatchet
impl UnwindSafe for AtrRatchet
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>>
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
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>
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>
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