Skip to content

Base Indicator

BaseIndicator is an abstract representation of an Indicator. It is registered on FrameSet.

BaseIndicatorValue is an abstract representation of an indicator value. On every new Frame created by a FrameSet, indicators values are created on the new Frame.


BaseIndicator

Base class of an Indicator.

Attributes:

Name Type Description
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] 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, value_class, ref=None, market_open_only=False) special

Create a new indicator.

Parameters:

Name Type Description Default
value_class Type[BaseIndicatorValue]

Class of value to generate on new frame.

required
market_open_only bool

apply this indicator only when market is open.

False
ref Optional[str]

reference of this instance

None
Source code in estrade/graph/base_indicator.py
def __init__(
    self,
    value_class: Type["BaseIndicatorValue"],
    ref: Optional[str] = None,
    market_open_only: bool = False,
) -> None:
    """
    Create a new indicator.

    Arguments:
        value_class: Class of value to generate on new frame.
        market_open_only: apply this indicator only when market is open.
        ref: reference of this instance
    """
    RefMixin.__init__(self, ref=ref)

    self.value_class = value_class
    self.market_open_only = market_open_only
    self.frame_set: Optional["FrameSet"] = None

build_value_from_frame(self, frame, epic_market_open)

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/base_indicator.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

BaseIndicatorValue

Base class of an Indicator value.

Attributes:

Name Type Description
indicator estrade.graph.base_indicator.BaseIndicator

Parent indicator.

frame estrade.graph.frame_set.Frame

Parent frame.

self.first_tick estrade.tick.Tick

first tick registered by indicator value

self.high_tick estrade.tick.Tick

highest tick registered by indicator value

self.low_tick estrade.tick.Tick

lowest tick registered by indicator value

self.last_tick estrade.tick.Tick

last tick registered by indicator value

closed: bool property readonly

Check if the parent frame is closed.

Returns:

Type Description
bool

Is the parent frame closed?

nb_ticks: int 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] 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] 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 indicator value.

Parameters:

Name Type Description Default
indicator BaseIndicator

Parent indicator.

required
frame Frame

Parent frame.

required
Source code in estrade/graph/base_indicator.py
def __init__(
    self,
    indicator: "BaseIndicator",
    frame: "Frame",
) -> None:
    """
    Create a new indicator value.

    Arguments:
        indicator: Parent indicator.
        frame: Parent frame.

    """
    self.indicator = indicator
    self.frame = frame
    self.first_tick = self.frame.last_tick
    self.high_tick = self.frame.last_tick
    self.low_tick = self.frame.last_tick
    self.last_tick = self.frame.last_tick