Skip to content

amorph

amorph

Classes:

Name Description
Amorph

Amorph

Amorph

Amorph(analysis: Callable, args: dict | None = 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 dict | None

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

None

Methods:

Name Description
add_child

Register a child indicator that shares this indicator's candles.

add_child_after

Register a child calculated after the parent's reading is stored.

add_child_managed

Register a child calculated only when explicitly invoked.

add_state

Register hidden state storage for incremental calculations.

append

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

at

Reading at a specific candle index — shorthand for reading.

at_src

Reading at index for this indicator's configured source.

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.

prev

Previous reading — shorthand for prev_reading.

prev_src

Previous reading for this indicator's configured source.

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

series

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

src

Current reading for this indicator's configured source.

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: dict | None = 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_child

add_child(indicator: Indicator, when: ChildWhen | str = BEFORE) -> Indicator

Register a child indicator that shares this indicator's candles.

Parameters:

Name Type Description Default
indicator Indicator

The child indicator to attach.

required
when ChildWhen | str

When the child is calculated relative to the parent at each index. :attr:ChildWhen.BEFORE runs before _calculate_reading. :attr:ChildWhen.AFTER runs after the parent's reading is stored. :attr:ChildWhen.MANUAL is only calculated when explicitly invoked (e.g. via Managed.set_reading or calculate_index).

BEFORE
Source code in hexital/core/indicator/core.py
def add_child(
    self,
    indicator: Indicator,
    when: ChildWhen | str = ChildWhen.BEFORE,
) -> Indicator:
    """Register a child indicator that shares this indicator's candles.

    Args:
        indicator: The child indicator to attach.
        when: When the child is calculated relative to the parent at each index.
            :attr:`ChildWhen.BEFORE` runs before `_calculate_reading`.
            :attr:`ChildWhen.AFTER` runs after the parent's reading is stored.
            :attr:`ChildWhen.MANUAL` is only calculated when explicitly invoked
            (e.g. via `Managed.set_reading` or `calculate_index`).
    """
    when = _normalize_when(when)
    self._prefix_generated_name(indicator, f"{self.name}-{indicator.name}")
    return self._bind_child(indicator, when)

add_child_after

add_child_after(indicator: Indicator) -> Indicator

Register a child calculated after the parent's reading is stored.

Source code in hexital/core/indicator/core.py
def add_child_after(self, indicator: Indicator) -> Indicator:
    """Register a child calculated after the parent's reading is stored."""
    return self.add_child(indicator, when=ChildWhen.AFTER)

add_child_managed

add_child_managed(indicator: Indicator) -> Indicator

Register a child calculated only when explicitly invoked.

Source code in hexital/core/indicator/core.py
def add_child_managed(self, indicator: Indicator) -> Indicator:
    """Register a child calculated only when explicitly invoked."""
    if isinstance(indicator, Managed):
        self._prefix_generated_name(indicator, f"{self.name}_data")
    return self.add_child(indicator, when=ChildWhen.MANUAL)

add_state

add_state(name: str | None = None) -> State

Register hidden state storage for incremental calculations.

Source code in hexital/core/indicator/core.py
def add_state(self, name: str | None = None) -> State:
    """Register hidden state storage for incremental calculations."""
    state_name = name if name is not None else f"{self.name}_data"
    managed = Managed(name=state_name)
    return State(self, self.add_child(managed, when=ChildWhen.MANUAL))

append

append(candles: Candles)

Appends a Candle or a chronological ordered list of Candle's to the end 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 append.

required
Source code in hexital/core/indicator/core.py
def append(self, candles: Candles):
    """Appends a Candle or a chronological ordered list of Candle's to the end 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 append.
    """
    self._candle_mngr.append(candles)
    self.calculate()

at

at(
    index: int, source: Source | None = None, default: T | None = None
) -> V | T

Reading at a specific candle index — shorthand for reading.

Source code in hexital/core/indicator/core.py
def at(
    self,
    index: int,
    source: Source | None = None,
    default: T | None = None,
) -> V | T:
    """Reading at a specific candle index — shorthand for `reading`."""
    return self.reading(source, index=index, default=default)

at_src

at_src(index: int, default: T | None = None) -> V | T

Reading at index for this indicator's configured source.

Source code in hexital/core/indicator/core.py
def at_src(self, index: int, default: T | None = None) -> V | T:
    """Reading at ``index`` for this indicator's configured ``source``."""
    return self.reading(
        getattr(self, "source", "close"), index=index, default=default
    )

calculate

calculate()

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

Source code in hexital/core/indicator/core.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_children(ChildWhen.BEFORE, 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_children(ChildWhen.AFTER, index)

calculate_index

calculate_index(start_index: int, end_index: int | None = None)

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

Source code in hexital/core/indicator/core.py
def calculate_index(self, start_index: int, end_index: int | None = 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_children(ChildWhen.BEFORE, index)

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

        self._set_reading(reading, index)
        self._calculate_children(ChildWhen.AFTER, 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/core.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/core.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()

prev

prev(source: Source | None = None, default: T | None = None) -> V | T

Previous reading — shorthand for prev_reading.

Source code in hexital/core/indicator/core.py
def prev(self, source: Source | None = None, default: T | None = None) -> V | T:
    """Previous reading — shorthand for `prev_reading`."""
    return self.prev_reading(source, default)

prev_src

prev_src(default: T | None = None) -> V | T

Previous reading for this indicator's configured source.

Source code in hexital/core/indicator/core.py
def prev_src(self, default: T | None = None) -> V | T:
    """Previous reading for this indicator's configured ``source``."""
    return self.prev_reading(getattr(self, "source", "close"), default=default)

reading

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

Simple method to get an indicator reading from the index

Source code in hexital/core/indicator/core.py
def reading(
    self,
    source: Source | None = None,
    index: int | None = None,
    default: T | None = None,
) -> 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  # type: ignore

reading_count

reading_count(source: Source | None = None, index: int | None = None) -> int

Returns how many instance of the given indicator exist

Source code in hexital/core/indicator/core.py
def reading_count(
    self, source: Source | None = None, index: int | None = 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: Source | None = None, index: int | None = 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/core.py
def reading_period(
    self, period: int, source: Source | None = None, index: int | None = 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,
    )

recalculate

recalculate()

Re-calculate this indicator value for all Candles

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

series

series(name: Source | None = 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 str | None

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/core.py
def series(self, name: Source | None = 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 (str | None): 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_series(name)  # type: ignore

src

src(default: T | None = None) -> V | T

Current reading for this indicator's configured source.

Source code in hexital/core/indicator/core.py
def src(self, default: T | None = None) -> V | T:
    """Current reading for this indicator's configured ``source``."""
    return self.reading(getattr(self, "source", "close"), default=default)