Expand description
§Support & Resistance Module
This module implements a support/resistance indicator based on swing highs and lows. It keeps a sliding window of prices (with a customizable period) and calculates support and resistance levels using a specified threshold (default is 2%).
The module provides a calculate method that returns an SRResult containing:
- The nearest support level
- The nearest resistance level
- A support strength (0-100%)
- A resistance strength (0-100%)
- A breakout potential (based on the weaker of the two strengths)
- A price position (relative to the support/resistance levels)
§Example
use indexes_rs::v1::support_resistance::main::SupportResistance;
use indexes_rs::v1::support_resistance::types::{SRResult, PricePosition};
let mut sr = SupportResistance::new(SupportResistance::DEFAULT_PERIOD, SupportResistance::DEFAULT_THRESHOLD);
// Simulate adding prices (in a real scenario, these would be updated on every tick)
let prices = vec![100.0, 101.0, 102.0, 101.5, 100.5, 99.0, 98.5, 99.5, 100.0, 101.0, 102.0, 103.0];
let mut result: Option<SRResult> = None;
for price in prices {
result = sr.calculate(price);
}
if let Some(res) = result {
println!("Nearest support: {:?}", res.nearest_support);
println!("Nearest resistance: {:?}", res.nearest_resistance);
println!("Support strength: {:.2}%", res.support_strength);
println!("Resistance strength: {:.2}%", res.resistance_strength);
println!("Breakout potential: {:.2}%", res.breakout_potential);
println!("Price position: {:?}", res.price_position);
}Structs§
- Support
Resistance - A Support/Resistance indicator based on a sliding window of prices and swing detection.