Indicator ValueType can possibly used by Investfly to validate expression and optimize experience for users
For e.g, all Indicators of same valueType can be plotted in the same y-axis
PRICE =
PRICE
PERCENT =
PERCENT
RATIO =
RATIO
BOOLEAN =
BOOLEAN
NUMBER =
NUMBER
classIndicatorId(builtins.str, enum.Enum):
Technical indicators supported by Investfly.
This enum lists all standard technical indicators that can be used in trading
strategies for technical analysis. The enum values are string identifiers that
must be used when calling computeIndicatorSeries() in DataService.
Note: The enum values are strings (not the enum names) to support both standard
and custom indicators. When using standard indicators, use the .value property
or the string directly (e.g., "SMA" or StandardIndicatorId.SMA.value).
Parameter Type (INTEGER, FLOAT, BOOLEAN, STRING, BARINTERVAL)
required: bool =
True
Whether this parameter is required or optional
defaultValue: typing.Any | None =
None
The default value for the parameter to auto-populate mainly in UI
options: Optional[List[Any]] =
None
Valid value options (if any). If specified, then in the UI, this parameter renders as a dropdown select list.
If left as None, parameter renders and freeform input text field.
Validate that required fields are provided and have correct types
classIndicator(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.
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.
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.
Interface for accessing market data in indicators.
This interface provides market data access methods without requiring
a security parameter. The security context is captured when the service
is instantiated, allowing indicators to remain pure mathematical functions.
Attributes:
ALL_BARS: Constant value (-1) used to retrieve all available historical bars.
Retrieve historical bars for the configured security.
The bar interval and lookback are captured when the service is instantiated.
If lookback > 0, the most recent 'lookback' bars are automatically excluded
from the result, effectively shifting the time window backwards.
Returns:
List of Bar objects containing OHLC data in chronological order (oldest first).
If lookback > 0, the result excludes the most recent 'lookback' bars.
Raises:
NoDataException: If the requested data is not available.
Retrieve latest news articles for the configured security.
This method returns recent news articles related to the configured
security. News data can be used for sentiment analysis or event-driven
trading strategies.
Returns:
List of StockNews objects containing news articles. Returns an
empty list if no news is available.
classIndicatorSeries:
Represents a series of indicator values over time.
Provides methods to access the latest value and detect crossovers.