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
impl WilliamsR
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Williams %R calculator with default configuration (period=14)
Sourcepub fn with_period(period: usize) -> Result<Self, WilliamsRError>
pub fn with_period(period: usize) -> Result<Self, WilliamsRError>
Create a new Williams %R calculator with custom period
Sourcepub fn with_thresholds(
period: usize,
overbought: f64,
oversold: f64,
extreme_overbought: f64,
extreme_oversold: f64,
) -> Result<Self, WilliamsRError>
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
Sourcepub fn with_config(config: WilliamsRConfig) -> Self
pub fn with_config(config: WilliamsRConfig) -> Self
Create a new Williams %R calculator with custom configuration
Sourcepub fn calculate(
&mut self,
input: WilliamsRInput,
) -> Result<WilliamsROutput, WilliamsRError>
pub fn calculate( &mut self, input: WilliamsRInput, ) -> Result<WilliamsROutput, WilliamsRError>
Calculate Williams %R for the given input
Sourcepub fn calculate_batch(
&mut self,
inputs: &[WilliamsRInput],
) -> Result<Vec<WilliamsROutput>, WilliamsRError>
pub fn calculate_batch( &mut self, inputs: &[WilliamsRInput], ) -> Result<Vec<WilliamsROutput>, WilliamsRError>
Calculate Williams %R for a batch of inputs
Sourcepub fn get_state(&self) -> &WilliamsRState
pub fn get_state(&self) -> &WilliamsRState
Get current state (for serialization/debugging)
Sourcepub fn set_state(&mut self, state: WilliamsRState)
pub fn set_state(&mut self, state: WilliamsRState)
Restore state (for deserialization)
Sourcepub fn is_overbought(&self, williams_r: f64) -> bool
pub fn is_overbought(&self, williams_r: f64) -> bool
Check if currently overbought
Sourcepub fn is_oversold(&self, williams_r: f64) -> bool
pub fn is_oversold(&self, williams_r: f64) -> bool
Check if currently oversold
Sourcepub fn is_extreme_condition(&self, williams_r: f64) -> bool
pub fn is_extreme_condition(&self, williams_r: f64) -> bool
Check if in extreme condition
Sourcepub fn signal_strength(&self, williams_r: f64) -> f64
pub fn signal_strength(&self, williams_r: f64) -> f64
Get signal strength (0.0 to 1.0, where 1.0 is strongest)