Skip to content

Commit

Permalink
Mass Indicator clean up to fix, unused/unended input_value's and unus…
Browse files Browse the repository at this point in the history
…ed sub indicators
  • Loading branch information
MerlinR committed Apr 29, 2024
1 parent 1d026c4 commit 461d062
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html
## 1.1.1
- Changed Movement rising/falling default length from 4 to 1
- Added better exceptions to Hexital verifying dict indicators
- Mass Indicator clean up to fix, unused/unended input_value's and unused sub indicators
- Added Indicators
- Added HighestLowest (HL)
- Added Standard Deviation Threshold (STDEVTHRES)
Expand Down
9 changes: 1 addition & 8 deletions hexital/indicators/aroon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from hexital.analysis import movement
from hexital.core.indicator import Indicator
from hexital.indicators.sma import SMA
from hexital.indicators.stdev import StandardDeviation


@dataclass(kw_only=True)
Expand All @@ -14,22 +12,17 @@ class AROON(Indicator):

_name: str = field(init=False, default="AROON")
period: int = 14
input_value: str = "close"

def _generate_name(self) -> str:
return f"{self._name}_{self.period}"

def _initialise(self):
self.add_sub_indicator(StandardDeviation(period=self.period))
self.add_sub_indicator(SMA(period=self.period))

def _calculate_reading(self, index: int) -> float | dict | None:
aroon = {
"AROONU": None,
"AROOND": None,
"AROONOSC": None,
}
if self.reading_period(self.period + 1, self.input_value):
if self.reading_period(self.period + 1, "high"):
aroon["AROONU"] = (
(self.period - movement.highestbar(self.candles, "high", self.period + 1, index))
/ self.period
Expand Down
4 changes: 2 additions & 2 deletions hexital/indicators/bbands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def _generate_name(self) -> str:
return f"{self._name}_{self.period}"

def _initialise(self):
self.add_sub_indicator(StandardDeviation(period=self.period))
self.add_sub_indicator(SMA(period=self.period))
self.add_sub_indicator(StandardDeviation(input_value=self.input_value, period=self.period))
self.add_sub_indicator(SMA(input_value=self.input_value, period=self.period))

def _calculate_reading(self, index: int) -> float | dict | None:
bbands = {
Expand Down
1 change: 0 additions & 1 deletion hexital/indicators/donchian.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Donchian(Indicator):

_name: str = field(init=False, default="DONCHIAN")
period: int = 20
input_value: str = "close"

def _generate_name(self) -> str:
return f"{self._name}_{self.period}"
Expand Down
14 changes: 12 additions & 2 deletions hexital/indicators/hma.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@ def _generate_name(self) -> str:
return f"{self._name}_{self.period}"

def _initialise(self):
self.add_sub_indicator(WMA(period=self.period, fullname_override=f"{self.name}_WMA"))
self.add_sub_indicator(
WMA(period=int(self.period / 2), fullname_override=f"{self.name}_WMAh")
WMA(
input_value=self.input_value,
period=self.period,
fullname_override=f"{self.name}_WMA",
)
)
self.add_sub_indicator(
WMA(
input_value=self.input_value,
period=int(self.period / 2),
fullname_override=f"{self.name}_WMAh",
)
)

self.add_managed_indicator("raw_HMA", Managed(fullname_override=f"{self.name}_HMAr"))
Expand Down
3 changes: 0 additions & 3 deletions hexital/indicators/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class RMA(Indicator):
def _generate_name(self) -> str:
return f"{self._name}_{self.period}"

def _initialise(self):
return

def _calculate_reading(self, index: int) -> float | dict | None:
alpha = float(1.0 / self.period)

Expand Down
2 changes: 1 addition & 1 deletion hexital/indicators/roc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _generate_name(self) -> str:
return f"{self._name}"

def _calculate_reading(self, index: int) -> float | dict | None:
if self.prev_exists() or self.reading_period(self.period + 1, "close"):
if self.prev_exists() or self.reading_period(self.period + 1, self.input_value):
period_n_back = self.reading(self.input_value, index - self.period)

return ((self.reading(self.input_value) - period_n_back) / period_n_back) * 100
Expand Down
3 changes: 3 additions & 0 deletions hexital/indicators/stdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def _calculate_reading(self, index: int) -> float | dict | None:
removed_val = 0
in_calc_range = False

if self.reading(self.input_value) is None:
return None

if self.reading_period(self.period + 1, self.input_value, index):
removed_val = self.reading(self.input_value, index - self.period)
in_calc_range = True
Expand Down
2 changes: 1 addition & 1 deletion hexital/indicators/stdevthres.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def _generate_name(self) -> str:
def _initialise(self):
self.add_sub_indicator(
StandardDeviation(
fullname_override=f"{self.name}_stdev",
input_value=self.input_value,
period=self.period,
fullname_override=f"{self.name}_stdev",
)
)

Expand Down
3 changes: 0 additions & 3 deletions hexital/indicators/stoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class STOCH(Indicator):
def _generate_name(self) -> str:
return f"{self._name}_{self.period}"

def _validate_fields(self):
return

def _initialise(self):
self.add_managed_indicator("STOCH_data", Managed(fullname_override=f"{self.name}_data"))
self.managed_indicators["STOCH_data"].add_sub_indicator(
Expand Down

0 comments on commit 461d062

Please sign in to comment.