Base
IndicatorBase
Bases: ABC
Base class for scalar technical indicators with per-symbol history.
The class provides a thread-safe mechanism for storing and retrieving indicator values computed from incoming market bars, keyed by symbol. It does not manage input windows or rolling computation state.
Subclasses define a stable indicator identifier via the name property and implement _compute_indicator, which computes a single scalar value per incoming bar.
Indicators with multiple conceptual outputs must be implemented as multiple single-output indicators (e.g. Bollinger Bands must be implemented via three separate indicators BBUpper, BBMiddle, and BBLower).
The update mechanism is thread-safe.
Indicator computation is performed outside the internal lock.
Subclasses that maintain internal state are responsible for ensuring its thread safety and must not access _history_data.
Indicator values are stored per symbol in bounded FIFO buffers.
Missing data and out-of-bounds access yield numpy.nan.
The plot_at attribute is an opaque identifier forwarded to the charting backend and has no intrinsic meaning within the indicator subsystem.
name
abstractmethod
property
Canonical indicator name.
Returns:
| Type | Description |
|---|---|
str
|
Stable identifier used for charting and downstream integration. |
Source code in src/onesecondtrader/indicators/base.py
plot_at
property
Plotting identifier.
Returns:
| Type | Description |
|---|---|
int
|
Opaque identifier consumed by the charting backend. |
Source code in src/onesecondtrader/indicators/base.py
__init__(max_history=100, plot_at=99)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_history
|
int
|
Maximum number of indicator values retained per symbol. Cannot be less than 1. |
100
|
plot_at
|
int
|
Opaque plotting identifier forwarded to the charting backend. |
99
|
Source code in src/onesecondtrader/indicators/base.py
_compute_indicator(incoming_bar)
abstractmethod
Compute the indicator value for a single market bar.
This method is executed outside the internal lock.
Implementations must not access _history_data and must ensure thread safety of any internal computation state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incoming_bar
|
BarReceived
|
Market bar used as input for indicator computation. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Computed indicator value. |
Source code in src/onesecondtrader/indicators/base.py
update(incoming_bar)
Update the indicator with a new market bar.
The computed value is appended to the per-symbol history buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incoming_bar
|
BarReceived
|
Market bar triggering the update. |
required |
Source code in src/onesecondtrader/indicators/base.py
latest(symbol)
Return the most recent indicator value for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Symbol identifier. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Most recent value, or |
Source code in src/onesecondtrader/indicators/base.py
__getitem__(key)
Retrieve an indicator value by symbol and index.
Indexing follows standard Python sequence semantics. Negative indices refer to positions relative to the most recent value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
tuple[str, int]
|
|
required |
Returns:
| Type | Description |
|---|---|
float
|
Indicator value at the specified position, or |