Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 11, 2024
1 parent a8d196f commit 909886a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ta_lib/indicators/momentum/src/sso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use crate::stoch;
use core::prelude::*;

pub fn sso(
source: &Series<f32>,
high: &Series<f32>,
low: &Series<f32>,
close: &Series<f32>,
smooth_type: Smooth,
k_period: usize,
d_period: usize,
) -> (Series<f32>, Series<f32>) {
let high_smooth = high.smooth(smooth_type, k_period);
let low_smooth = low.smooth(smooth_type, k_period);
let close_smooth = close.smooth(smooth_type, k_period);
let source = source.smooth(smooth_type, k_period);

let k = stoch(&close_smooth, &high_smooth, &low_smooth, k_period);
let k = stoch(&source, &high_smooth, &low_smooth, k_period);
let d = k.smooth(smooth_type, d_period);

(k, d)
Expand All @@ -34,7 +34,7 @@ mod tests {
let expected_k = vec![0.0, 0.0, 58.333336, 41.666668, 41.666668];
let expected_d = vec![0.0, 0.0, 0.0, 0.0, 44.444447];

let (k, d) = sso(&high, &low, &close, Smooth::WMA, k_period, d_period);
let (k, d) = sso(&close, &high, &low, Smooth::WMA, k_period, d_period);

let result_k: Vec<f32> = k.into();
let result_d: Vec<f32> = d.into();
Expand Down
6 changes: 6 additions & 0 deletions ta_lib/strategies/base/src/price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,32 @@ pub trait Price {
}

impl Price for OHLCVSeries {
#[inline]
fn hl2(&self) -> Series<f32> {
median_price(&self.high, &self.low)
}

#[inline]
fn hlc3(&self) -> Series<f32> {
typical_price(&self.high, &self.low, &self.close)
}

#[inline]
fn hlcc4(&self) -> Series<f32> {
wcl(&self.high, &self.low, &self.close)
}

#[inline]
fn ohlc4(&self) -> Series<f32> {
average_price(&self.open, &self.high, &self.low, &self.close)
}

#[inline]
fn atr(&self, period: usize, smooth_type: Smooth) -> Series<f32> {
atr(&self.high, &self.low, &self.close, smooth_type, period)
}

#[inline]
fn tr(&self) -> Series<f32> {
tr(&self.high, &self.low, &self.close)
}
Expand Down

0 comments on commit 909886a

Please sign in to comment.