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

as_list

Retrieve the indicator values for all candles as a list.

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

purge

Remove this indicator value from all Candles

read_candle

Simple method to get an indicator reading from a candle,

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,

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

has_reading bool

Check if the indicator has generated values in the candles.

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_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

has_reading property

has_reading: bool

Check if the indicator has generated values in the candles.

This property determines whether the indicator readings have been generated for the associated candle data.

Returns:

Name Type Description
bool bool

True if the indicator readings exist in the candles; otherwise, False.

settings property

settings: dict

Returns a dict format of how this indicator can be generated

add_managed_indicator

add_managed_indicator(name: str, indicator: Managed | Indicator)

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

Source code in hexital/core/indicator.py
def add_managed_indicator(self, name: str, indicator: Managed | Indicator):
    """Adds managed sub indicator, this will not auto calculate with indicator"""
    indicator._sub_indicator = True
    indicator.candle_manager = self._candles
    indicator.rounding = None
    self.managed_indicators[name] = indicator

add_sub_indicator

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

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):
    """Adds sub indicator, this will auto calculate with indicator"""
    indicator._sub_indicator = True
    indicator._sub_calc_prior = prior_calc
    indicator.candle_manager = self._candles
    indicator.rounding = None
    self.sub_indicators[indicator.name] = indicator

as_list

as_list(name: Optional[str] = None) -> List[float | dict | None]

Retrieve the indicator values for all 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[float | dict | None]

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 as_list(self, name: Optional[str] = None) -> List[float | dict | None]:
    """
    Retrieve the indicator values for all 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 [reading_by_candle(candle, name if name else self.name) for candle in self.candles]

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"""
    if not self._initialised:
        self._initialise()
        self._initialised = True

    self._calculate_sub_indicators(prior_calc=True)

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

        if self.candles[index].indicators.get(self.name) is not None:
            continue

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

    self._calculate_sub_indicators(prior_calc=False)

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"""
    end_index = end_index if end_index else start_index + 1

    self._calculate_sub_indicators(True, start_index, end_index)

    for index in range(start_index, end_index):
        self._set_active_index(index)
        reading = round_values(self._calculate_reading(index=index), round_by=self.rounding)
        self._set_reading(reading, index)

    self._calculate_sub_indicators(False, start_index, end_index)

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._candles.purge(
        {self.name}
        | {indicator.name for indicator in self.sub_indicators.values()}
        | {indicator.name for indicator in self.managed_indicators.values()}
    )

read_candle

read_candle(
    candle: Candle, name: Optional[str] = None, default: Optional[T] = None
) -> float | dict | None | T

Simple method to get an indicator reading from a candle, regardless of it's location

Source code in hexital/core/indicator.py
def read_candle(
    self,
    candle: Candle,
    name: Optional[str] = None,
    default: Optional[T] = None,
) -> float | dict | None | T:
    """Simple method to get an indicator reading from a candle,
    regardless of it's location"""
    value = reading_by_candle(candle, name if name else self.name)
    return value if value is not None else default

reading

reading(
    name: Optional[str] = None,
    index: Optional[int] = None,
    default: Optional[T] = None,
) -> float | dict | None | T

Simple method to get an indicator reading from the index Name can use '.' to find nested reading, E.G 'MACD_12_26_9.MACD

Source code in hexital/core/indicator.py
def reading(
    self,
    name: Optional[str] = None,
    index: Optional[int] = None,
    default: Optional[T] = None,
) -> float | dict | None | T:
    """Simple method to get an indicator reading from the index
    Name can use '.' to find nested reading, E.G 'MACD_12_26_9.MACD"""
    value = reading_by_candle(
        self.candles[index if index is not None else self._active_index],
        name if name else self.name,
    )
    return value if value is not None else default

reading_count

reading_count(name: Optional[str] = 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, name: Optional[str] = None, index: Optional[int] = None) -> int:
    """Returns how many instance of the given indicator exist"""
    return reading_count(
        self.candles,
        name=name if name else self.name,
        index=index if index is not None else self._active_index,
    )

reading_period

reading_period(
    period: int, name: Optional[str] = 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, name: Optional[str] = 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.candles,
        period=period,
        name=name if name else self.name,
        index=index if index is not None else self._active_index,
    )

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()