Skip to content

Commit

Permalink
Added calculate_index to hexital
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinR committed Jan 30, 2024
1 parent bd797b7 commit fa3b19b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html
- Fixed Hammer index pattern working correctly
- Made 'as_list' property a method that can now take a nested indicator name
- Added ability to call the movement methods from Hexital and Indicator for easier usage
- Added calculate_index to hexital

## 0.4.0 - 2024-01-22
- Cleaned up code and some potential Bugs ruff/pyright
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For most libraries such as [Pandas-TA](https://github.com/twopirllc/pandas-ta) w
### Indicators
Hexital comes with a growing selection of available Indicators to compute. These can be used individually to calculate a single indicator, or used with the `Hexital` class to automatically compute multiple indicators with an incremental candle list; which is easily parsable.

### Candle Patterns
### Candlestick Patterns
Hexital also supports detecting candle patterns, such as Doji, etc. This can be achieved easily by calling the Pattern function with the candles, or used automatically as an indicator where it would be computed alongside Indicators.

### Multi-Timeframes
Expand Down Expand Up @@ -137,6 +137,8 @@ print(my_ema.reading()) # None
my_ema.recalculate()
print(my_ema.reading()) # 7319.8776

# Recalculate latest
my_ema.calculate_index("EMA_3")

# Access other Readings (Reading get's the latest readings)
print(my_ema.reading("high")) # 4837
Expand Down
6 changes: 6 additions & 0 deletions hexital/core/hexital.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ def calculate(self, name: Optional[str] = None):
if name is None or indicator_name == name:
indicator.calculate()

def calculate_index(self, name: Optional[str] = None, index: int = -1):
"""Calculate specific index for all or specific indicator readings."""
for indicator_name, indicator in self._indicators.items():
if name is None or indicator_name == name:
indicator.calculate_index(index)

def recalculate(self, name: Optional[str] = None):
"""Purge's all indicator reading's and re-calculates them all,
ideal for changing an indicator parameters midway."""
Expand Down

0 comments on commit fa3b19b

Please sign in to comment.