Developing Custom Indicators
Relevant source files
The following files were used as context for generating this wiki page:
Custom indicator development in OpenAlgo involves utilizing the built-in ta (Technical Analysis) library, which is a high-performance Rust-backed PyO3 extension. This architecture allows developers to create complex technical analysis tools that integrate seamlessly with the platform's visual Flow editor, Python Strategy Host, and analytical tools.
Developers can organize their custom work within the workspace/indicators/custom/ directory, which serves as a dedicated environment for indicator modules. The platform supports a wide range of standard indicator categories, including trend, momentum, volatility, volume, and statistical functions, providing a robust foundation for building specialized trading logic.
Sources: okf/log.md, okf/indicators/introduction.md, workspace/readme.md:5-15
Core Indicator Library (ta)
The foundation of technical analysis in OpenAlgo is the ta library. Unlike many Python-based platforms that rely on pure Python implementations, OpenAlgo uses a Rust-backed extension to ensure low-latency computation during live execution and backtesting.
Architecture and Data Flow
The indicator system processes OHLCV (Open, High, Low, Close, Volume) data through a series of introspection and computation steps. The indicator_service is responsible for mapping series parameters to data columns and executing computations.
The diagram shows how OHLCV records are processed by the internal service to produce indicator results.
Sources: scripts/generate_indicator_reference.py:38-75, okf/log.md
Key Components
| Component | Description |
|---|---|
openalgo.ta | The core Rust-backed PyO3 extension containing all technical indicator functions. |
indicator_service | Internal service layer that handles indicator discovery, parameter mapping, and execution. |
_SERIES_PARAM_TO_COLUMN | A mapping within the service that links function parameters (like close or high) to OHLCV data columns. |
compute_indicator | The primary function used to execute an indicator against a set of data records with specific parameters. |
Sources: scripts/generate_indicator_reference.py:27-35, okf/log.md
Development Environment: The Workspace
OpenAlgo provides a structured workspace/ directory for developing custom indicators and related tools. This area is gitignored by default, allowing for local experimentation without affecting the main repository.
Workspace Structure for Indicators
Custom development is organized into several subdirectories:
workspace/indicators/custom/: The primary location for custom indicator modules.workspace/indicators/charts/: Scripts for rendering indicator-based charts (stems typically follow<indicator>_<symbol>_<interval>.py).workspace/indicators/scanners/: Development of indicator-based market scanners.workspace/indicators/feeds/: Live WebSocket feed integrations.
Sources: workspace/readme.md:5-15, workspace/readme.md:56-61
Integration with Flow and Strategies
Custom and standard indicators are exposed to the platform's visual strategy builder ("Flow") and the Python Strategy Host.
Flow Indicator Configuration
In the Flow editor, indicators are configured using a specific JSON structure. Parameters must be passed as a JSON string within the params field to ensure correct parsing by the executor.
{
"id": "node_2",
"type": "indicator",
"data": {
"indicatorName": "rsi",
"params": "{\"period\": 14}",
"outputVariable": "r"
}
}
Sources: scripts/generate_indicator_reference.py:129-145
Output Handling
Indicators in OpenAlgo provide structured outputs accessible via three primary time-references:
latest: The value for the most recent bar.previous: The value for the bar immediately preceding the latest.at_offset: The value at a specific historical point defined byoffsetBars.
For multi-output indicators (like MACD or Bollinger Bands), results are indexed as out0, out1, etc.
Sources: scripts/generate_indicator_reference.py:107-110, scripts/generate_indicator_reference.py:146-150
Standard Indicator Categories
When developing custom logic, developers can leverage existing functions from these categories:
- Trend: Functions like SMA, EMA, WMA, HMA, Supertrend, and Ichimoku Cloud.
- Momentum: RSI, MACD, Stochastic, CCI, and Williams %R.
- Utility: Logic for
crossover,crossunder,highest,lowest, andvaluewhen. - Statistical: Linear Regression, Correlation, Beta, and Variance.
Sources: okf/indicators/trend.md, okf/indicators/momentum.md, okf/indicators/utility.md, okf/indicators/statistical.md
Best Practices for Custom Development
- Deterministic Testing: Indicators should be verified against a deterministic OHLCV set to ensure they produce non-null values before being used in strategies.
- Naming Conventions: Use the standard stem format
<indicator>_<symbol>_<interval>.pyfor chart and test scripts to maintain consistency. - Isolated Research: Utilize
workspace/research/for ad-hoc notebooks and exploratory work before moving stabilized logic intoworkspace/indicators/custom/. - Environment Consistency: When running scripts, use OpenAlgo's environment via
uv runto ensure all main dependencies likepandas,numpy, andplotlyare available.
Sources: scripts/generate_indicator_reference.py:43-55, workspace/readme.md:46-52, workspace/research/readme.md
OpenAlgo's custom indicator framework provides a high-performance, Rust-backed environment that bridges the gap between raw data analysis and automated execution across multiple trading surfaces.