Define user-authored indicator calculations for supported workflows
Define user-authored indicator calculations in Python for supported Investfly workflows.
Investfly exposes a catalog of standard technical indicators. These built-in indicators can be referenced in user-authored algorithmic trading strategies and can be utilized in screeners, automated trade signals, and backtesting engines.
You can implement custom calculations in Python and use them in supported workflows. Availability, data, execution limits, and compatibility depend on the current platform and workflow. A custom indicator is not a recommendation and does not predict market movements or strategy results.
This guide assumes proficiency with Python programming and object-oriented concepts for developing algorithmic trading indicators.
The Indicator class provides the foundational framework for
creating any type of technical indicator for algorithmic trading. Its
flexible design accommodates indicators based on various data inputs,
including price action, volume patterns, market sentiment, or alternative
data sources.
While we provide the SecurityDataProvider class for historical
market data access, advanced algorithmic traders can incorporate external
data sources using Python's requests module to create
indicators based on unique datasets like social media sentiment, options
flow, or macroeconomic indicators.
To develop a proprietary trading indicator, extend the
Indicator base class and implement these required methods:
The IndicatorSpec class defines the metadata for your custom
algorithmic trading indicator, including its name, description, required
parameters, and output value type. This specification serves as the
blueprint for how your indicator will be presented and used throughout the
Investfly platform.
When implementing the getIndicatorSpec method, you must return
an instance of IndicatorSpec with all required metadata
properly defined:
Your custom indicator code runs in a restricted and sandboxed Python environment for security reasons. This ensures that the code cannot perform any malicious tasks on our servers. Only a few white-listed safe modules can be imported. System operations such as file IO are not allowed, and wildcard imports are also restricted.
If you find any safe function that is blocked, please contact us, and we can make it available.
The core functionality of your custom indicator is implemented in the
computeSeries method. This method receives historical price data and
your indicator's parameters, and must return a series of dated values representing
your indicator's calculations.
Keep calculations within the execution limits documented by the current platform. Data timing, system load, and execution limits can affect evaluation.
Below is a complete example of a custom indicator that generates buy signals when a fast moving average crosses above a slow moving average:
After defining your custom indicator class, you need to register it with Investfly's platform to make it available for use in your trading strategies, screeners, and charts.
Navigate to User Settings > Custom Indicators in the Investfly platform. Paste your Python code into the editor and click "Save & Compile". Once successfully validated, your custom indicator will be available throughout the platform alongside standard indicators.
After deployment, your custom algorithmic trading indicator can be:
When developing custom indicators for algorithmic trading strategies, consider these best practices:
Optimize your code for speed using vectorized operations with NumPy whenever possible. The platform imposes a 1-second execution limit to maintain responsiveness during live trading.
Implement robust error handling to manage edge cases like insufficient data points or unexpected input values. Return appropriate fallback values when calculations cannot be performed.
Ensure your indicator only uses data that would have been available at each historical point to prevent unrealistic backtesting results and false trade signals.
Extensively backtest your custom indicators across different market conditions and timeframes to validate their reliability before using them in live algorithmic trading.
Test custom calculations, handle missing or unexpected data, and review every strategy rule that references the indicator. Historical and simulated results do not predict live results.
Start automating your trading strategies today with our free 14-day trial.
Start Free TrialNo credit card required.