IndicatorSet#
API documentation for tradeexecutor.strategy.pandas_trader.indicator.IndicatorSet Python class in Trading Strategy framework.
- class IndicatorSet[source]#
Bases:
object
Define the indicators that are needed by a trading strategy.
For backtesting, indicators are precalculated
For live trading, these indicators are recalculated for the each decision cycle
Indicators are calculated for each given trading pair, unless specified otherwise, and a separate
IndicatorKey
is generated bygenerate_combinations()
See
CreateIndicatorsProtocolV2
for usage.Methods
__init__
()add
(name, func[, parameters, source, order])Add a new indicator to this indicator set.
from_indicator_keys
(indicator_keys)Reconstruct the original indicator set from keys.
generate_combinations
(strategy_universe)Create all indiviual indicator (per pair) we need to calculate for this trading universe.
How many indicators we have
get_indicator
(name)Get a named indicator definition.
get_label
()has_indicator
(name)iterate
()Attributes
Map indicators by the indicator name to their definition
- indicators: dict[str, tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition]#
Map indicators by the indicator name to their definition
- get_indicator(name)[source]#
Get a named indicator definition.
- Parameters:
name (str) –
- Return type:
tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition | None
- add(name, func, parameters=None, source=IndicatorSource.close_price, order=1)[source]#
Add a new indicator to this indicator set.
Builds an indicator set for the trading strategy, called from create_indicators.
See
CreateIndicatorsProtocol
for usage.- Parameters:
name (str) –
Name of the indicator.
Human-readable name. If the same function is calculated multiple times, e.g. EMA, you can have names like ema_short and ema_long.
func (Callable) –
Python function to be called.
Function takes arguments from parameters dict. It must return either
pd.DataFrame
orpd.Series
.parameters (dict | None) –
Parameters to be passed to the Python function.
Raw func Python arguments.
You can pass parameters as is from StrategyParameters.
source (IndicatorSource) –
Data source on this indicator is calculated.
Defaults to the close price for each trading pair. To calculate universal indicators set to
IndicatorSource.strategy_universe
.order –
Dependency resolution order.
See
tradingstrategy.strategy.pandas_trader.indicator.IndicatorKey.order
parameter.
- generate_combinations(strategy_universe)[source]#
Create all indiviual indicator (per pair) we need to calculate for this trading universe.
Because most indicators are per pair, we need to combine the trading pair universe with wanted indicators to get the final set of indicators we need to calcuate
Note that some indicator are calculated over the whole universe or an external source and may not have a trading pair defined
- Returns:
IndicatorKey iterator.
(Trading pair, indicator) iterator
- Parameters:
strategy_universe (TradingStrategyUniverse) –
- Return type:
- static from_indicator_keys(indicator_keys)[source]#
Reconstruct the original indicator set from keys.
Used when grid search passes data around processes
- Parameters:
indicator_keys (set[tradeexecutor.strategy.pandas_trader.indicator.IndicatorKey]) –
- Return type: