Skip to content

utils

utils

Functions:

Name Description
candle_bodylong

real body is long when it's longer than the average of the 10 previous candles' real body

candle_bodyshort

real body is short when it's shorter than the average of the 10 previous candles' real bodies

candle_bodyverylong

real body is very long when it's longer than 3 times the average of the 10 previous candles' real body

candle_doji

real body is like doji's body when it's shorter than 10% the average of the 10 previous candles' high-low range

candle_equal

when measuring distance between parts of candles or width of gaps

candle_far

when measuring distance between parts of candles or width of gaps

candle_near

when measuring distance between parts of candles or width of gaps

candle_shadow_long

shadow is long when it's longer than the real body

candle_shadow_short

shadow is short when it's shorter than half the average of the 10 previous candles' sum of shadows

candle_shadow_verylong

shadow is very long when it's longer than 2 times the real body

candle_shadow_veryshort

shadow is very short when it's shorter than 10% the average of the 10 previous candles' high-low range

high_low_avg

Computes the average of the high-low range over a specified number of candles,

highest

Computes the highest value of the specified indicator over a given range of candles.

lowest

Computes the lowest value of the specified indicator over a given range of candles.

realbody_avg

Computes the average real body of a specified number of candles, including the current candle.

realbody_gapdown

Computes if a candle has a real body gap-down compared to a previous candle.

realbody_gapup

Computes if a candle has a real body gap-up compared to a previous candle.

shadow_lower_avg

Computes the average lower shadow over a specified number of candles, including the current candle.

shadow_upper_avg

Computes the average upper shadow over a specified number of candles, including the current candle.

candle_bodylong

candle_bodylong(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float

real body is long when it's longer than the average of the 10 previous candles' real body

Source code in hexital/analysis/utils.py
def candle_bodylong(candles: List[Candle], index: Optional[int] = None, length: int = 10) -> float:
    """real body is long when it's longer than the average of the 10 previous candles' real body"""
    return _realbody_percentage(candles, index=index, length=length)

candle_bodyshort

candle_bodyshort(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float

real body is short when it's shorter than the average of the 10 previous candles' real bodies

Source code in hexital/analysis/utils.py
def candle_bodyshort(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float:
    """real body is short when it's shorter than the average of the 10 previous candles' real bodies"""
    return _realbody_percentage(candles, index=index, length=length)

candle_bodyverylong

candle_bodyverylong(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float

real body is very long when it's longer than 3 times the average of the 10 previous candles' real body

Source code in hexital/analysis/utils.py
def candle_bodyverylong(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float:
    """real body is very long when it's longer than 3 times the average of the 10 previous candles' real body"""
    return _realbody_percentage(candles, index=index, length=length, percentage=3)

candle_doji

candle_doji(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float

real body is like doji's body when it's shorter than 10% the average of the 10 previous candles' high-low range

Source code in hexital/analysis/utils.py
def candle_doji(candles: List[Candle], index: Optional[int] = None, length: int = 10) -> float:
    """real body is like doji's body when it's shorter than 10% the average of the 10 previous candles' high-low range"""
    return _high_low_percentage(candles, index=index, length=length, percentage=0.1)

candle_equal

candle_equal(
    candles: List[Candle], index: Optional[int] = None, length: int = 5
) -> float

when measuring distance between parts of candles or width of gaps equal means "<= 5% of the average of the 5 previous candles' high-low range

Source code in hexital/analysis/utils.py
def candle_equal(candles: List[Candle], index: Optional[int] = None, length: int = 5) -> float:
    """when measuring distance between parts of candles or width of gaps
    equal means "<= 5% of the average of the 5 previous candles' high-low range"""
    return _high_low_percentage(candles, index=index, length=length, percentage=0.05)

candle_far

candle_far(
    candles: List[Candle], index: Optional[int] = None, length: int = 5
) -> float

when measuring distance between parts of candles or width of gaps far means ">= 60% of the average of the 5 previous candles' high-low range

Source code in hexital/analysis/utils.py
def candle_far(candles: List[Candle], index: Optional[int] = None, length: int = 5) -> float:
    """when measuring distance between parts of candles or width of gaps
    far means ">= 60% of the average of the 5 previous candles' high-low range"""
    return _high_low_percentage(candles, index=index, length=length, percentage=0.6)

candle_near

candle_near(
    candles: List[Candle], index: Optional[int] = None, length: int = 5
) -> float

when measuring distance between parts of candles or width of gaps near means "<= 20% of the average of the 5 previous candles' high-low range"

Source code in hexital/analysis/utils.py
def candle_near(candles: List[Candle], index: Optional[int] = None, length: int = 5) -> float:
    """when measuring distance between parts of candles or width of gaps
    near means "<= 20% of the average of the 5 previous candles' high-low range" """
    return _high_low_percentage(candles, index=index, length=length, percentage=0.2)

candle_shadow_long

candle_shadow_long(candles: List[Candle], index: Optional[int] = None) -> float

shadow is long when it's longer than the real body

Source code in hexital/analysis/utils.py
def candle_shadow_long(candles: List[Candle], index: Optional[int] = None) -> float:
    """shadow is long when it's longer than the real body"""
    if index is None:
        index = -1

    return candles[index].realbody

candle_shadow_short

candle_shadow_short(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float

shadow is short when it's shorter than half the average of the 10 previous candles' sum of shadows

Source code in hexital/analysis/utils.py
def candle_shadow_short(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float:
    """shadow is short when it's shorter than half the average of the 10 previous candles' sum of shadows"""
    return _high_low_percentage(candles, index=index, length=length)

candle_shadow_verylong

candle_shadow_verylong(
    candles: List[Candle], index: Optional[int] = None
) -> float

shadow is very long when it's longer than 2 times the real body

Source code in hexital/analysis/utils.py
def candle_shadow_verylong(candles: List[Candle], index: Optional[int] = None) -> float:
    """shadow is very long when it's longer than 2 times the real body"""
    if index is None:
        index = -1

    return candles[index].realbody * 2

candle_shadow_veryshort

candle_shadow_veryshort(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float

shadow is very short when it's shorter than 10% the average of the 10 previous candles' high-low range

Source code in hexital/analysis/utils.py
def candle_shadow_veryshort(
    candles: List[Candle], index: Optional[int] = None, length: int = 10
) -> float:
    """shadow is very short when it's shorter than 10% the average of the 10 previous candles' high-low range"""
    return _high_low_percentage(candles, index=index, length=length, percentage=0.1)

high_low_avg

high_low_avg(
    candles: List[Candle], length: int, index: Optional[int] = None
) -> float

Computes the average of the high-low range over a specified number of candles, including the current candle. The high-low range is the difference between a candle's high and low prices.

Source code in hexital/analysis/utils.py
def high_low_avg(candles: List[Candle], length: int, index: Optional[int] = None) -> float:
    """
    Computes the average of the high-low range over a specified number of candles,
    including the current candle. The high-low range is the difference between a candle's
    high and low prices.
    """

    if index is None:
        index = len(candles) - 1
    index += 1
    start_index = 0 if index - length < 0 else index - length

    return sum(candles[i].high_low for i in range(start_index, index)) / length

highest

highest(
    candles: List[Candle],
    indicator: str,
    length: int,
    index: Optional[int] = None,
) -> float | None

Computes the highest value of the specified indicator over a given range of candles. The range includes the latest candle by default and considers up to the specified number of candles.

Source code in hexital/analysis/utils.py
def highest(
    candles: List[Candle], indicator: str, length: int, index: Optional[int] = None
) -> float | None:
    """
    Computes the highest value of the specified `indicator` over a given range of candles.
    The range includes the latest candle by default and considers up to the specified number of candles.
    """
    if index is None:
        index = len(candles) - 1

    readings = get_readings_period(candles, indicator, length, index, True)
    return max(readings, default=None)

lowest

lowest(
    candles: List[Candle],
    indicator: str,
    length: int,
    index: Optional[int] = None,
) -> float | None

Computes the lowest value of the specified indicator over a given range of candles. The range includes the latest candle by default and considers up to the specified number of candles.

Source code in hexital/analysis/utils.py
def lowest(
    candles: List[Candle], indicator: str, length: int, index: Optional[int] = None
) -> float | None:
    """
    Computes the lowest value of the specified `indicator` over a given range of candles.
    The range includes the latest candle by default and considers up to the specified number of candles.
    """

    if not candles:
        return None
    if index is None:
        index = len(candles) - 1

    readings = get_readings_period(candles, indicator, length, index, True)
    return min(readings, default=None)

realbody_avg

realbody_avg(
    candles: List[Candle], length: int, index: Optional[int] = None
) -> float

Computes the average real body of a specified number of candles, including the current candle. The real body is calculated as the absolute difference between a candle's open and close prices.

Source code in hexital/analysis/utils.py
def realbody_avg(candles: List[Candle], length: int, index: Optional[int] = None) -> float:
    """
    Computes the average real body of a specified number of candles, including the current candle.
    The real body is calculated as the absolute difference between a candle's open and close prices.
    """

    if index is None:
        index = len(candles) - 1
    index += 1
    start_index = 0 if index - length < 0 else index - length

    return sum(candles[i].realbody for i in range(start_index, index)) / length

realbody_gapdown

realbody_gapdown(candle: Candle, candle_two: Candle) -> bool

Computes if a candle has a real body gap-down compared to a previous candle. A gap-down occurs when the maximum value of the current candle's real body (i.e., the higher of its open or close) is less than the minimum value of the previous candle's real body (i.e., the lower of its open or close).

Source code in hexital/analysis/utils.py
def realbody_gapdown(candle: Candle, candle_two: Candle) -> bool:
    """
    Computes if a candle has a real body gap-down compared to a previous candle.
    A gap-down occurs when the maximum value of the current candle's real body
    (i.e., the higher of its open or close) is less than the minimum value
    of the previous candle's real body (i.e., the lower of its open or close).
    """

    return max(candle.open, candle.close) < min(candle_two.open, candle_two.close)

realbody_gapup

realbody_gapup(candle: Candle, candle_two: Candle) -> bool

Computes if a candle has a real body gap-up compared to a previous candle. A gap-up occurs when the minimum value of the current candle's real body (i.e., the lower of its open or close) is greater than the maximum value of the previous candle's real body (i.e., the higher of its open or close).

Source code in hexital/analysis/utils.py
def realbody_gapup(candle: Candle, candle_two: Candle) -> bool:
    """
    Computes if a candle has a real body gap-up compared to a previous candle.
    A gap-up occurs when the minimum value of the current candle's real body
    (i.e., the lower of its open or close) is greater than the maximum value
    of the previous candle's real body (i.e., the higher of its open or close).
    """

    return min(candle.open, candle.close) > max(candle_two.open, candle_two.close)

shadow_lower_avg

shadow_lower_avg(
    candles: List[Candle], length: int, index: Optional[int] = None
) -> float

Computes the average lower shadow over a specified number of candles, including the current candle. The lower shadow is the difference between a candle's high price and either its open or close price.

Source code in hexital/analysis/utils.py
def shadow_lower_avg(candles: List[Candle], length: int, index: Optional[int] = None) -> float:
    """
    Computes the average lower shadow over a specified number of candles, including the current candle.
    The lower shadow is the difference between a candle's high price and either its open or close price.
    """
    if index is None:
        index = len(candles) - 1
    index += 1
    start_index = 0 if index - length < 0 else index - length

    return sum(candles[i].shadow_lower for i in range(start_index, index)) / length

shadow_upper_avg

shadow_upper_avg(
    candles: List[Candle], length: int, index: Optional[int] = None
) -> float

Computes the average upper shadow over a specified number of candles, including the current candle. The upper shadow is the difference between a candle's high price and either its open or close price.

Source code in hexital/analysis/utils.py
def shadow_upper_avg(candles: List[Candle], length: int, index: Optional[int] = None) -> float:
    """
    Computes the average upper shadow over a specified number of candles, including the current candle.
    The upper shadow is the difference between a candle's high price and either its open or close price.
    """
    if index is None:
        index = len(candles) - 1
    index += 1
    start_index = 0 if index - length < 0 else index - length

    return sum(candles[i].shadow_upper for i in range(start_index, index)) / length