diff --git a/ta_lib/strategies/base/src/lib.rs b/ta_lib/strategies/base/src/lib.rs index c0841936..5a39f843 100644 --- a/ta_lib/strategies/base/src/lib.rs +++ b/ta_lib/strategies/base/src/lib.rs @@ -3,17 +3,19 @@ extern crate alloc; mod constants; mod ffi; mod model; -mod price; +mod source; mod strategy; mod traits; +mod volatility; pub mod prelude { pub use crate::constants::*; pub use crate::ffi::*; pub use crate::model::{OHLCVSeries, OHLCV}; - pub use crate::price::*; + pub use crate::source::*; pub use crate::strategy::{BaseStrategy, StopLossLevels, TradeAction}; pub use crate::traits::*; + pub use crate::volatility::*; } pub use prelude::*; diff --git a/ta_lib/strategies/base/src/price.rs b/ta_lib/strategies/base/src/source.rs similarity index 60% rename from ta_lib/strategies/base/src/price.rs rename to ta_lib/strategies/base/src/source.rs index 7c1df9db..2ba439a0 100644 --- a/ta_lib/strategies/base/src/price.rs +++ b/ta_lib/strategies/base/src/source.rs @@ -1,18 +1,15 @@ use crate::OHLCVSeries; use core::prelude::*; use price::prelude::*; -use volatility::{atr, tr}; -pub trait Price { +pub trait Source { fn hl2(&self) -> Series; fn hlc3(&self) -> Series; fn hlcc4(&self) -> Series; fn ohlc4(&self) -> Series; - fn atr(&self, period: usize, smooth_type: Smooth) -> Series; - fn tr(&self) -> Series; } -impl Price for OHLCVSeries { +impl Source for OHLCVSeries { #[inline] fn hl2(&self) -> Series { median_price(&self.high, &self.low) @@ -32,14 +29,4 @@ impl Price for OHLCVSeries { fn ohlc4(&self) -> Series { average_price(&self.open, &self.high, &self.low, &self.close) } - - #[inline] - fn atr(&self, period: usize, smooth_type: Smooth) -> Series { - atr(&self.high, &self.low, &self.close, smooth_type, period) - } - - #[inline] - fn tr(&self) -> Series { - tr(&self.high, &self.low, &self.close) - } } diff --git a/ta_lib/strategies/base/src/strategy.rs b/ta_lib/strategies/base/src/strategy.rs index d726b595..9debbf4f 100644 --- a/ta_lib/strategies/base/src/strategy.rs +++ b/ta_lib/strategies/base/src/strategy.rs @@ -1,4 +1,4 @@ -use crate::price::Price; +use crate::source::Source; use crate::{BaseLine, Confirm, Exit, OHLCVSeries, Pulse, Signal, StopLoss, Strategy, OHLCV}; use core::prelude::*; use std::collections::VecDeque; @@ -170,7 +170,7 @@ impl BaseStrategy { #[cfg(test)] mod tests { - use crate::price::Price; + use crate::source::Source; use crate::{ BaseLine, BaseStrategy, Confirm, Exit, OHLCVSeries, Pulse, Signal, StopLoss, Strategy, TradeAction, OHLCV, diff --git a/ta_lib/strategies/base/src/volatility.rs b/ta_lib/strategies/base/src/volatility.rs new file mode 100644 index 00000000..67036816 --- /dev/null +++ b/ta_lib/strategies/base/src/volatility.rs @@ -0,0 +1,20 @@ +use crate::OHLCVSeries; +use core::prelude::*; +use volatility::{atr, tr}; + +pub trait Volatility { + fn atr(&self, period: usize, smooth_type: Smooth) -> Series; + fn tr(&self) -> Series; +} + +impl Volatility for OHLCVSeries { + #[inline] + fn atr(&self, period: usize, smooth_type: Smooth) -> Series { + atr(&self.high, &self.low, &self.close, smooth_type, period) + } + + #[inline] + fn tr(&self) -> Series { + tr(&self.high, &self.low, &self.close) + } +}