Skip to content

trading.indicators.state.rsi_state

trading.indicators.state.rsi_state

RSIState

Bases: Enum

The position of the RSI relative to its thresholds.

Attributes:

Name Type Description
OVERSOLD

RSI is below lower threshold.

NEUTRAL

RSI is between thresholds.

OVERBOUGHT

RSI is above upper threshold.

get_state classmethod

get_state(rsi: float, lower_threshold: float, upper_threshold: float) -> RSIState

Returns the state of the RSI relative to its thresholds.

Parameters:

Name Type Description Default
rsi float

The RSI value for the current bar.

required
lower_threshold float

The lower threshold for the RSI (determines if oversold).

required
upper_threshold float

The upper threshold for the RSI (determines if overbought).

required

Returns:

Name Type Description
RSIState RSIState

Whether the RSI is above or below their respective thresholds (oversold or overbought).

Source code in src\contango\trading\indicators\state\rsi_state.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@classmethod
def get_state(
    cls,
    rsi: float, 
    lower_threshold: float, 
    upper_threshold: float
) -> RSIState:
    """
    Returns the state of the RSI relative to its thresholds.

    Args:
        rsi: The RSI value for the current bar.
        lower_threshold: The lower threshold for the RSI (determines if oversold).
        upper_threshold: The upper threshold for the RSI (determines if overbought).

    Returns:
        RSIState: Whether the RSI is above or below their respective thresholds (oversold or overbought).
    """
    if rsi < lower_threshold:
        return RSIState.OVERSOLD
    elif rsi > upper_threshold:
        return RSIState.OVERBOUGHT
    else:
        return RSIState.NEUTRAL