pub struct ElderSafeZone { /* private fields */ }Expand description
Elder SafeZone Stop — Alexander Elder’s stop placed a multiple of the
average market noise away from price.
long market noise = average downside penetration = mean( prev_low − low | low < prev_low )
short market noise = average upside penetration = mean( high − prev_high | high > prev_high )
long stop = ratchet_up( low_t − coeff · avg_down_penetration )
short stop = ratchet_down( high_t + coeff · avg_up_penetration )Elder defines noise in an uptrend as the part of each bar that pokes below
the previous bar’s low (a “downside penetration”). Averaging those
penetrations over a lookback and placing the stop coeff multiples below the
current low keeps the stop just outside normal pullbacks while still exiting on
a genuine reversal. The stop trails in the trend’s favour and flips when price
closes through it. The average uses only the bars that actually penetrated
(Elder’s definition), so a noiseless trend gives a tight stop at the bar’s
extreme.
The first bar seeds the prior candle; the next period bars accumulate the
penetration statistics, so the first stop lands after period + 1 inputs.
Each update is O(1).
§Example
use wickra_core::{Candle, Indicator, ElderSafeZone};
let mut indicator = ElderSafeZone::new(14, 2.0).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 ElderSafeZone
impl ElderSafeZone
Sourcepub fn new(period: usize, coeff: f64) -> Result<Self>
pub fn new(period: usize, coeff: f64) -> Result<Self>
Construct an Elder SafeZone stop with the given averaging period and
noise coefficient.
§Errors
Returns Error::PeriodZero if period == 0 and
Error::NonPositiveMultiplier if coeff is not finite and positive.
Sourcepub const fn value(&self) -> Option<ElderSafeZoneOutput>
pub const fn value(&self) -> Option<ElderSafeZoneOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for ElderSafeZone
impl Clone for ElderSafeZone
Source§fn clone(&self) -> ElderSafeZone
fn clone(&self) -> ElderSafeZone
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 ElderSafeZone
impl Debug for ElderSafeZone
Source§impl Indicator for ElderSafeZone
impl Indicator for ElderSafeZone
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = ElderSafeZoneOutput
type Output = ElderSafeZoneOutput
Source§fn update(&mut self, candle: Candle) -> Option<ElderSafeZoneOutput>
fn update(&mut self, candle: Candle) -> Option<ElderSafeZoneOutput>
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 ElderSafeZone
impl RefUnwindSafe for ElderSafeZone
impl Send for ElderSafeZone
impl Sync for ElderSafeZone
impl Unpin for ElderSafeZone
impl UnsafeUnpin for ElderSafeZone
impl UnwindSafe for ElderSafeZone
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