- Introduced a comprehensive user indicator management system in `components/charts/indicator_manager.py`, allowing users to create, edit, and manage custom indicators with JSON persistence. - Added new default indicators in `components/charts/indicator_defaults.py` to provide users with immediate options for technical analysis. - Enhanced the chart rendering capabilities by implementing the `create_chart_with_indicators` function in `components/charts/builder.py`, supporting both overlay and subplot indicators. - Updated the main application layout in `app.py` to include a modal for adding and editing indicators, improving user interaction. - Enhanced documentation to cover the new indicator system, including a quick guide for adding new indicators and detailed usage examples. - Added unit tests to ensure the reliability and functionality of the new indicator management features.
133 lines
4.5 KiB
Python
133 lines
4.5 KiB
Python
"""
|
|
Default Indicator Creation
|
|
|
|
This module creates a set of default indicators that users can start with.
|
|
These are common indicator configurations that are immediately useful.
|
|
"""
|
|
|
|
from .indicator_manager import get_indicator_manager, IndicatorType, DisplayType
|
|
|
|
|
|
def create_default_indicators():
|
|
"""Create default indicators if they don't exist."""
|
|
manager = get_indicator_manager()
|
|
|
|
# Check if we already have indicators
|
|
existing_indicators = manager.list_indicators()
|
|
if existing_indicators:
|
|
manager.logger.info(f"Found {len(existing_indicators)} existing indicators, skipping defaults creation")
|
|
return
|
|
|
|
# Define default indicators
|
|
default_indicators = [
|
|
# Moving Averages
|
|
{
|
|
"name": "SMA 20",
|
|
"description": "20-period Simple Moving Average for short-term trend",
|
|
"type": IndicatorType.SMA.value,
|
|
"parameters": {"period": 20},
|
|
"color": "#007bff"
|
|
},
|
|
{
|
|
"name": "SMA 50",
|
|
"description": "50-period Simple Moving Average for medium-term trend",
|
|
"type": IndicatorType.SMA.value,
|
|
"parameters": {"period": 50},
|
|
"color": "#6c757d"
|
|
},
|
|
{
|
|
"name": "EMA 12",
|
|
"description": "12-period Exponential Moving Average for fast signals",
|
|
"type": IndicatorType.EMA.value,
|
|
"parameters": {"period": 12},
|
|
"color": "#ff6b35"
|
|
},
|
|
{
|
|
"name": "EMA 26",
|
|
"description": "26-period Exponential Moving Average for slower signals",
|
|
"type": IndicatorType.EMA.value,
|
|
"parameters": {"period": 26},
|
|
"color": "#28a745"
|
|
},
|
|
|
|
# Oscillators
|
|
{
|
|
"name": "RSI 14",
|
|
"description": "14-period RSI for momentum analysis",
|
|
"type": IndicatorType.RSI.value,
|
|
"parameters": {"period": 14},
|
|
"color": "#20c997"
|
|
},
|
|
{
|
|
"name": "RSI 21",
|
|
"description": "21-period RSI for less sensitive momentum signals",
|
|
"type": IndicatorType.RSI.value,
|
|
"parameters": {"period": 21},
|
|
"color": "#17a2b8"
|
|
},
|
|
|
|
# MACD Variants
|
|
{
|
|
"name": "MACD Standard",
|
|
"description": "Standard MACD (12, 26, 9) for trend changes",
|
|
"type": IndicatorType.MACD.value,
|
|
"parameters": {"fast_period": 12, "slow_period": 26, "signal_period": 9},
|
|
"color": "#fd7e14"
|
|
},
|
|
{
|
|
"name": "MACD Fast",
|
|
"description": "Fast MACD (5, 13, 4) for quick signals",
|
|
"type": IndicatorType.MACD.value,
|
|
"parameters": {"fast_period": 5, "slow_period": 13, "signal_period": 4},
|
|
"color": "#dc3545"
|
|
},
|
|
|
|
# Bollinger Bands
|
|
{
|
|
"name": "Bollinger Bands",
|
|
"description": "Standard Bollinger Bands (20, 2) for volatility analysis",
|
|
"type": IndicatorType.BOLLINGER_BANDS.value,
|
|
"parameters": {"period": 20, "std_dev": 2.0},
|
|
"color": "#6f42c1"
|
|
},
|
|
{
|
|
"name": "Bollinger Tight",
|
|
"description": "Tight Bollinger Bands (20, 1.5) for sensitive volatility",
|
|
"type": IndicatorType.BOLLINGER_BANDS.value,
|
|
"parameters": {"period": 20, "std_dev": 1.5},
|
|
"color": "#e83e8c"
|
|
}
|
|
]
|
|
|
|
# Create indicators
|
|
created_count = 0
|
|
for indicator_config in default_indicators:
|
|
indicator = manager.create_indicator(
|
|
name=indicator_config["name"],
|
|
indicator_type=indicator_config["type"],
|
|
parameters=indicator_config["parameters"],
|
|
description=indicator_config["description"],
|
|
color=indicator_config["color"]
|
|
)
|
|
|
|
if indicator:
|
|
created_count += 1
|
|
manager.logger.info(f"Created default indicator: {indicator.name}")
|
|
else:
|
|
manager.logger.error(f"Failed to create indicator: {indicator_config['name']}")
|
|
|
|
manager.logger.info(f"Created {created_count} default indicators")
|
|
|
|
|
|
def ensure_default_indicators():
|
|
"""Ensure default indicators exist (called during app startup)."""
|
|
try:
|
|
create_default_indicators()
|
|
except Exception as e:
|
|
manager = get_indicator_manager()
|
|
manager.logger.error(f"Error creating default indicators: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Create defaults when run directly
|
|
create_default_indicators() |