pub struct SupportResistance { /* private fields */ }Expand description
A Support/Resistance indicator based on a sliding window of prices and swing detection.
Implementations§
Source§impl SupportResistance
impl SupportResistance
Sourcepub const DEFAULT_PERIOD: usize = 20usize
pub const DEFAULT_PERIOD: usize = 20usize
Default period (number of prices to consider) for swing detection.
Sourcepub const DEFAULT_THRESHOLD: f64 = 0.02f64
pub const DEFAULT_THRESHOLD: f64 = 0.02f64
Default threshold (2%): used to validate or clean up support/resistance levels.
Sourcepub fn new(period: usize, threshold: f64) -> Self
pub fn new(period: usize, threshold: f64) -> Self
Creates a new SupportResistance indicator.
§Arguments
period- The number of prices to include in the sliding window.threshold- The percentage threshold (as a decimal, e.g. 0.02 for 2%) to determine swing levels.
Sourcepub fn calculate(&mut self, price: f64) -> Option<SRResult>
pub fn calculate(&mut self, price: f64) -> Option<SRResult>
Updates the indicator with a new price and returns the current support/resistance result.
This method pushes the new price into the internal price window, updates the
detected support and resistance levels, and returns an SRResult if there are
enough prices.
§Arguments
price- The new price to add.
§Returns
Some(SRResult)if there are enough prices for calculation.Noneif there aren’t enough prices yet.
Auto Trait Implementations§
impl Freeze for SupportResistance
impl RefUnwindSafe for SupportResistance
impl Send for SupportResistance
impl Sync for SupportResistance
impl Unpin for SupportResistance
impl UnwindSafe for SupportResistance
Blanket Implementations§
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