Skip to content

Relative Strength Index (RSI)

RSI

Relative Strength Index (RSI) representation.

Attributes:

Name Type Description
periods

Number of periods to calculate RSI

value_class Type[estrade.graph.base_indicator.BaseIndicatorValue]

Class of value to generate on new frame.

frame_set Optional[estrade.graph.frame_set.FrameSet]

The FrameSet instance that send ticks to this instance.

market_open_only bool

apply this indicator only when market is open.

ref str

reference of this instance

epic: Optional[Epic] inherited property readonly

Return the Epic associated to this instance.

Returns:

Type Description
Optional[Epic]

Epic associated to this instance.

ref: str inherited property writable

Return ref of current instance.

Returns:

Type Description
str

reference of current instance.

__init__(self, periods, **kwargs) special

Create a new instance of a RSI Generator.

Parameters:

Name Type Description Default
periods int

periods

required
kwargs

see BaseIndicator

{}
Source code in estrade/graph/indicators/rsi.py
def __init__(self, periods: int, **kwargs):
    """
    Create a new instance of a RSI Generator.

    Arguments:
        periods: periods
        kwargs: see [`BaseIndicator`][estrade.graph.base_indicator.BaseIndicator]
    """
    BaseIndicator.__init__(
        self,
        value_class=RSIValue,
        **kwargs,
    )

    self.periods = periods
    self.rsi_periods: Optional[int] = None

build_value_from_frame(self, frame, epic_market_open) inherited

Create a new value for this indicator.

This method is triggered when its frame_set create a new Frame.

Parameters:

Name Type Description Default
frame Frame

The newly created frame.

required
epic_market_open bool

is the epic open?

required

Returns:

Type Description
Optional[BaseIndicatorValue]

An instance of this instance value_class (None Market is not open).

Source code in estrade/graph/indicators/rsi.py
def build_value_from_frame(
    self, frame: "Frame", epic_market_open: bool
) -> Optional["BaseIndicatorValue"]:
    """
    Create a new value for this indicator.

    This method is triggered when its `frame_set` create a new
        [`Frame`][estrade.graph.frame_set.Frame].

    Arguments:
        frame: The newly created frame.
        epic_market_open: is the epic open?

    Returns:
        An instance of this instance `value_class` (`None` Market is not open).
    """
    if not self.market_open_only or epic_market_open:
        new_value = self.value_class(
            indicator=self,
            frame=frame,
        )
        return new_value
    return None

RSI Value

Relative Strength Index (RSI) Value representation.

Attributes:

Name Type Description
indicator estrade.graph.base_indicator.BaseIndicator

Parent indicator.

frame estrade.graph.frame_set.Frame

Parent frame.

last_changes List[float]

List of last frames changes

value Optional[float]

value of the RSI

closed: bool inherited property readonly

Check if the parent frame is closed.

Returns:

Type Description
bool

Is the parent frame closed?

nb_ticks: int inherited property readonly

Count of Ticks received by the parent frame.

Returns:

Type Description
int

Number of Ticks received by the parent frame.

next: Optional[BaseIndicatorValue] inherited property readonly

Return the value of this indicator on the next frame.

Returns:

Type Description
Optional[BaseIndicatorValue]

This indicator value on the next frame (None if the parent have no next frame)

previous: Optional[BaseIndicatorValue] inherited property readonly

Return the value of this indicator on the previous frame.

Returns:

Type Description
Optional[BaseIndicatorValue]

This indicator value on the previous frame (None if the parent have no previous frame)

__init__(self, indicator, frame) special

Create a new RSI Value for the input Frame.

Parameters:

Name Type Description Default
indicator RSI

parent indicator

required
frame Frame

parent frame

required
Source code in estrade/graph/indicators/rsi.py
def __init__(
    self,
    indicator: "RSI",
    frame: "Frame",
) -> None:
    """
    Create a new RSI Value for the input Frame.

    Arguments:
        indicator: parent indicator
        frame: parent frame
    """
    BaseIndicatorValue.__init__(self, indicator=indicator, frame=frame)
    if (
        not hasattr(self.indicator, "rsi_periods")
        or not self.indicator.rsi_periods  # type: ignore
    ):
        raise BaseIndicatorException("Invalid RSI Value parent")
    self.rsi_periods = self.indicator.rsi_periods  # type: ignore

    self.last_changes: List[float] = []
    if self.previous:
        self.last_changes = self.previous.extended_changes[:]  # type: ignore

    self.value: Optional[float] = None

    if self.rsi_periods:
        max_last_changes_size = self.rsi_periods - 1
        self.last_changes = self.last_changes[(max_last_changes_size * -1) :]

        self._update_rsi()