pub struct YoyoExit { /* private fields */ }Expand description
Yo-Yo Exit — an ATR-based long-only trailing stop that “yo-yos” in and out
of the market: when price closes below the trail it exits, and when price
recovers multiplier · ATR above the same trail it re-enters long. The
emitted level is always the trail itself (not a flip-to-short stop), so a
consumer reads a single line on the chart and toggles the position
depending on which side of it the close sits.
band = multiplier · ATR
in-trade: trail_t = max(trail_{t−1}, close − band)
exit when close < trail
out: trail held flat at the last in-trade level
re-enter when close > trail + bandUnlike AtrTrailingStop — which always flips to
the opposite side — the Yo-Yo only takes longs and treats the off-period
as a “wait until price proves itself again” phase. A common configuration
is ATR(14) with a 2.0 multiplier.
§Example
use wickra_core::{Candle, Indicator, YoyoExit};
let mut indicator = YoyoExit::new(14, 2.0).unwrap();
let mut last = None;
for i in 0..80 {
let base = 100.0 + f64::from(i);
let candle =
Candle::new(base, base + 2.0, base - 2.0, base + 1.0, 10.0, i64::from(i)).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl YoyoExit
impl YoyoExit
Sourcepub fn new(atr_period: usize, multiplier: f64) -> Result<YoyoExit, Error>
pub fn new(atr_period: usize, multiplier: f64) -> Result<YoyoExit, Error>
Construct a Yo-Yo Exit with an explicit ATR period and band multiplier.
§Errors
Returns Error::PeriodZero if atr_period == 0 and
Error::NonPositiveMultiplier if multiplier is not strictly
positive and finite.
Trait Implementations§
Source§impl Indicator for YoyoExit
impl Indicator for YoyoExit
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> Option<f64>
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 YoyoExit
impl RefUnwindSafe for YoyoExit
impl Send for YoyoExit
impl Sync for YoyoExit
impl Unpin for YoyoExit
impl UnsafeUnpin for YoyoExit
impl UnwindSafe for YoyoExit
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