pub struct KaseDevStop { /* private fields */ }Expand description
Kase DevStop — Cynthia Kase’s volatility stop, built on the standard
deviation of the two-bar true range rather than a single-bar ATR.
DTR_t = max(high_t, high_{t−1}) − min(low_t, low_{t−1}) (two-bar range)
band = mean(DTR, period) + dev · stddev(DTR, period)
long stop = ratchet_up( highest_high_since_flip − band )
short stop = ratchet_down( lowest_low_since_flip + band )Kase observed that range expansion is better captured by a two-bar range than
a one-bar one, and that subtracting a standard-deviation band (not a fixed
ATR multiple) adapts the stop to changing volatility. The stop trails the
extreme reached since the last reversal — ratcheting only in the trend’s favour
— and flips sides when price closes through it. dev selects which DevStop
line to follow (1, 2 or 3 standard deviations are Kase’s warning lines).
The first bar seeds the prior candle; the next period two-bar ranges seed the
mean and standard deviation, so the first stop lands after period + 1 inputs.
Each update is O(1).
§Example
use wickra_core::{Candle, Indicator, KaseDevStop};
let mut indicator = KaseDevStop::new(30, 1.0).unwrap();
let mut last = None;
for i in 0..80 {
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 KaseDevStop
impl KaseDevStop
Sourcepub fn new(period: usize, dev: f64) -> Result<Self>
pub fn new(period: usize, dev: f64) -> Result<Self>
Construct a Kase DevStop with the given lookback period and
standard-deviation multiplier dev.
§Errors
Returns Error::InvalidPeriod if period < 2 (a standard deviation
needs at least two samples) and Error::NonPositiveMultiplier if dev
is not finite and positive.
Sourcepub const fn value(&self) -> Option<KaseDevStopOutput>
pub const fn value(&self) -> Option<KaseDevStopOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for KaseDevStop
impl Clone for KaseDevStop
Source§fn clone(&self) -> KaseDevStop
fn clone(&self) -> KaseDevStop
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 KaseDevStop
impl Debug for KaseDevStop
Source§impl Indicator for KaseDevStop
impl Indicator for KaseDevStop
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = KaseDevStopOutput
type Output = KaseDevStopOutput
Source§fn update(&mut self, candle: Candle) -> Option<KaseDevStopOutput>
fn update(&mut self, candle: Candle) -> Option<KaseDevStopOutput>
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 KaseDevStop
impl RefUnwindSafe for KaseDevStop
impl Send for KaseDevStop
impl Sync for KaseDevStop
impl Unpin for KaseDevStop
impl UnsafeUnpin for KaseDevStop
impl UnwindSafe for KaseDevStop
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