-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from dataclasses import dataclass | ||
|
||
from core.models.indicator import Indicator | ||
from core.models.moving_average import MovingAverageType | ||
from core.models.parameter import Parameter, RandomParameter | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Cross3xMovingAverageSignal(Indicator): | ||
ma: MovingAverageType = MovingAverageType.SMA | ||
short_period: Parameter = RandomParameter(5.0, 50.0, 5.0) | ||
medium_period: Parameter = RandomParameter(50.0, 100.0, 5.0) | ||
long_period: Parameter = RandomParameter(100.0, 200.0, 10.0) | ||
|
||
@property | ||
def parameters(self): | ||
return [ | ||
self.ma, | ||
self.short_period, | ||
self.medium_period, | ||
self.long_period, | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use base::{OHLCVSeries, Signal}; | ||
use core::Series; | ||
use shared::{ma_indicator, MovingAverageType}; | ||
|
||
pub struct Cross3xMASignal { | ||
smoothing: MovingAverageType, | ||
short_period: usize, | ||
medium_period: usize, | ||
long_period: usize, | ||
} | ||
|
||
impl Cross3xMASignal { | ||
pub fn new( | ||
smoothing: MovingAverageType, | ||
short_period: f32, | ||
medium_period: f32, | ||
long_period: f32, | ||
) -> Self { | ||
Self { | ||
smoothing, | ||
short_period: short_period as usize, | ||
medium_period: medium_period as usize, | ||
long_period: long_period as usize, | ||
} | ||
} | ||
} | ||
|
||
impl Signal for Cross3xMASignal { | ||
fn id(&self) -> String { | ||
format!( | ||
"CROSS3xMA_{}:{}:{}:{}", | ||
self.smoothing, self.short_period, self.medium_period, self.long_period | ||
) | ||
} | ||
|
||
fn lookback(&self) -> usize { | ||
let adjusted_lookback = std::cmp::max(self.short_period, self.long_period); | ||
std::cmp::max(adjusted_lookback, self.medium_period) | ||
} | ||
|
||
fn entry(&self, data: &OHLCVSeries) -> (Series<bool>, Series<bool>) { | ||
let short_ma = ma_indicator(&self.smoothing, data, self.short_period); | ||
let medium_ma = ma_indicator(&self.smoothing, data, self.medium_period); | ||
let long_ma = ma_indicator(&self.smoothing, data, self.long_period); | ||
|
||
let long_signal = short_ma.cross_over(&medium_ma) & medium_ma.cross_over(&long_ma); | ||
let short_signal = short_ma.cross_under(&medium_ma) & medium_ma.cross_under(&long_ma); | ||
|
||
(long_signal, short_signal) | ||
} | ||
|
||
fn exit(&self, _data: &OHLCVSeries) -> (Series<bool>, Series<bool>) { | ||
(Series::empty(1), Series::empty(1)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.