Struct WilliamsR

Source
pub struct WilliamsR { /* private fields */ }
Expand description

Williams %R Indicator

Williams %R is a momentum oscillator that measures overbought and oversold levels. It’s similar to the Stochastic Oscillator but with an inverted scale (0 to -100).

Formula: Williams %R = (Highest High - Close) / (Highest High - Lowest Low) × -100

Where:

  • Highest High = Highest high over the lookback period
  • Lowest Low = Lowest low over the lookback period
  • Close = Current closing price

Interpretation:

  • Values range from 0 to -100
  • Above -20: Overbought condition
  • Below -80: Oversold condition
  • Above -10: Extremely overbought
  • Below -90: Extremely oversold

Williams %R is particularly useful for:

  • Identifying extreme price conditions
  • Timing entry/exit points
  • Confirming trend reversals

Implementations§

Source§

impl WilliamsR

Source

pub fn new() -> Self

Create a new Williams %R calculator with default configuration (period=14)

Source

pub fn with_period(period: usize) -> Result<Self, WilliamsRError>

Create a new Williams %R calculator with custom period

Source

pub fn with_thresholds( period: usize, overbought: f64, oversold: f64, extreme_overbought: f64, extreme_oversold: f64, ) -> Result<Self, WilliamsRError>

Create a new Williams %R calculator with custom period and thresholds

Source

pub fn with_config(config: WilliamsRConfig) -> Self

Create a new Williams %R calculator with custom configuration

Source

pub fn calculate( &mut self, input: WilliamsRInput, ) -> Result<WilliamsROutput, WilliamsRError>

Calculate Williams %R for the given input

Source

pub fn calculate_batch( &mut self, inputs: &[WilliamsRInput], ) -> Result<Vec<WilliamsROutput>, WilliamsRError>

Calculate Williams %R for a batch of inputs

Source

pub fn reset(&mut self)

Reset the calculator state

Source

pub fn get_state(&self) -> &WilliamsRState

Get current state (for serialization/debugging)

Source

pub fn set_state(&mut self, state: WilliamsRState)

Restore state (for deserialization)

Source

pub fn is_overbought(&self, williams_r: f64) -> bool

Check if currently overbought

Source

pub fn is_oversold(&self, williams_r: f64) -> bool

Check if currently oversold

Source

pub fn is_extreme_condition(&self, williams_r: f64) -> bool

Check if in extreme condition

Source

pub fn signal_strength(&self, williams_r: f64) -> f64

Get signal strength (0.0 to 1.0, where 1.0 is strongest)

Trait Implementations§

Source§

impl Default for WilliamsR

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.