Adding an Indicator
To add a custom indicator to the project, follow these guidelines. Every custom indicator must extend the BaseIndicator
class and adhere to the specified directory and file structure.
Directory Structure
Add your custom indicator class to the
custom_modules/indicators/
directory:Implement your indicator class in a Python file named after your indicator.
Implementing a Custom Indicator
Class Definition:
Your indicator class must extend the
BaseIndicator
class.Here's an example of a custom indicator implementation:
Requirements:
Implement the
running_calc(popped_data_point, new_data_point)
method to define the indicator's calculation logic.Use the
self.time_series
to maintain the data points within the indicator's rolling window (N
size specified in the config).Update
self.result
with the calculated result of the indicator in each window.
State Management:
The
BaseIndicator
class maintains an internal time series and state. You can extend this state or use additional internal variables for more complex calculations.
Configuration:
Indicators must be initialized with a
config
dictionary containing all required parameters (e.g., the window sizeN
).
Accessing and Using Indicators
Custom indicators can be used in strategies or other components by importing and instantiating them:
Example Directory Structure
Assuming the indicator is named custom_indicator
:
Notes on Indicator Logic
Rolling Window Calculations: The
running_calc()
method provides a streamlined way to perform calculations within a rolling window. When a new data point is added, the oldest data point is removed (if the window size is reached).State Handling: Use the
self.states
attribute if you need to maintain additional state data across calculations.Thread Safety: The
BaseIndicator
class is not thread-safe. If your use case requires thread safety, you should implement appropriate synchronization mechanisms.
By following these guidelines, your custom indicator will integrate seamlessly with the project, ensuring compatibility and adherence to project conventions. This modular structure allows for easy addition, management, and testing of new indicators.
Last updated