pub struct AndrewsPitchfork { /* private fields */ }Expand description
Andrews Pitchfork — Alan Andrews’ median-line tool drawn from the three most recent swing pivots, projected forward to the current bar.
detect alternating swing highs/lows with a `strength`-bar fractal
P0 = handle (oldest of the last three), P1, P2 = the next two
M = midpoint of P1 and P2
median(t) = P0 + slope·(t − t0) slope = (M − P0) / (M_t − t0)
upper / lower = median(t) offset by the vertical gap to the higher / lower anchorThe pitchfork projects a “fork” of three parallel lines: a central median
line drawn from a starting pivot through the midpoint of a later swing, plus
two parallels passing through that swing’s high and low. Price tends to
oscillate around the median line and find support/resistance at the parallels.
This streaming version detects the pivots automatically with a symmetric
fractal of half-width strength (so each pivot is confirmed strength bars
late) and keeps the three most recent alternating swings.
Because it depends on swing structure, readiness is data-dependent: the
first output appears once three alternating pivots have been confirmed.
warmup_period returns the minimum bars to confirm a single pivot. Each
update is O(strength).
§Example
use wickra_core::{Candle, Indicator, AndrewsPitchfork};
let mut indicator = AndrewsPitchfork::new(2).unwrap();
let mut last = None;
for i in 0..120 {
let base = 100.0 + (f64::from(i) * 0.4).sin() * 10.0;
let c = Candle::new(base, base + 1.0, base - 1.0, base, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
// A swinging series eventually establishes a pitchfork.
let _ = last;Implementations§
Source§impl AndrewsPitchfork
impl AndrewsPitchfork
Sourcepub fn new(strength: usize) -> Result<Self>
pub fn new(strength: usize) -> Result<Self>
Construct an Andrews Pitchfork with the given fractal strength (bars on
each side of a pivot).
§Errors
Returns Error::PeriodZero if strength == 0.
Sourcepub const fn value(&self) -> Option<AndrewsPitchforkOutput>
pub const fn value(&self) -> Option<AndrewsPitchforkOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for AndrewsPitchfork
impl Clone for AndrewsPitchfork
Source§fn clone(&self) -> AndrewsPitchfork
fn clone(&self) -> AndrewsPitchfork
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 AndrewsPitchfork
impl Debug for AndrewsPitchfork
Source§impl Indicator for AndrewsPitchfork
impl Indicator for AndrewsPitchfork
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = AndrewsPitchforkOutput
type Output = AndrewsPitchforkOutput
Source§fn update(&mut self, candle: Candle) -> Option<AndrewsPitchforkOutput>
fn update(&mut self, candle: Candle) -> Option<AndrewsPitchforkOutput>
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 AndrewsPitchfork
impl RefUnwindSafe for AndrewsPitchfork
impl Send for AndrewsPitchfork
impl Sync for AndrewsPitchfork
impl Unpin for AndrewsPitchfork
impl UnsafeUnpin for AndrewsPitchfork
impl UnwindSafe for AndrewsPitchfork
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