Skip to content

contango.stream.indicators.state.sma_state

contango.stream.indicators.state.sma_state

SMAState

Bases: Enum

The position of the fast SMA relative to a slow SMA.

Attributes:

Name Type Description
BELOW

The fast SMA below the slow SMA.

ABOVE

The fast SMA is above the slow SMA.

get_state classmethod

get_state(fast_sma: float, slow_sma: float) -> SMAState

Returns the SMA state of the fast SMA relative to the slow SMA.

Parameters:

Name Type Description Default
fast_sma float

The value of the fast SMA for the current bar.

required
slow_sma float

The value of the slow SMA for the current bar.

required

Returns:

Name Type Description
SMAState SMAState

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

Source code in src\contango\stream\indicators\state\sma_state.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@classmethod
def get_state(cls, fast_sma: float, slow_sma: float) -> SMAState:
    """
    Returns the SMA state of the fast SMA relative to the slow SMA.

    Args:
        fast_sma: The value of the fast SMA for the current bar.
        slow_sma: The value of the slow SMA for the current bar.

    Returns:
        SMAState: Whether the fast SMA is above or below the slow SMA.
    """
    if fast_sma > slow_sma:
        return SMAState.ABOVE
    else:
        return SMAState.BELOW