From 4bd53baca88e9c5e6fef617d689881bd60fdec8c Mon Sep 17 00:00:00 2001 From: m5l14i11 Date: Sun, 28 Apr 2024 19:55:10 +0300 Subject: [PATCH] upd --- ta_lib/strategies/base/src/model.rs | 40 +++++++++++-- ta_lib/strategies/base/src/source.rs | 14 ++--- ta_lib/strategies/base/src/strategy.rs | 26 ++++----- ta_lib/strategies/base/src/volatility.rs | 4 +- ta_lib/strategies/baseline/src/ma.rs | 4 +- ta_lib/strategies/confirm/src/dpo.rs | 2 +- ta_lib/strategies/confirm/src/dso.rs | 2 +- ta_lib/strategies/confirm/src/dumb.rs | 2 +- ta_lib/strategies/confirm/src/eom.rs | 6 +- ta_lib/strategies/confirm/src/roc.rs | 2 +- .../strategies/confirm/src/rsi_neutrality.rs | 2 +- .../strategies/confirm/src/rsi_signalline.rs | 3 +- ta_lib/strategies/confirm/src/stc.rs | 2 +- ta_lib/strategies/confirm/src/vi.rs | 4 +- ta_lib/strategies/exit/src/ast.rs | 2 +- ta_lib/strategies/exit/src/dumb.rs | 2 +- ta_lib/strategies/exit/src/highlow.rs | 4 +- ta_lib/strategies/exit/src/ma.rs | 2 +- ta_lib/strategies/exit/src/mfi.rs | 2 +- ta_lib/strategies/exit/src/rsi.rs | 3 +- ta_lib/strategies/exit/src/trix.rs | 2 +- ta_lib/strategies/indicator/src/candle.rs | 56 +++++++++---------- ta_lib/strategies/indicator/src/ma.rs | 54 +++++++++--------- ta_lib/strategies/pulse/src/adx.rs | 4 +- ta_lib/strategies/pulse/src/braid.rs | 6 +- ta_lib/strategies/pulse/src/chop.rs | 4 +- ta_lib/strategies/pulse/src/dumb.rs | 2 +- ta_lib/strategies/pulse/src/nvol.rs | 2 +- ta_lib/strategies/pulse/src/tdfi.rs | 2 +- ta_lib/strategies/pulse/src/vo.rs | 2 +- ta_lib/strategies/pulse/src/wae.rs | 10 ++-- ta_lib/strategies/signal/src/bb/macd_bb.rs | 2 +- ta_lib/strategies/signal/src/bb/vwap_bb.rs | 3 +- .../signal/src/breakout/dch_ma2_breakout.rs | 7 ++- ta_lib/strategies/signal/src/flip/ce_flip.rs | 6 +- .../signal/src/flip/supertrend_flip.rs | 2 +- ta_lib/strategies/signal/src/ma/ma2_rsi.rs | 12 ++-- ta_lib/strategies/signal/src/ma/ma_cross.rs | 2 +- .../strategies/signal/src/ma/ma_quadruple.rs | 26 ++++----- ta_lib/strategies/signal/src/ma/ma_surpass.rs | 20 +++---- .../signal/src/ma/ma_testing_ground.rs | 24 ++++---- ta_lib/strategies/signal/src/ma/vwap_cross.rs | 7 ++- ta_lib/strategies/signal/src/pattern/hl.rs | 4 +- .../signal/src/reversal/dmi_reversal.rs | 4 +- .../signal/src/reversal/vi_reversal.rs | 4 +- .../signal/src/signalline/di_signalline.rs | 2 +- .../signal/src/signalline/dso_signalline.rs | 2 +- .../signal/src/signalline/kst_signalline.rs | 2 +- .../signal/src/signalline/macd_signalline.rs | 2 +- .../src/signalline/qstick_signalline.rs | 2 +- .../signal/src/signalline/rsi_signalline.rs | 3 +- .../signal/src/signalline/stoch_signalline.rs | 6 +- .../signal/src/signalline/trix_signalline.rs | 2 +- .../signal/src/signalline/tsi_signalline.rs | 2 +- .../signal/src/zerocross/apo_zerocross.rs | 2 +- .../signal/src/zerocross/bop_zerocross.rs | 8 +-- .../signal/src/zerocross/cc_zerocross.rs | 2 +- .../signal/src/zerocross/cfo_zerocross.rs | 2 +- .../signal/src/zerocross/di_zerocross.rs | 2 +- .../signal/src/zerocross/macd_zerocross.rs | 2 +- .../signal/src/zerocross/qstick_zerocross.rs | 2 +- .../signal/src/zerocross/roc_zerocross.rs | 2 +- .../signal/src/zerocross/trix_zerocross.rs | 2 +- .../signal/src/zerocross/tsi_zerocross.rs | 2 +- ta_lib/strategies/stop_loss/src/dch.rs | 4 +- 65 files changed, 241 insertions(+), 207 deletions(-) diff --git a/ta_lib/strategies/base/src/model.rs b/ta_lib/strategies/base/src/model.rs index d115707c..99fd9134 100644 --- a/ta_lib/strategies/base/src/model.rs +++ b/ta_lib/strategies/base/src/model.rs @@ -13,11 +13,11 @@ pub struct OHLCV { #[derive(Debug, Clone)] pub struct OHLCVSeries { - pub open: Series, - pub high: Series, - pub low: Series, - pub close: Series, - pub volume: Series, + open: Series, + high: Series, + low: Series, + close: Series, + volume: Series, } impl OHLCVSeries { @@ -55,4 +55,34 @@ impl OHLCVSeries { volume: Series::from(volume), } } + + #[inline] + pub fn len(&self) -> usize { + self.close.len() + } + + #[inline] + pub fn open(&self) -> &Series { + &self.open + } + + #[inline] + pub fn high(&self) -> &Series { + &self.high + } + + #[inline] + pub fn low(&self) -> &Series { + &self.low + } + + #[inline] + pub fn close(&self) -> &Series { + &self.close + } + + #[inline] + pub fn volume(&self) -> &Series { + &self.volume + } } diff --git a/ta_lib/strategies/base/src/source.rs b/ta_lib/strategies/base/src/source.rs index 73b2c191..b851adcd 100644 --- a/ta_lib/strategies/base/src/source.rs +++ b/ta_lib/strategies/base/src/source.rs @@ -3,7 +3,6 @@ use core::prelude::*; use price::prelude::*; pub trait Source { - fn close(&self) -> Series; fn hl2(&self) -> Series; fn hlc3(&self) -> Series; fn hlcc4(&self) -> Series; @@ -11,28 +10,23 @@ pub trait Source { } impl Source for OHLCVSeries { - #[inline] - fn close(&self) -> Series { - self.close.clone() - } - #[inline] fn hl2(&self) -> Series { - median_price(&self.high, &self.low) + median_price(self.high(), self.low()) } #[inline] fn hlc3(&self) -> Series { - typical_price(&self.high, &self.low, &self.close) + typical_price(self.high(), self.low(), self.close()) } #[inline] fn hlcc4(&self) -> Series { - wcl(&self.high, &self.low, &self.close) + wcl(&self.high(), self.low(), self.close()) } #[inline] fn ohlc4(&self) -> Series { - average_price(&self.open, &self.high, &self.low, &self.close) + average_price(self.open(), 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 cdce51fa..4cb331f0 100644 --- a/ta_lib/strategies/base/src/strategy.rs +++ b/ta_lib/strategies/base/src/strategy.rs @@ -98,8 +98,8 @@ impl Strategy for BaseStrategy { match self.trade_signals() { (true, false, false, false) => TradeAction::GoLong(theo_price), (false, true, false, false) => TradeAction::GoShort(theo_price), - (false, false, true, false) => TradeAction::ExitLong(data.close), - (false, false, false, true) => TradeAction::ExitShort(data.close), + (false, false, true, false) => TradeAction::ExitLong(theo_price), + (false, false, false, true) => TradeAction::ExitShort(theo_price), _ => TradeAction::DoNothing, } } @@ -187,7 +187,7 @@ mod tests { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::zero(len).into()) } } @@ -202,7 +202,7 @@ mod tests { } fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::zero(len).into()) } } @@ -217,7 +217,7 @@ mod tests { } fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::one(len).into()) } } @@ -232,12 +232,12 @@ mod tests { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::zero(len).into()) } fn filter(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::zero(len).into()) } } @@ -253,7 +253,7 @@ mod tests { } fn find(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); ( Series::from(vec![5.0; len]) * self.multi, Series::from(vec![6.0; len]) * self.multi, @@ -269,7 +269,7 @@ mod tests { } fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::zero(len).into()) } } @@ -322,10 +322,10 @@ mod tests { let series = OHLCVSeries::from_data(&strategy.data); - let hl2: Vec = series.hl2().into(); - let hlc3: Vec = series.hlc3().into(); - let hlcc4: Vec = series.hlcc4().into(); - let ohlc4: Vec = series.ohlc4().into(); + let hl2: Vec = series.hl2().clone().into(); + let hlc3: Vec = series.hlc3().clone().into(); + let hlcc4: Vec = series.hlcc4().clone().into(); + let ohlc4: Vec = series.ohlc4().clone().into(); assert_eq!(hl2, vec![1.25]); assert_eq!(hlc3, vec![1.333_333_4]); diff --git a/ta_lib/strategies/base/src/volatility.rs b/ta_lib/strategies/base/src/volatility.rs index 67036816..99670cc6 100644 --- a/ta_lib/strategies/base/src/volatility.rs +++ b/ta_lib/strategies/base/src/volatility.rs @@ -10,11 +10,11 @@ pub trait Volatility { impl Volatility for OHLCVSeries { #[inline] fn atr(&self, period: usize, smooth_type: Smooth) -> Series { - atr(&self.high, &self.low, &self.close, smooth_type, period) + atr(self.high(), self.low(), self.close(), smooth_type, period) } #[inline] fn tr(&self) -> Series { - tr(&self.high, &self.low, &self.close) + tr(self.high(), self.low(), self.close()) } } diff --git a/ta_lib/strategies/baseline/src/ma.rs b/ta_lib/strategies/baseline/src/ma.rs index 30beeea6..ef37eb36 100644 --- a/ta_lib/strategies/baseline/src/ma.rs +++ b/ta_lib/strategies/baseline/src/ma.rs @@ -19,7 +19,7 @@ impl MaBaseLine { period: period as usize, signal: vec![ Box::new(MaSurpassSignal::new(ma, period)), - // Box::new(MaQuadrupleSignal::new(ma, period)), + Box::new(MaQuadrupleSignal::new(ma, period)), ], } } @@ -40,7 +40,7 @@ impl BaseLine for MaBaseLine { let ma = ma_indicator(&self.ma, data, self.period); let prev_ma = ma.shift(1); - let dist = (&ma - &data.close).abs(); + let dist = (&ma - data.close()).abs(); let atr = data.atr(DEFAULT_ATR_LOOKBACK, Smooth::SMMA) * DEFAULT_ATR_FACTOR; ( diff --git a/ta_lib/strategies/confirm/src/dpo.rs b/ta_lib/strategies/confirm/src/dpo.rs index 1e882040..abe0a7c9 100644 --- a/ta_lib/strategies/confirm/src/dpo.rs +++ b/ta_lib/strategies/confirm/src/dpo.rs @@ -22,7 +22,7 @@ impl Confirm for DpoConfirm { } fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { - let dpo = dpo(&data.close, self.smooth_type, self.period); + let dpo = dpo(data.close(), self.smooth_type, self.period); (dpo.sgt(&ZERO_LINE), dpo.slt(&ZERO_LINE)) } diff --git a/ta_lib/strategies/confirm/src/dso.rs b/ta_lib/strategies/confirm/src/dso.rs index 748366b1..a0b4e915 100644 --- a/ta_lib/strategies/confirm/src/dso.rs +++ b/ta_lib/strategies/confirm/src/dso.rs @@ -28,7 +28,7 @@ impl Confirm for DsoConfirm { fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { let (k, d) = dso( - &data.close, + data.close(), self.smooth_type, self.smooth_period, self.k_period, diff --git a/ta_lib/strategies/confirm/src/dumb.rs b/ta_lib/strategies/confirm/src/dumb.rs index 50b8589b..03629ede 100644 --- a/ta_lib/strategies/confirm/src/dumb.rs +++ b/ta_lib/strategies/confirm/src/dumb.rs @@ -19,7 +19,7 @@ impl Confirm for DumbConfirm { } fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::one(len).into()) } diff --git a/ta_lib/strategies/confirm/src/eom.rs b/ta_lib/strategies/confirm/src/eom.rs index b1cf5651..c36100cb 100644 --- a/ta_lib/strategies/confirm/src/eom.rs +++ b/ta_lib/strategies/confirm/src/eom.rs @@ -26,9 +26,9 @@ impl Confirm for EomConfirm { fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { let eom = eom( &data.hl2(), - &data.high, - &data.low, - &data.volume, + data.high(), + data.low(), + data.volume(), self.smooth_type, self.period, self.divisor, diff --git a/ta_lib/strategies/confirm/src/roc.rs b/ta_lib/strategies/confirm/src/roc.rs index f06350e8..de6996ce 100644 --- a/ta_lib/strategies/confirm/src/roc.rs +++ b/ta_lib/strategies/confirm/src/roc.rs @@ -20,7 +20,7 @@ impl Confirm for RocConfirm { } fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { - let roc = roc(&data.close, self.period); + let roc = roc(data.close(), self.period); (roc.sgt(&ZERO_LINE), roc.slt(&ZERO_LINE)) } diff --git a/ta_lib/strategies/confirm/src/rsi_neutrality.rs b/ta_lib/strategies/confirm/src/rsi_neutrality.rs index 7829c51e..4e413001 100644 --- a/ta_lib/strategies/confirm/src/rsi_neutrality.rs +++ b/ta_lib/strategies/confirm/src/rsi_neutrality.rs @@ -27,7 +27,7 @@ impl Confirm for RsiNeutralityConfirm { } fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { - let rsi = rsi(&data.close, self.smooth_type, self.period); + let rsi = rsi(data.close(), self.smooth_type, self.period); let lower_barrier = RSI_LOWER_BARRIER + self.threshold; let upper_barrier = RSI_UPPER_BARRIER - self.threshold; diff --git a/ta_lib/strategies/confirm/src/rsi_signalline.rs b/ta_lib/strategies/confirm/src/rsi_signalline.rs index 0935c994..4b9dd52c 100644 --- a/ta_lib/strategies/confirm/src/rsi_signalline.rs +++ b/ta_lib/strategies/confirm/src/rsi_signalline.rs @@ -37,8 +37,9 @@ impl Confirm for RsiSignalLineConfirm { } fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { - let rsi = rsi(&data.close, self.smooth_type, self.rsi_period); + let rsi = rsi(&data.close(), self.smooth_type, self.rsi_period); let signal = rsi.smooth(self.smooth_signal, self.smooth_period); + let upper_barrier = RSI_UPPER_BARRIER + self.threshold; let lower_barrier = RSI_LOWER_BARRIER - self.threshold; diff --git a/ta_lib/strategies/confirm/src/stc.rs b/ta_lib/strategies/confirm/src/stc.rs index e3be053e..e94559d4 100644 --- a/ta_lib/strategies/confirm/src/stc.rs +++ b/ta_lib/strategies/confirm/src/stc.rs @@ -44,7 +44,7 @@ impl Confirm for StcConfirm { fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { let stc = stc( - &data.close, + data.close(), self.smooth_type, self.fast_period, self.slow_period, diff --git a/ta_lib/strategies/confirm/src/vi.rs b/ta_lib/strategies/confirm/src/vi.rs index 189e5b73..949c93d2 100644 --- a/ta_lib/strategies/confirm/src/vi.rs +++ b/ta_lib/strategies/confirm/src/vi.rs @@ -23,8 +23,8 @@ impl Confirm for ViConfirm { fn validate(&self, data: &OHLCVSeries) -> (Series, Series) { let (vip, vim) = vi( - &data.high, - &data.low, + data.high(), + data.low(), &data.atr(self.atr_period, Smooth::SMMA), self.period, ); diff --git a/ta_lib/strategies/exit/src/ast.rs b/ta_lib/strategies/exit/src/ast.rs index cb1c200b..6a81cceb 100644 --- a/ta_lib/strategies/exit/src/ast.rs +++ b/ta_lib/strategies/exit/src/ast.rs @@ -23,7 +23,7 @@ impl Exit for AstExit { fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { let (direction, _) = ast( - &data.close, + data.close(), &data.atr(self.atr_period, Smooth::SMMA), self.factor, ); diff --git a/ta_lib/strategies/exit/src/dumb.rs b/ta_lib/strategies/exit/src/dumb.rs index 7ebe0567..117fe00d 100644 --- a/ta_lib/strategies/exit/src/dumb.rs +++ b/ta_lib/strategies/exit/src/dumb.rs @@ -9,7 +9,7 @@ impl Exit for DumbExit { } fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::zero(len).into(), Series::zero(len).into()) } diff --git a/ta_lib/strategies/exit/src/highlow.rs b/ta_lib/strategies/exit/src/highlow.rs index db53cbcf..43aa5bd5 100644 --- a/ta_lib/strategies/exit/src/highlow.rs +++ b/ta_lib/strategies/exit/src/highlow.rs @@ -20,8 +20,8 @@ impl Exit for HighLowExit { fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { ( - data.close.sgt(&data.high.shift(self.period)), - data.close.slt(&data.low.shift(self.period)), + data.close().sgt(&data.high().shift(self.period)), + data.close().slt(&data.low().shift(self.period)), ) } } diff --git a/ta_lib/strategies/exit/src/ma.rs b/ta_lib/strategies/exit/src/ma.rs index 6aa2617d..2c370ec9 100644 --- a/ta_lib/strategies/exit/src/ma.rs +++ b/ta_lib/strategies/exit/src/ma.rs @@ -24,6 +24,6 @@ impl Exit for MaExit { fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { let ma = ma_indicator(&self.ma, data, self.period); - (data.close.cross_under(&ma), data.close.cross_over(&ma)) + (data.close().cross_under(&ma), data.close().cross_over(&ma)) } } diff --git a/ta_lib/strategies/exit/src/mfi.rs b/ta_lib/strategies/exit/src/mfi.rs index 6d1f1af9..1d59e86d 100644 --- a/ta_lib/strategies/exit/src/mfi.rs +++ b/ta_lib/strategies/exit/src/mfi.rs @@ -25,7 +25,7 @@ impl Exit for MfiExit { } fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { - let mfi = mfi(&data.hlc3(), &data.volume, self.period); + let mfi = mfi(&data.hlc3(), data.volume(), self.period); let upper_bound = MFI_OVERBOUGHT - self.threshold; let lower_bound = MFI_OVERSOLD + self.threshold; diff --git a/ta_lib/strategies/exit/src/rsi.rs b/ta_lib/strategies/exit/src/rsi.rs index cb750812..f0db5052 100644 --- a/ta_lib/strategies/exit/src/rsi.rs +++ b/ta_lib/strategies/exit/src/rsi.rs @@ -27,7 +27,8 @@ impl Exit for RsiExit { } fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { - let rsi = rsi(&data.close, self.smooth_type, self.period); + let rsi = rsi(data.close(), self.smooth_type, self.period); + let upper_bound = RSI_OVERBOUGHT - self.threshold; let lower_bound = RSI_OVERSOLD + self.threshold; diff --git a/ta_lib/strategies/exit/src/trix.rs b/ta_lib/strategies/exit/src/trix.rs index bf36109e..17fa5b64 100644 --- a/ta_lib/strategies/exit/src/trix.rs +++ b/ta_lib/strategies/exit/src/trix.rs @@ -24,7 +24,7 @@ impl Exit for TrixExit { } fn evaluate(&self, data: &OHLCVSeries) -> (Series, Series) { - let trix = trix(&data.close, self.smooth_type, self.period); + let trix = trix(data.close(), self.smooth_type, self.period); let signal_line = trix.smooth(self.smooth_type, self.signal_period); ( diff --git a/ta_lib/strategies/indicator/src/candle.rs b/ta_lib/strategies/indicator/src/candle.rs index fe0f9232..4b52aaf1 100644 --- a/ta_lib/strategies/indicator/src/candle.rs +++ b/ta_lib/strategies/indicator/src/candle.rs @@ -29,60 +29,60 @@ pub fn candlestick_trend_indicator( ) -> (Series, Series) { match candle { CandleTrendType::BOTTLE => ( - bottle::bullish(&data.open, &data.low, &data.close), - bottle::bearish(&data.open, &data.high, &data.close), + bottle::bullish(data.open(), data.low(), data.close()), + bottle::bearish(data.open(), data.high(), data.close()), ), CandleTrendType::DOUBLE_TROUBLE => ( - double_trouble::bullish(&data.open, &data.high, &data.low, &data.close), - double_trouble::bearish(&data.open, &data.high, &data.low, &data.close), + double_trouble::bullish(data.open(), data.high(), data.low(), data.close()), + double_trouble::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::GOLDEN => ( - golden::bullish(&data.open, &data.high, &data.low, &data.close), - golden::bearish(&data.open, &data.high, &data.low, &data.close), + golden::bullish(data.open(), data.high(), data.low(), data.close()), + golden::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::H => ( - h::bullish(&data.open, &data.high, &data.low, &data.close), - h::bearish(&data.open, &data.high, &data.low, &data.close), + h::bullish(data.open(), data.high(), data.low(), data.close()), + h::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::HEXAD => ( - hexad::bullish(&data.open, &data.high, &data.close), - hexad::bearish(&data.open, &data.low, &data.close), + hexad::bullish(data.open(), data.high(), data.close()), + hexad::bearish(data.open(), data.low(), data.close()), ), CandleTrendType::HIKKAKE => ( - hikkake::bullish(&data.open, &data.high, &data.low, &data.close), - hikkake::bearish(&data.open, &data.high, &data.low, &data.close), + hikkake::bullish(data.open(), data.high(), data.low(), data.close()), + hikkake::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::MARUBOZU => ( - marubozu::bullish(&data.open, &data.high, &data.low, &data.close), - marubozu::bearish(&data.open, &data.high, &data.low, &data.close), + marubozu::bullish(data.open(), data.high(), data.low(), data.close()), + marubozu::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::MASTER_CANDLE => ( - master_candle::bullish(&data.open, &data.high, &data.low, &data.close), - master_candle::bearish(&data.open, &data.high, &data.low, &data.close), + master_candle::bullish(data.open(), data.high(), data.low(), data.close()), + master_candle::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::QUINTUPLETS => ( - quintuplets::bullish(&data.open, &data.close), - quintuplets::bearish(&data.open, &data.close), + quintuplets::bullish(data.open(), data.close()), + quintuplets::bearish(data.open(), data.close()), ), CandleTrendType::SLINGSHOT => ( - slingshot::bullish(&data.open, &data.high, &data.low, &data.close), - slingshot::bearish(&data.open, &data.high, &data.low, &data.close), + slingshot::bullish(data.open(), data.high(), data.low(), data.close()), + slingshot::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::THREE_CANDLES => ( - three_candles::bullish(&data.open, &data.close), - three_candles::bearish(&data.open, &data.close), + three_candles::bullish(data.open(), data.close()), + three_candles::bearish(data.open(), data.close()), ), CandleTrendType::THREE_METHODS => ( - three_methods::bullish(&data.open, &data.high, &data.low, &data.close), - three_methods::bearish(&data.open, &data.high, &data.low, &data.close), + three_methods::bullish(data.open(), data.high(), data.low(), data.close()), + three_methods::bearish(data.open(), data.high(), data.low(), data.close()), ), CandleTrendType::TASUKI => ( - tasuki::bullish(&data.open, &data.close), - tasuki::bearish(&data.open, &data.close), + tasuki::bullish(data.open(), data.close()), + tasuki::bearish(data.open(), data.close()), ), CandleTrendType::THREE_ONE_TWO => ( - three_one_two::bullish(&data.open, &data.high, &data.low, &data.close), - three_one_two::bearish(&data.open, &data.high, &data.low, &data.close), + three_one_two::bullish(data.open(), data.high(), data.low(), data.close()), + three_one_two::bearish(data.open(), data.high(), data.low(), data.close()), ), } } diff --git a/ta_lib/strategies/indicator/src/ma.rs b/ta_lib/strategies/indicator/src/ma.rs index faceb3dd..9d3547d1 100644 --- a/ta_lib/strategies/indicator/src/ma.rs +++ b/ta_lib/strategies/indicator/src/ma.rs @@ -38,32 +38,32 @@ pub enum MovingAverageType { pub fn ma_indicator(ma: &MovingAverageType, data: &OHLCVSeries, period: usize) -> Series { match ma { - MovingAverageType::ALMA => alma(&data.close, period, 0.85, 6.0), - MovingAverageType::CAMA => cama(&data.close, &data.high, &data.low, &data.tr(), period), - MovingAverageType::DEMA => dema(&data.close, period), - MovingAverageType::EMA => ema(&data.close, period), - MovingAverageType::FRAMA => frama(&data.high, &data.low, &data.close, period), - MovingAverageType::GMA => gma(&data.close, period), - MovingAverageType::HMA => hma(&data.close, period), - MovingAverageType::HEMA => hema(&data.close, period), - MovingAverageType::KAMA => kama(&data.close, period), - MovingAverageType::KJS => kjs(&data.high, &data.low, period), - MovingAverageType::LSMA => lsma(&data.close, period), - MovingAverageType::MD => md(&data.close, period), - MovingAverageType::RMSMA => rmsma(&data.close, period), - MovingAverageType::SINWMA => sinwma(&data.close, period), - MovingAverageType::SMA => sma(&data.close, period), - MovingAverageType::SMMA => smma(&data.close, period), - MovingAverageType::TTHREE => t3(&data.close, period), - MovingAverageType::TEMA => tema(&data.close, period), - MovingAverageType::TMA => tma(&data.close, period), - MovingAverageType::VIDYA => vidya(&data.close, period, 3 * period), - MovingAverageType::VWMA => vwma(&data.close, &data.volume, period), - MovingAverageType::VWEMA => vwema(&data.close, &data.volume, period), - MovingAverageType::WMA => wma(&data.close, period), - MovingAverageType::ZLEMA => zlema(&data.close, period), - MovingAverageType::ZLSMA => zlsma(&data.close, period), - MovingAverageType::ZLTEMA => zltema(&data.close, period), - MovingAverageType::ZLHMA => zlhma(&data.close, period, 3), + MovingAverageType::ALMA => alma(data.close(), period, 0.85, 6.0), + MovingAverageType::CAMA => cama(data.close(), data.high(), data.low(), &data.tr(), period), + MovingAverageType::DEMA => dema(data.close(), period), + MovingAverageType::EMA => ema(data.close(), period), + MovingAverageType::FRAMA => frama(data.high(), data.low(), data.close(), period), + MovingAverageType::GMA => gma(data.close(), period), + MovingAverageType::HMA => hma(data.close(), period), + MovingAverageType::HEMA => hema(data.close(), period), + MovingAverageType::KAMA => kama(data.close(), period), + MovingAverageType::KJS => kjs(data.high(), data.low(), period), + MovingAverageType::LSMA => lsma(data.close(), period), + MovingAverageType::MD => md(data.close(), period), + MovingAverageType::RMSMA => rmsma(data.close(), period), + MovingAverageType::SINWMA => sinwma(data.close(), period), + MovingAverageType::SMA => sma(data.close(), period), + MovingAverageType::SMMA => smma(data.close(), period), + MovingAverageType::TTHREE => t3(data.close(), period), + MovingAverageType::TEMA => tema(data.close(), period), + MovingAverageType::TMA => tma(data.close(), period), + MovingAverageType::VIDYA => vidya(data.close(), period, 3 * period), + MovingAverageType::VWMA => vwma(data.close(), data.volume(), period), + MovingAverageType::VWEMA => vwema(data.close(), data.volume(), period), + MovingAverageType::WMA => wma(data.close(), period), + MovingAverageType::ZLEMA => zlema(data.close(), period), + MovingAverageType::ZLSMA => zlsma(data.close(), period), + MovingAverageType::ZLTEMA => zltema(data.close(), period), + MovingAverageType::ZLHMA => zlhma(data.close(), period, 3), } } diff --git a/ta_lib/strategies/pulse/src/adx.rs b/ta_lib/strategies/pulse/src/adx.rs index 95795713..fc7172b2 100644 --- a/ta_lib/strategies/pulse/src/adx.rs +++ b/ta_lib/strategies/pulse/src/adx.rs @@ -29,8 +29,8 @@ impl Pulse for AdxPulse { fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { let (adx, _, _) = dmi( - &data.high, - &data.low, + data.high(), + data.low(), &data.atr(self.di_period, Smooth::SMMA), self.smooth_type, self.adx_period, diff --git a/ta_lib/strategies/pulse/src/braid.rs b/ta_lib/strategies/pulse/src/braid.rs index 89b4dff0..12ba6e4c 100644 --- a/ta_lib/strategies/pulse/src/braid.rs +++ b/ta_lib/strategies/pulse/src/braid.rs @@ -37,9 +37,9 @@ impl Pulse for BraidPulse { } fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { - let fast_ma = data.close.smooth(self.smooth_type, self.fast_period); - let open_ma = data.open.smooth(self.smooth_type, self.open_period); - let slow_ma = data.close.smooth(self.smooth_type, self.slow_period); + let fast_ma = data.close().smooth(self.smooth_type, self.fast_period); + let open_ma = data.open().smooth(self.smooth_type, self.open_period); + let slow_ma = data.close().smooth(self.smooth_type, self.slow_period); let filter = data.atr(self.atr_period, Smooth::SMMA) * self.strength / 100.0; diff --git a/ta_lib/strategies/pulse/src/chop.rs b/ta_lib/strategies/pulse/src/chop.rs index 639c268f..6248292c 100644 --- a/ta_lib/strategies/pulse/src/chop.rs +++ b/ta_lib/strategies/pulse/src/chop.rs @@ -27,8 +27,8 @@ impl Pulse for ChopPulse { fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { let chop = chop( - &data.high, - &data.low, + data.high(), + data.low(), &data.atr(self.atr_period, Smooth::SMMA), self.period, ); diff --git a/ta_lib/strategies/pulse/src/dumb.rs b/ta_lib/strategies/pulse/src/dumb.rs index 01deea18..0ef0a11f 100644 --- a/ta_lib/strategies/pulse/src/dumb.rs +++ b/ta_lib/strategies/pulse/src/dumb.rs @@ -19,7 +19,7 @@ impl Pulse for DumbPulse { } fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { - let len = data.close.len(); + let len = data.len(); (Series::one(len).into(), Series::one(len).into()) } diff --git a/ta_lib/strategies/pulse/src/nvol.rs b/ta_lib/strategies/pulse/src/nvol.rs index 2d0fbb8c..ed730288 100644 --- a/ta_lib/strategies/pulse/src/nvol.rs +++ b/ta_lib/strategies/pulse/src/nvol.rs @@ -24,7 +24,7 @@ impl Pulse for NvolPulse { } fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { - let nvol = nvol(&data.volume, self.smooth_type, self.period); + let nvol = nvol(&data.volume(), self.smooth_type, self.period); (nvol.sgt(&NVOL_LINE), nvol.sgt(&NVOL_LINE)) } diff --git a/ta_lib/strategies/pulse/src/tdfi.rs b/ta_lib/strategies/pulse/src/tdfi.rs index 76918169..ee59d17c 100644 --- a/ta_lib/strategies/pulse/src/tdfi.rs +++ b/ta_lib/strategies/pulse/src/tdfi.rs @@ -27,7 +27,7 @@ impl Pulse for TdfiPulse { } fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { - let tdfi = tdfi(&data.close, self.smooth_type, self.period, self.n); + let tdfi = tdfi(data.close(), self.smooth_type, self.period, self.n); (tdfi.sgt(&TDFI_UPPER_LINE), tdfi.slt(&TDFI_LOWER_LINE)) } diff --git a/ta_lib/strategies/pulse/src/vo.rs b/ta_lib/strategies/pulse/src/vo.rs index e12e037b..c62a1e6f 100644 --- a/ta_lib/strategies/pulse/src/vo.rs +++ b/ta_lib/strategies/pulse/src/vo.rs @@ -25,7 +25,7 @@ impl Pulse for VoPulse { fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { let vo = vo( - &data.volume, + data.volume(), self.smooth_type, self.fast_period, self.slow_period, diff --git a/ta_lib/strategies/pulse/src/wae.rs b/ta_lib/strategies/pulse/src/wae.rs index 1b60e56f..a87cdab7 100644 --- a/ta_lib/strategies/pulse/src/wae.rs +++ b/ta_lib/strategies/pulse/src/wae.rs @@ -50,18 +50,18 @@ impl Pulse for WaePulse { fn assess(&self, data: &OHLCVSeries) -> (Series, Series) { let dz = data.atr(self.atr_period, Smooth::SMMA) * self.dz_factor; - let (upper_bb, _, lower_bb) = bb(&data.close, self.smooth_bb, self.bb_period, self.factor); + let (upper_bb, _, lower_bb) = bb(data.close(), self.smooth_bb, self.bb_period, self.factor); let e = upper_bb - lower_bb; - let prev_close = data.close.shift(1); + let prev_close = data.close().shift(1); - let macd_line = data.close.smooth(self.smooth_type, self.fast_period) - - data.close.smooth(self.smooth_type, self.slow_period); + let macd_line = data.close().smooth(self.smooth_type, self.fast_period) + - data.close().smooth(self.smooth_type, self.slow_period); let prev_macd_line = prev_close.smooth(self.smooth_type, self.fast_period) - prev_close.smooth(self.smooth_type, self.slow_period); let t = (macd_line - prev_macd_line) * self.strength; - let zero = Series::zero(data.close.len()); + let zero = Series::zero(data.close().len()); let up = iff!(t.sgte(&ZERO), t, zero); let down = iff!(t.slt(&ZERO), t.negate(), zero); diff --git a/ta_lib/strategies/signal/src/bb/macd_bb.rs b/ta_lib/strategies/signal/src/bb/macd_bb.rs index f939e03a..b224c728 100644 --- a/ta_lib/strategies/signal/src/bb/macd_bb.rs +++ b/ta_lib/strategies/signal/src/bb/macd_bb.rs @@ -44,7 +44,7 @@ impl Signal for MacdBbSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (macd_line, _, _) = macd( - &data.close, + data.close(), self.smooth_type, self.fast_period, self.slow_period, diff --git a/ta_lib/strategies/signal/src/bb/vwap_bb.rs b/ta_lib/strategies/signal/src/bb/vwap_bb.rs index 705efa7a..07739978 100644 --- a/ta_lib/strategies/signal/src/bb/vwap_bb.rs +++ b/ta_lib/strategies/signal/src/bb/vwap_bb.rs @@ -27,7 +27,8 @@ impl Signal for VwapBbSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let vwap = vwap(&data.hlc3(), &data.volume); + let vwap = vwap(&data.hlc3(), data.volume()); + let (upper_bb, _, lower_bb) = bb(&vwap, self.bb_smooth, self.bb_period, self.factor); (vwap.cross_over(&upper_bb), vwap.cross_under(&lower_bb)) diff --git a/ta_lib/strategies/signal/src/breakout/dch_ma2_breakout.rs b/ta_lib/strategies/signal/src/breakout/dch_ma2_breakout.rs index 6d1e9ae7..b064c76e 100644 --- a/ta_lib/strategies/signal/src/breakout/dch_ma2_breakout.rs +++ b/ta_lib/strategies/signal/src/breakout/dch_ma2_breakout.rs @@ -28,13 +28,14 @@ impl Signal for DchMa2BreakoutSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let (upper_band, _, lower_band) = dch(&data.high, &data.low, self.dch_period); + let (upper_band, _, lower_band) = dch(data.high(), data.low(), self.dch_period); + let ma_short = ma_indicator(&self.ma, data, self.fast_period); let ma_long = ma_indicator(&self.ma, data, self.slow_period); ( - data.close.sgt(&upper_band.shift(1)) & ma_short.sgt(&ma_long), - data.close.slt(&lower_band.shift(1)) & ma_short.slt(&ma_long), + data.close().sgt(&upper_band.shift(1)) & ma_short.sgt(&ma_long), + data.close().slt(&lower_band.shift(1)) & ma_short.slt(&ma_long), ) } } diff --git a/ta_lib/strategies/signal/src/flip/ce_flip.rs b/ta_lib/strategies/signal/src/flip/ce_flip.rs index 7345d70e..b24e1573 100644 --- a/ta_lib/strategies/signal/src/flip/ce_flip.rs +++ b/ta_lib/strategies/signal/src/flip/ce_flip.rs @@ -25,9 +25,9 @@ impl Signal for CeFlipSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (direction, _) = ce( - &data.high, - &data.low, - &data.close, + data.high(), + data.low(), + data.close(), &data.atr(self.atr_period, Smooth::SMMA), self.period, self.factor, diff --git a/ta_lib/strategies/signal/src/flip/supertrend_flip.rs b/ta_lib/strategies/signal/src/flip/supertrend_flip.rs index 6022ed33..f93f1ddf 100644 --- a/ta_lib/strategies/signal/src/flip/supertrend_flip.rs +++ b/ta_lib/strategies/signal/src/flip/supertrend_flip.rs @@ -24,7 +24,7 @@ impl Signal for SupertrendFlipSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (direction, _) = supertrend( &data.hl2(), - &data.close, + data.close(), &data.atr(self.atr_period, Smooth::SMMA), self.factor, ); diff --git a/ta_lib/strategies/signal/src/ma/ma2_rsi.rs b/ta_lib/strategies/signal/src/ma/ma2_rsi.rs index 798a4427..771be035 100644 --- a/ta_lib/strategies/signal/src/ma/ma2_rsi.rs +++ b/ta_lib/strategies/signal/src/ma/ma2_rsi.rs @@ -42,19 +42,21 @@ impl Signal for Ma2RsiSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let rsi = rsi(&data.close, self.smooth_type, self.rsi_period); + let rsi = rsi(data.close(), self.smooth_type, self.rsi_period); + let ma_short = ma_indicator(&self.ma, data, self.fast_period); let ma_long = ma_indicator(&self.ma, data, self.slow_period); + let lower_barrier = RSI_LOWER_BARRIER + self.threshold; let upper_barrier = RSI_UPPER_BARRIER - self.threshold; ( - data.close.sgt(&ma_short) - & data.close.sgt(&ma_long) + data.close().sgt(&ma_short) + & data.close().sgt(&ma_long) & ma_short.sgt(&ma_long) & rsi.cross_under(&lower_barrier), - data.close.slt(&ma_short) - & data.close.slt(&ma_long) + data.close().slt(&ma_short) + & data.close().slt(&ma_long) & ma_short.slt(&ma_long) & rsi.cross_over(&upper_barrier), ) diff --git a/ta_lib/strategies/signal/src/ma/ma_cross.rs b/ta_lib/strategies/signal/src/ma/ma_cross.rs index 45a9e931..95b7aa8a 100644 --- a/ta_lib/strategies/signal/src/ma/ma_cross.rs +++ b/ta_lib/strategies/signal/src/ma/ma_cross.rs @@ -24,6 +24,6 @@ impl Signal for MaCrossSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let ma = ma_indicator(&self.ma, data, self.period); - (data.close.cross_over(&ma), data.close.cross_under(&ma)) + (data.close().cross_over(&ma), data.close().cross_under(&ma)) } } diff --git a/ta_lib/strategies/signal/src/ma/ma_quadruple.rs b/ta_lib/strategies/signal/src/ma/ma_quadruple.rs index f8f4e1be..179f0c1b 100644 --- a/ta_lib/strategies/signal/src/ma/ma_quadruple.rs +++ b/ta_lib/strategies/signal/src/ma/ma_quadruple.rs @@ -28,26 +28,26 @@ impl Signal for MaQuadrupleSignal { let back_2_ma = ma.shift(2); let back_3_ma = ma.shift(3); - let prev_close = data.close.shift(1); - let back_2_close = data.close.shift(2); - let back_3_close = data.close.shift(3); + let prev_close = data.close().shift(1); + let back_2_close = data.close().shift(2); + let back_3_close = data.close().shift(3); ( - data.low.slt(&ma) - & data.close.sgt(&ma) - & data.low.shift(1).slt(&prev_ma) + data.low().slt(&ma) + & data.close().sgt(&ma) + & data.low().shift(1).slt(&prev_ma) & prev_close.sgt(&prev_ma) - & data.low.shift(2).slt(&back_2_ma) + & data.low().shift(2).slt(&back_2_ma) & back_2_close.sgt(&back_2_ma) - & data.low.shift(3).slt(&back_3_ma) + & data.low().shift(3).slt(&back_3_ma) & back_3_close.sgt(&back_3_ma), - data.high.sgt(&ma) - & data.close.slt(&ma) - & data.high.shift(1).sgt(&prev_ma) + data.high().sgt(&ma) + & data.close().slt(&ma) + & data.high().shift(1).sgt(&prev_ma) & prev_close.slt(&prev_ma) - & data.high.shift(2).sgt(&back_2_ma) + & data.high().shift(2).sgt(&back_2_ma) & back_2_close.slt(&back_2_ma) - & data.high.shift(3).sgt(&back_3_ma) + & data.high().shift(3).sgt(&back_3_ma) & back_3_close.slt(&back_3_ma), ) } diff --git a/ta_lib/strategies/signal/src/ma/ma_surpass.rs b/ta_lib/strategies/signal/src/ma/ma_surpass.rs index ea66da81..46b9e915 100644 --- a/ta_lib/strategies/signal/src/ma/ma_surpass.rs +++ b/ta_lib/strategies/signal/src/ma/ma_surpass.rs @@ -27,25 +27,25 @@ impl Signal for MaSurpassSignal { let prev_ma = ma.shift(1); let back_2_ma = ma.shift(2); - let prev_open = data.open.shift(1); - let back_2_open = data.open.shift(2); + let prev_open = data.open().shift(1); + let back_2_open = data.open().shift(2); - let prev_close = data.close.shift(1); - let back_2_close = data.close.shift(2); + let prev_close = data.close().shift(1); + let back_2_close = data.close().shift(2); let prev_max = prev_close.max(&prev_open); let prev_min = prev_close.min(&prev_open); ( - data.open.sgt(&ma) - & data.close.sgt(&ma) - & data.low.slt(&ma) + data.open().sgt(&ma) + & data.close().sgt(&ma) + & data.low().slt(&ma) & prev_max.sgt(&prev_ma) & prev_min.slt(&prev_ma) & back_2_close.max(&back_2_open).slt(&back_2_ma), - data.open.slt(&ma) - & data.close.slt(&ma) - & data.high.sgt(&ma) + data.open().slt(&ma) + & data.close().slt(&ma) + & data.high().sgt(&ma) & prev_min.slt(&prev_ma) & prev_max.sgt(&prev_ma) & back_2_close.min(&back_2_open).sgt(&back_2_ma), diff --git a/ta_lib/strategies/signal/src/ma/ma_testing_ground.rs b/ta_lib/strategies/signal/src/ma/ma_testing_ground.rs index 001b44b3..fd9aa668 100644 --- a/ta_lib/strategies/signal/src/ma/ma_testing_ground.rs +++ b/ta_lib/strategies/signal/src/ma/ma_testing_ground.rs @@ -27,23 +27,23 @@ impl Signal for MaTestingGroundSignal { let prev_ma = ma.shift(1); let back_2_ma = ma.shift(2); - let prev_close = data.close.shift(1); - let back_2_close = data.close.shift(2); + let prev_close = data.close().shift(1); + let back_2_close = data.close().shift(2); - let prev_open = data.open.shift(1); - let back_2_open = data.open.shift(2); + let prev_open = data.open().shift(1); + let back_2_open = data.open().shift(2); ( - data.low.slt(&ma) - & data.low.shift(1).slt(&prev_ma) - & data.low.shift(2).slt(&back_2_ma) - & data.close.min(&data.open).sgt(&ma) + data.low().slt(&ma) + & data.low().shift(1).slt(&prev_ma) + & data.low().shift(2).slt(&back_2_ma) + & data.close().min(data.open()).sgt(&ma) & prev_close.min(&prev_open).sgt(&prev_ma) & back_2_close.min(&back_2_open).sgt(&back_2_ma), - data.high.sgt(&ma) - & data.high.shift(1).sgt(&prev_ma) - & data.high.shift(2).sgt(&back_2_ma) - & data.close.max(&data.open).slt(&ma) + data.high().sgt(&ma) + & data.high().shift(1).sgt(&prev_ma) + & data.high().shift(2).sgt(&back_2_ma) + & data.close().max(data.open()).slt(&ma) & prev_close.max(&prev_open).slt(&prev_ma) & back_2_close.max(&back_2_open).slt(&back_2_ma), ) diff --git a/ta_lib/strategies/signal/src/ma/vwap_cross.rs b/ta_lib/strategies/signal/src/ma/vwap_cross.rs index 4ff7fa40..6e3596a8 100644 --- a/ta_lib/strategies/signal/src/ma/vwap_cross.rs +++ b/ta_lib/strategies/signal/src/ma/vwap_cross.rs @@ -20,8 +20,11 @@ impl Signal for VwapCrossSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let vwap = vwap(&data.hlc3(), &data.volume); + let vwap = vwap(&data.hlc3(), data.volume()); - (data.close.cross_over(&vwap), data.close.cross_under(&vwap)) + ( + data.close().cross_over(&vwap), + data.close().cross_under(&vwap), + ) } } diff --git a/ta_lib/strategies/signal/src/pattern/hl.rs b/ta_lib/strategies/signal/src/pattern/hl.rs index 9b4488a6..5417a536 100644 --- a/ta_lib/strategies/signal/src/pattern/hl.rs +++ b/ta_lib/strategies/signal/src/pattern/hl.rs @@ -20,8 +20,8 @@ impl Signal for HighLowSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { ( - data.low.seq(&data.low.shift(1)), - data.high.seq(&data.high.shift(1)), + data.low().seq(&data.low().shift(1)), + data.high().seq(&data.high().shift(1)), ) } } diff --git a/ta_lib/strategies/signal/src/reversal/dmi_reversal.rs b/ta_lib/strategies/signal/src/reversal/dmi_reversal.rs index 7014c1b9..ee430652 100644 --- a/ta_lib/strategies/signal/src/reversal/dmi_reversal.rs +++ b/ta_lib/strategies/signal/src/reversal/dmi_reversal.rs @@ -25,8 +25,8 @@ impl Signal for DmiReversalSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (_, di_plus, di_minus) = dmi( - &data.high, - &data.low, + data.high(), + data.low(), &data.atr(self.di_period, Smooth::SMMA), self.smooth_type, self.adx_period, diff --git a/ta_lib/strategies/signal/src/reversal/vi_reversal.rs b/ta_lib/strategies/signal/src/reversal/vi_reversal.rs index 0faaa440..52b7f241 100644 --- a/ta_lib/strategies/signal/src/reversal/vi_reversal.rs +++ b/ta_lib/strategies/signal/src/reversal/vi_reversal.rs @@ -23,8 +23,8 @@ impl Signal for ViReversalSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (vip, vim) = vi( - &data.high, - &data.low, + data.high(), + data.low(), &data.atr(self.atr_period, Smooth::SMMA), self.period, ); diff --git a/ta_lib/strategies/signal/src/signalline/di_signalline.rs b/ta_lib/strategies/signal/src/signalline/di_signalline.rs index b79c1457..ed8422cb 100644 --- a/ta_lib/strategies/signal/src/signalline/di_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/di_signalline.rs @@ -24,7 +24,7 @@ impl Signal for DiSignalLineSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let di = di(&data.close(), self.smooth_type, self.period); + let di = di(data.close(), self.smooth_type, self.period); let signal_line = di.smooth(self.smooth_type, self.signal_period); (di.cross_over(&signal_line), di.cross_under(&signal_line)) diff --git a/ta_lib/strategies/signal/src/signalline/dso_signalline.rs b/ta_lib/strategies/signal/src/signalline/dso_signalline.rs index 7ee3ce18..b57a5659 100644 --- a/ta_lib/strategies/signal/src/signalline/dso_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/dso_signalline.rs @@ -28,7 +28,7 @@ impl Signal for DsoSignalLineSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (k, d) = dso( - &data.close(), + data.close(), self.smooth_type, self.smooth_period, self.k_period, diff --git a/ta_lib/strategies/signal/src/signalline/kst_signalline.rs b/ta_lib/strategies/signal/src/signalline/kst_signalline.rs index fbd40f97..211e712d 100644 --- a/ta_lib/strategies/signal/src/signalline/kst_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/kst_signalline.rs @@ -57,7 +57,7 @@ impl Signal for KstSignalLineSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let kst = kst( - &data.close(), + data.close(), self.smooth_type, self.roc_period_first, self.roc_period_second, diff --git a/ta_lib/strategies/signal/src/signalline/macd_signalline.rs b/ta_lib/strategies/signal/src/signalline/macd_signalline.rs index 95be9034..72c4cb92 100644 --- a/ta_lib/strategies/signal/src/signalline/macd_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/macd_signalline.rs @@ -33,7 +33,7 @@ impl Signal for MacdSignalLineSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (macd_line, signal_line, _) = macd( - &data.close(), + data.close(), self.smooth_type, self.fast_period, self.slow_period, diff --git a/ta_lib/strategies/signal/src/signalline/qstick_signalline.rs b/ta_lib/strategies/signal/src/signalline/qstick_signalline.rs index 6d6f3d0e..dcdca8d3 100644 --- a/ta_lib/strategies/signal/src/signalline/qstick_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/qstick_signalline.rs @@ -24,7 +24,7 @@ impl Signal for QstickSignalLineSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let qstick = qstick(&data.open, &data.close, self.smooth_type, self.period); + let qstick = qstick(data.open(), data.close(), self.smooth_type, self.period); let signal_line = qstick.smooth(self.smooth_type, self.signal_period); ( diff --git a/ta_lib/strategies/signal/src/signalline/rsi_signalline.rs b/ta_lib/strategies/signal/src/signalline/rsi_signalline.rs index 2ece8a00..50476949 100644 --- a/ta_lib/strategies/signal/src/signalline/rsi_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/rsi_signalline.rs @@ -34,8 +34,9 @@ impl Signal for RsiSignalLineSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let rsi = rsi(&data.close(), self.smooth_type, self.rsi_period); + let rsi = rsi(data.close(), self.smooth_type, self.rsi_period); let rsi_ma = rsi.smooth(self.smooth_signal, self.smooth_period); + let upper_neutrality = NEUTRALITY_LINE + self.threshold; let lower_neutrality = NEUTRALITY_LINE - self.threshold; diff --git a/ta_lib/strategies/signal/src/signalline/stoch_signalline.rs b/ta_lib/strategies/signal/src/signalline/stoch_signalline.rs index b3644f65..7da9f2de 100644 --- a/ta_lib/strategies/signal/src/signalline/stoch_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/stoch_signalline.rs @@ -28,9 +28,9 @@ impl Signal for StochSignalLineSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (k, d) = stochosc( - &data.high, - &data.low, - &data.close, + data.high(), + data.low(), + data.close(), self.smooth_type, self.period, self.k_period, diff --git a/ta_lib/strategies/signal/src/signalline/trix_signalline.rs b/ta_lib/strategies/signal/src/signalline/trix_signalline.rs index 2149c80e..1388855d 100644 --- a/ta_lib/strategies/signal/src/signalline/trix_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/trix_signalline.rs @@ -24,7 +24,7 @@ impl Signal for TrixSignalLineSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let trix = trix(&data.close(), self.smooth_type, self.period); + let trix = trix(data.close(), self.smooth_type, self.period); let signal_line = trix.smooth(self.smooth_type, self.signal_period); ( diff --git a/ta_lib/strategies/signal/src/signalline/tsi_signalline.rs b/ta_lib/strategies/signal/src/signalline/tsi_signalline.rs index c6a36053..02b21403 100644 --- a/ta_lib/strategies/signal/src/signalline/tsi_signalline.rs +++ b/ta_lib/strategies/signal/src/signalline/tsi_signalline.rs @@ -33,7 +33,7 @@ impl Signal for TsiSignalLineSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let tsi = tsi( - &data.close(), + data.close(), self.smooth_type, self.slow_period, self.fast_period, diff --git a/ta_lib/strategies/signal/src/zerocross/apo_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/apo_zerocross.rs index 512ef36f..6b75f0a6 100644 --- a/ta_lib/strategies/signal/src/zerocross/apo_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/apo_zerocross.rs @@ -22,7 +22,7 @@ impl Signal for ApoZeroCrossSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let apo = apo(&data.close(), self.fast_period, self.slow_period); + let apo = apo(data.close(), self.fast_period, self.slow_period); (apo.cross_over(&ZERO_LINE), apo.cross_under(&ZERO_LINE)) } diff --git a/ta_lib/strategies/signal/src/zerocross/bop_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/bop_zerocross.rs index de210830..02e03f96 100644 --- a/ta_lib/strategies/signal/src/zerocross/bop_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/bop_zerocross.rs @@ -23,10 +23,10 @@ impl Signal for BopZeroCrossSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let bop = bop( - &data.open, - &data.high, - &data.low, - &data.close, + data.open(), + data.high(), + data.low(), + data.close(), self.smooth_type, self.smooth_period, ); diff --git a/ta_lib/strategies/signal/src/zerocross/cc_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/cc_zerocross.rs index 3a10cfa3..e1a0ccc7 100644 --- a/ta_lib/strategies/signal/src/zerocross/cc_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/cc_zerocross.rs @@ -33,7 +33,7 @@ impl Signal for CcZeroCrossSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let cc = cc( - &data.close(), + data.close(), self.fast_period, self.slow_period, self.smooth_type, diff --git a/ta_lib/strategies/signal/src/zerocross/cfo_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/cfo_zerocross.rs index dbbf98a9..24e12fc7 100644 --- a/ta_lib/strategies/signal/src/zerocross/cfo_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/cfo_zerocross.rs @@ -20,7 +20,7 @@ impl Signal for CfoZeroCrossSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let cfo = cfo(&data.close(), self.period); + let cfo = cfo(data.close(), self.period); (cfo.cross_over(&ZERO_LINE), cfo.cross_under(&ZERO_LINE)) } diff --git a/ta_lib/strategies/signal/src/zerocross/di_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/di_zerocross.rs index 6fd57af6..cd825569 100644 --- a/ta_lib/strategies/signal/src/zerocross/di_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/di_zerocross.rs @@ -22,7 +22,7 @@ impl Signal for DiZeroCrossSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let di = di(&data.close(), self.smooth_type, self.period); + let di = di(data.close(), self.smooth_type, self.period); (di.cross_over(&ZERO_LINE), di.cross_under(&ZERO_LINE)) } diff --git a/ta_lib/strategies/signal/src/zerocross/macd_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/macd_zerocross.rs index 89d84a8e..ee587fc9 100644 --- a/ta_lib/strategies/signal/src/zerocross/macd_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/macd_zerocross.rs @@ -33,7 +33,7 @@ impl Signal for MacdZeroCrossSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let (macd_line, _, _) = macd( - &data.close(), + data.close(), self.smooth_type, self.fast_period, self.slow_period, diff --git a/ta_lib/strategies/signal/src/zerocross/qstick_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/qstick_zerocross.rs index ff86eca1..87030b0b 100644 --- a/ta_lib/strategies/signal/src/zerocross/qstick_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/qstick_zerocross.rs @@ -22,7 +22,7 @@ impl Signal for QstickZeroCrossSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let qstick = qstick(&data.open, &data.close, self.smooth_type, self.period); + let qstick = qstick(data.open(), data.close(), self.smooth_type, self.period); ( qstick.cross_over(&ZERO_LINE), diff --git a/ta_lib/strategies/signal/src/zerocross/roc_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/roc_zerocross.rs index 80e4d391..503be582 100644 --- a/ta_lib/strategies/signal/src/zerocross/roc_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/roc_zerocross.rs @@ -20,7 +20,7 @@ impl Signal for RocZeroCrossSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let roc = roc(&data.close(), self.period); + let roc = roc(data.close(), self.period); (roc.cross_over(&ZERO_LINE), roc.cross_under(&ZERO_LINE)) } diff --git a/ta_lib/strategies/signal/src/zerocross/trix_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/trix_zerocross.rs index f1000620..c20681dd 100644 --- a/ta_lib/strategies/signal/src/zerocross/trix_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/trix_zerocross.rs @@ -22,7 +22,7 @@ impl Signal for TrixZeroCrossSignal { } fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { - let trix = trix(&data.close(), self.smooth_type, self.period); + let trix = trix(data.close(), self.smooth_type, self.period); (trix.cross_over(&ZERO_LINE), trix.cross_under(&ZERO_LINE)) } diff --git a/ta_lib/strategies/signal/src/zerocross/tsi_zerocross.rs b/ta_lib/strategies/signal/src/zerocross/tsi_zerocross.rs index 448cfaa3..ab721841 100644 --- a/ta_lib/strategies/signal/src/zerocross/tsi_zerocross.rs +++ b/ta_lib/strategies/signal/src/zerocross/tsi_zerocross.rs @@ -25,7 +25,7 @@ impl Signal for TsiZeroCrossSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let tsi = tsi( - &data.close(), + data.close(), self.smooth_type, self.slow_period, self.fast_period, diff --git a/ta_lib/strategies/stop_loss/src/dch.rs b/ta_lib/strategies/stop_loss/src/dch.rs index e3b35a81..484de52f 100644 --- a/ta_lib/strategies/stop_loss/src/dch.rs +++ b/ta_lib/strategies/stop_loss/src/dch.rs @@ -22,8 +22,8 @@ impl StopLoss for DchStopLoss { } fn find(&self, data: &OHLCVSeries) -> (Series, Series) { - let (upper, _, lower) = dch(&data.high, &data.low, self.period); - let volatility = data.close.std(self.period).highest(self.period) * self.factor; + let (upper, _, lower) = dch(data.high(), data.low(), self.period); + let volatility = data.close().std(self.period).highest(self.period) * self.factor; (lower - &volatility, upper + &volatility) }