Skip to content

trading.indicators.state.ema_state

trading.indicators.state.ema_state

EMAState

Bases: Enum

Current location of the fast EMA relative to the slow EMA for a bar.

Attributes:

Name Type Description
BELOW

The fast EMA is below the slow EMA.

ABOVE

The fast EMA is above the slow EMA.

get_state classmethod

get_state(fast_ema: float, slow_ema: float) -> EMAState

Returns the state of the fast EMA relative to the slow EMA (above or below).

Parameters:

Name Type Description Default
fast_ema float

The fast EMA value for the current bar.

required
slow_ema float

The slow EMA value for the current bar.

required

Returns:

Name Type Description
EMAState EMAState

Whether the fast EMA is below or above the slow EMA.

Source code in src\contango\trading\indicators\state\ema_state.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@classmethod
def get_state(cls, fast_ema: float, slow_ema: float) -> EMAState:
    """
    Returns the state of the fast EMA relative to the slow EMA (above or below).

    Args:
        fast_ema: The fast EMA value for the current bar.
        slow_ema: The slow EMA value for the current bar.

    Returns:
        EMAState: Whether the fast EMA is below or above the slow EMA.
    """
    if fast_ema > slow_ema:
        return EMAState.ABOVE
    else:
        return EMAState.BELOW