Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 24, 2024
1 parent a800229 commit 5ff5fa6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions strategy/generator/stop_loss/dch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
class DchStopLoss(StopLoss):
type: StopLossType = StopLossType.Dch
period: Parameter = StaticParameter(21.0)
factor: Parameter = StaticParameter(0.2)
7 changes: 5 additions & 2 deletions ta_lib/strategies/stop_loss/src/dch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use volatility::dch;

pub struct DchStopLoss {
period: usize,
factor: f32,
}

impl DchStopLoss {
pub fn new(period: f32) -> Self {
pub fn new(period: f32, factor: f32) -> Self {
Self {
period: period as usize,
factor,
}
}
}
Expand All @@ -21,7 +23,8 @@ impl StopLoss for DchStopLoss {

fn find(&self, data: &OHLCVSeries) -> (Series<f32>, Series<f32>) {
let (upper, _, lower) = dch(&data.high, &data.low, self.period);
let volatility = data.close.std(self.period).highest(self.period) * self.factor;

(lower, upper)
(lower - &volatility, upper + &volatility)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pub enum StopLossConfig {
},
Dch {
period: f32,
factor: f32,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ pub fn map_to_stoploss(config: StopLossConfig) -> Box<dyn StopLoss> {
period,
factor,
)),
StopLossConfig::Dch { period } => Box::new(DchStopLoss::new(period)),
StopLossConfig::Dch { period, factor } => Box::new(DchStopLoss::new(period, factor)),
}
}

0 comments on commit 5ff5fa6

Please sign in to comment.