pub struct ModifiedMaStop { /* private fields */ }Expand description
Modified-MA Stop — a trailing stop whose line is the Modified Moving Average (SMMA / Wilder’s RMA) of price, allowed to move only in the trend’s favour.
ma = SMMA(close, period) (Modified Moving Average)
long: stop = max(prev_stop, ma); flip short when close < stop
short: stop = min(prev_stop, ma); flip long when close > stopThe Modified Moving Average (also called the smoothed or running moving average) is the slow, low-lag average Wilder used throughout his systems. Using it directly as a trailing line — but ratcheting so the long stop never falls and the short stop never rises — turns the smooth average into a stop that hugs price in a trend and flips when price decisively crosses it. Because the SMMA lags, the stop gives trends room while still exiting clean reversals.
The first stop lands once the SMMA is ready (period inputs). Each update is
O(1).
§Example
use wickra_core::{Candle, Indicator, ModifiedMaStop};
let mut indicator = ModifiedMaStop::new(14).unwrap();
let mut last = None;
for i in 0..60 {
let base = 100.0 + f64::from(i);
let c = Candle::new(base, base + 1.0, base - 1.0, base + 0.5, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl ModifiedMaStop
impl ModifiedMaStop
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct a Modified-MA stop with the given SMMA period.
§Errors
Returns Error::PeriodZero if period == 0.
Sourcepub const fn value(&self) -> Option<ModifiedMaStopOutput>
pub const fn value(&self) -> Option<ModifiedMaStopOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for ModifiedMaStop
impl Clone for ModifiedMaStop
Source§fn clone(&self) -> ModifiedMaStop
fn clone(&self) -> ModifiedMaStop
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 ModifiedMaStop
impl Debug for ModifiedMaStop
Source§impl Indicator for ModifiedMaStop
impl Indicator for ModifiedMaStop
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = ModifiedMaStopOutput
type Output = ModifiedMaStopOutput
Source§fn update(&mut self, candle: Candle) -> Option<ModifiedMaStopOutput>
fn update(&mut self, candle: Candle) -> Option<ModifiedMaStopOutput>
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 ModifiedMaStop
impl RefUnwindSafe for ModifiedMaStop
impl Send for ModifiedMaStop
impl Sync for ModifiedMaStop
impl Unpin for ModifiedMaStop
impl UnsafeUnpin for ModifiedMaStop
impl UnwindSafe for ModifiedMaStop
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