pub struct ProjectionBands { /* private fields */ }Expand description
Projection Bands: forward-projected high/low envelope.
Mel Widner (“Projection Bands and the Projection Oscillator”, Technical
Analysis of Stocks & Commodities, May 1995) fits a separate linear
regression to the highs and to the lows over the last period bars, then
slides every bar’s high and low forward to the current bar along its own
slope. The upper band is the maximum of the projected highs, the lower band
the minimum of the projected lows:
slope_h = OLS slope of (x, high) over the window
slope_l = OLS slope of (x, low) over the window
// bar i (0 = oldest, period-1 = newest) is (period-1-i) bars in the past
upper = max over i of [ high_i + slope_h · (period-1-i) ]
lower = min over i of [ low_i + slope_l · (period-1-i) ]
middle = (upper + lower) / 2Unlike LinRegChannel and
StandardErrorBands — which wrap a single
close-regression endpoint by a dispersion statistic — Projection Bands are
built from the extremes: the envelope adapts to the trend’s slope yet
always contains every projected high and low, so by construction price never
pierces the bands within the window. A flat slope reduces the bands to the
rolling highest-high / lowest-low (a Donchian channel); a steep slope tilts
the whole envelope with the trend.
§Example
use wickra_core::{Candle, Indicator, ProjectionBands};
let mut indicator = ProjectionBands::new(14).unwrap();
let mut last = None;
for i in 0..30 {
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§
Trait Implementations§
Source§impl Clone for ProjectionBands
impl Clone for ProjectionBands
Source§fn clone(&self) -> ProjectionBands
fn clone(&self) -> ProjectionBands
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 ProjectionBands
impl Debug for ProjectionBands
Source§impl Indicator for ProjectionBands
impl Indicator for ProjectionBands
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = ProjectionBandsOutput
type Output = ProjectionBandsOutput
Source§fn update(&mut self, candle: Candle) -> Option<ProjectionBandsOutput>
fn update(&mut self, candle: Candle) -> Option<ProjectionBandsOutput>
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 ProjectionBands
impl RefUnwindSafe for ProjectionBands
impl Send for ProjectionBands
impl Sync for ProjectionBands
impl Unpin for ProjectionBands
impl UnsafeUnpin for ProjectionBands
impl UnwindSafe for ProjectionBands
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