investfly.models.indicator.Indicator

class Indicator(abc.ABC):

The primary class to implement a custom Indicator. A Custom Indicator is like standard indicator (e.g SMA, RSI) and can be used in any place that standard indicator can be used (e.g screener, charts, strategy etc) Investfly comes with a set of standard indicators. If you find that the indicator you want is not supported or you can a small variation (e.g SMA but with using Heikin Ashi Candles), then you can use this function

Indicators receive market data through an IndicatorDataService injected via setDataService(). This service abstracts away the security context, allowing indicators to be pure mathematical functions.

Indicator()

Initialize the indicator.

The data service will be set via setDataService() after instantiation.

def setDataService( self, dataService: investfly.models.indicator.IndicatorDataService) -> None:

Set the data service for this indicator.

This method is called by IndicatorService after instantiating the indicator.

Args: dataService: The data service for accessing bars, quotes, financials, and news for a specific security.

@abstractmethod
def getIndicatorSpec(self) -> investfly.models.indicator.IndicatorSpec:

Return IndicatorSpec with name, description, required params, and valuetype.

See IndicatorSpec abstract class for more details.

Returns: IndicatorSpec: The indicator specification object.

@abstractmethod
def computeSeries( self, params: Dict[str, Any]) -> List[investfly.models.common.DatedValue]:

Compute indicator series based on provided parameters.

This function must return List of indicator values instead of only the most recent single value because indicator series is required to plot in the price chart and also to use in backtest.

The indicator should use self.dataService to retrieve the data it needs (bars, quotes, financials, news). The timestamps in the DatedValue must correspond to timestamps in the retrieved data.

Args: params: User supplied indicator parameter values. The keys match the keys from IndicatorSpec.params.

Note: The params[StandardParams.COUNT] parameter specifies how many indicator values the function should return in the list. - If COUNT is NOT specified: Compute and return the FULL series based on all available data. - If COUNT is specified: Return only the last COUNT values.

For optimal performance, use COUNT to only request the minimum necessary amount of historical data.
For example: to compute a 20-period SMA and return a single most recent value (`count=1`), you should request 20 bars. 
If `count=2`, you should request 21 bars; in general, for SMA, the number of bars needed is `period + count - 1`.
If COUNT is not specified, request ALL_BARS to compute the full series.

Returns: List of DatedValue representing indicator values for each time unit.

def computeCurrent( self, params: Dict[str, Any]) -> investfly.models.common.DatedValue:

Compute the current (most recent) indicator value.

This default implementation calls computeSeries() and returns the last value. If computing just the current value is more performant than computing the full series, Indicator implementations should override this method.

Args: params: User supplied indicator parameter values. Same as computeSeries().

Returns: The most recent DatedValue from the indicator series.

Raises: IndexError: If the indicator series is empty.

def validateParams(self, paramVals: Dict[str, Any]):
def addStandardParamsToDef( self, indicatorDef: investfly.models.indicator.IndicatorSpec):