pub struct Nrtr { /* private fields */ }Expand description
NRTR (Nick Rypock Trailing Reverse) — a percentage trailing-reverse stop that follows the trend extreme and flips when price retraces by a fixed percentage.
uptrend: high_water = max(high_water, close)
line = high_water · (1 − pct/100)
flip down when close < line (reseed low_water = close)
downtrend: low_water = min(low_water, close)
line = low_water · (1 + pct/100)
flip up when close > line (reseed high_water = close)Unlike volatility stops (ATR, σ-of-range), NRTR uses a pure percentage
retracement: the line trails the highest close reached in the up-leg at a
fixed pct below it, and a close that gives back that percentage reverses the
trend, handing the line to the opposite extreme. This makes it scale-free and
trivially tunable — one number sets how much retracement you tolerate. It
differs from a fixed percentage stop-loss in that it reverses (tracks
both directions) rather than just exiting.
The first bar seeds the up-trend and emits a line immediately. Each update is
O(1).
§Example
use wickra_core::{Candle, Indicator, Nrtr};
let mut indicator = Nrtr::new(2.0).unwrap();
let mut last = None;
for i in 0..40 {
let close = 100.0 + f64::from(i);
let c = Candle::new(close, close + 0.5, close - 0.5, close, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Indicator for Nrtr
impl Indicator for Nrtr
Source§type Input = Candle
type Input = Candle
Type of one input data point (typically
f64 for a price, or Candle / Tick).Source§type Output = NrtrOutput
type Output = NrtrOutput
Type of one output value.
Source§fn update(&mut self, candle: Candle) -> Option<NrtrOutput>
fn update(&mut self, candle: Candle) -> Option<NrtrOutput>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for Nrtr
impl RefUnwindSafe for Nrtr
impl Send for Nrtr
impl Sync for Nrtr
impl Unpin for Nrtr
impl UnsafeUnpin for Nrtr
impl UnwindSafe for Nrtr
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>>
Run the indicator over a slice of inputs in order, returning one output (or
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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