Skip to content

amorph

amorph

Classes:

Name Description
Amorph

Amorph

Amorph

Amorph(analysis: Callable, args: Optional[dict] = None, **kwargs)

Bases: Indicator

Amorph

Flexible Skeleton Indicator that will use a method to generate readings on every Candle like indicators.

The given Method is expected to have 'candles' and 'index' as named arguments, EG:

Input type Example: Doji

Output type: Based on analysis method

Parameters:

Name Type Description Default
analysis Callable

Period to index back in

required
args Optional[dict]

All of the Arguments as keyword arguments as a dict of keyword arguments for called analysis

None

Methods:

Name Description
add_managed_indicator

Adds managed sub indicator, this will not auto calculate with indicator

add_sub_indicator

Adds sub indicator, this will auto calculate with indicator

append

append a Candle or a chronological ordered list of Candle's to the end of the Indicator Candle's. This wil only re-sample and re-calculate the new Candles, with minor overlap.

calculate

Calculate the TA values, will calculate for all the Candles,

calculate_index

Calculate the TA values, will calculate a index range the Candles, will re-calculate

insert

insert a Candle or a list of Candle's to the Indicator Candles. This accepts any order or placement. This will sort, re-sample and re-calculate all Candles.

prepend

Prepends a Candle or a chronological ordered list of Candle's to the front of the Indicator Candle's. This will only re-sample and re-calculate the new Candles, with minor overlap.

purge

Remove this indicator value from all Candles

reading

Simple method to get an indicator reading from the index

reading_count

Returns how many instance of the given indicator exist

reading_period

Will return True if the given indicator goes back as far as amount,

readings

Retrieve the indicator readings for within the candles as a list.

recalculate

Re-calculate this indicator value for all Candles

Attributes:

Name Type Description
candle_manager CandleManager

The Candle Manager which controls TimeFrame, Trimming and collapsing

settings dict

Returns a dict format of how this indicator can be generated

Source code in hexital/indicators/amorph.py
def __init__(self, analysis: Callable, args: Optional[dict] = None, **kwargs):
    self._analysis_method = analysis
    self.analysis_name = analysis.__name__
    self._analysis_kwargs, kwargs = self._separate_indicator_attributes(kwargs)

    if isinstance(args, dict):
        self._analysis_kwargs.update(args)

    super().__init__(**kwargs)

candle_manager property writable

candle_manager: CandleManager

The Candle Manager which controls TimeFrame, Trimming and collapsing

settings property

settings: dict

Returns a dict format of how this indicator can be generated

add_managed_indicator

add_managed_indicator(indicator: N) -> N

Adds managed sub indicator, this will not auto calculate with indicator

Source code in hexital/core/indicator.py
def add_managed_indicator(self, indicator: N) -> N:
    """Adds managed sub indicator, this will not auto calculate with indicator"""
    indicator._mode = IndicatorMode.MANAGED

    if indicator.name == MANAGED_NAME:
        indicator.name = f"{self.name}_data"
    elif indicator._generated_name:
        indicator.name = f"{self.name}-{indicator.name}"

    indicator.candle_manager = self._candle_mngr
    indicator.rounding = None
    self.managed_indicators[indicator.name] = indicator
    return indicator

add_sub_indicator

add_sub_indicator(indicator: Indicator, prior_calc: bool = True) -> Indicator

Adds sub indicator, this will auto calculate with indicator

Source code in hexital/core/indicator.py
def add_sub_indicator(self, indicator: Indicator, prior_calc: bool = True) -> Indicator:
    """Adds sub indicator, this will auto calculate with indicator"""
    indicator._mode = IndicatorMode.SUB
    indicator._calc_prior = prior_calc

    if indicator._generated_name:
        indicator.name = f"{self.name}-{indicator.name}"

    indicator.candle_manager = self._candle_mngr
    indicator.rounding = None
    self.sub_indicators[indicator.name] = indicator
    return self.sub_indicators[indicator.name]

append

append(candles: Candles)

append a Candle or a chronological ordered list of Candle's to the end of the Indicator Candle's. This wil only re-sample and re-calculate the new Candles, with minor overlap.

Parameters:

Name Type Description Default
candles Candles

The Candle or List of Candle's to prepend.

required
Source code in hexital/core/indicator.py
def append(self, candles: Candles):
    """append a Candle or a chronological ordered list of Candle's to the end of the Indicator Candle's. This wil only re-sample and re-calculate the new Candles, with minor overlap.

    Args:
        candles: The Candle or List of Candle's to prepend.
    """
    self._candle_mngr.append(candles)
    self.calculate()

calculate

calculate()

Calculate the TA values, will calculate for all the Candles, where this indicator is missing

Source code in hexital/core/indicator.py
def calculate(self):
    """Calculate the TA values, will calculate for all the Candles,
    where this indicator is missing"""
    self.check_initialised()

    for index in range(self._find_calc_index(), len(self.candles)):
        self._set_active_index(index)
        self._calculate_sub_indicators(True, index)

        reading = round_values(self._calculate_reading(index=index), round_by=self.rounding)

        if index < len(self.candles) - 1 and self._reading_dup(reading, self.candles[index]):
            break

        self._set_reading(reading, index)
        self._calculate_sub_indicators(False, index)

calculate_index

calculate_index(start_index: int, end_index: Optional[int] = None)

Calculate the TA values, will calculate a index range the Candles, will re-calculate

Source code in hexital/core/indicator.py
def calculate_index(self, start_index: int, end_index: Optional[int] = None):
    """Calculate the TA values, will calculate a index range the Candles, will re-calculate"""
    self.check_initialised()

    start_index = absindex(start_index, len(self.candles))

    if end_index is not None:
        end_index = absindex(end_index, len(self.candles))
    else:
        end_index = start_index

    for index in range(start_index, end_index + 1):
        self._set_active_index(index)
        self._calculate_sub_indicators(True, index)

        reading = round_values(self._calculate_reading(index=index), self.rounding)

        self._set_reading(reading, index)
        self._calculate_sub_indicators(False, index)

insert

insert(candles: Candles)

insert a Candle or a list of Candle's to the Indicator Candles. This accepts any order or placement. This will sort, re-sample and re-calculate all Candles.

Parameters:

Name Type Description Default
candles Candles

The Candle or List of Candle's to prepend.

required
Source code in hexital/core/indicator.py
def insert(self, candles: Candles):
    """insert a Candle or a list of Candle's to the Indicator Candles. This accepts any order or placement. This will sort, re-sample and re-calculate all Candles.

    Args:
        candles: The Candle or List of Candle's to prepend.
    """
    self._candle_mngr.insert(candles)
    self.calculate_index(0, -1)

prepend

prepend(candles: Candles)

Prepends a Candle or a chronological ordered list of Candle's to the front of the Indicator Candle's. This will only re-sample and re-calculate the new Candles, with minor overlap.

Parameters:

Name Type Description Default
candles Candles

The Candle or List of Candle's to prepend.

required
Source code in hexital/core/indicator.py
def prepend(self, candles: Candles):
    """Prepends a Candle or a chronological ordered list of Candle's to the front of the Indicator Candle's. This will only re-sample and re-calculate the new Candles, with minor overlap.

    Args:
        candles: The Candle or List of Candle's to prepend.
    """

    self._candle_mngr.prepend(candles)
    self.calculate()

purge

purge()

Remove this indicator value from all Candles

Source code in hexital/core/indicator.py
def purge(self):
    """Remove this indicator value from all Candles"""
    self._candle_mngr.purge(
        {self.name}
        | {indicator.name for indicator in self.sub_indicators.values()}
        | {indicator.name for indicator in self.managed_indicators.values()}
    )

reading

reading(
    source: Optional[Source] = None,
    index: Optional[int] = None,
    default: Optional[T] = None,
) -> Reading | V | T

Simple method to get an indicator reading from the index

Source code in hexital/core/indicator.py
def reading(
    self,
    source: Optional[Source] = None,
    index: Optional[int] = None,
    default: Optional[T] = None,
) -> Reading | V | T:
    """Simple method to get an indicator reading from the index"""
    value = self._find_reading(source, index)
    return value if value is not None else default

reading_count

reading_count(
    source: Optional[Source] = None, index: Optional[int] = None
) -> int

Returns how many instance of the given indicator exist

Source code in hexital/core/indicator.py
def reading_count(self, source: Optional[Source] = None, index: Optional[int] = None) -> int:
    """Returns how many instance of the given indicator exist"""
    return reading_count(
        *self._find_candles(source),
        index if index is not None else self._active_index,
    )

reading_period

reading_period(
    period: int, source: Optional[Source] = None, index: Optional[int] = None
) -> bool

Will return True if the given indicator goes back as far as amount, It's true if exactly or more than. Period will be period -1

Source code in hexital/core/indicator.py
def reading_period(
    self, period: int, source: Optional[Source] = None, index: Optional[int] = None
) -> bool:
    """Will return True if the given indicator goes back as far as amount,
    It's true if exactly or more than. Period will be period -1"""
    return reading_period(
        *self._find_candles(source),
        period,
        index if index is not None else self._active_index,
    )

readings

readings(name: Optional[Source] = None) -> List[Reading | V]

Retrieve the indicator readings for within the candles as a list.

This method collects the readings of a specified indicator for all candles and returns them as a list. If no name is provided, the generated name of the indicator is used.

Parameters:

Name Type Description Default
name Optional[str]

The name of the indicator to retrieve. Defaults to self.name if not provided.

None

Returns:

Type Description
List[Reading | V]

List[float | dict | None]: A list containing the indicator values for each candle. The values may be floats, dictionaries (for complex indicators), or None if no reading is available.

Source code in hexital/core/indicator.py
def readings(self, name: Optional[Source] = None) -> List[Reading | V]:
    """
    Retrieve the indicator readings for within the candles as a list.

    This method collects the readings of a specified indicator for all candles
    and returns them as a list. If no name is provided, the generated name of
    the indicator is used.

    Args:
        name (Optional[str]): The name of the indicator to retrieve.
                              Defaults to `self.name` if not provided.

    Returns:
        List[float | dict | None]: A list containing the indicator values for
                                   each candle. The values may be floats,
                                   dictionaries (for complex indicators),
                                   or `None` if no reading is available.
    """
    return self._find_readings(name)

recalculate

recalculate()

Re-calculate this indicator value for all Candles

Source code in hexital/core/indicator.py
def recalculate(self):
    """Re-calculate this indicator value for all Candles"""
    self.purge()
    self.calculate()