- 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.
8.9 KiB
Indicator System Documentation
Overview
The Crypto Trading Bot Dashboard features a comprehensive modular indicator system that allows users to create, customize, and manage technical indicators for chart analysis. The system supports both overlay indicators (displayed on the main price chart) and subplot indicators (displayed in separate panels below the main chart).
Table of Contents
- System Architecture
- Current Indicators
- User Interface
- File Structure
- Adding New Indicators
- Configuration Format
- API Reference
- Troubleshooting
System Architecture
Core Components
components/charts/
├── indicator_manager.py # Core indicator CRUD operations
├── indicator_defaults.py # Default indicator templates
├── layers/
│ ├── indicators.py # Overlay indicator rendering
│ └── subplots.py # Subplot indicator rendering
└── config/
└── indicator_defs.py # Indicator definitions and schemas
config/indicators/
└── user_indicators/ # User-created indicators (JSON files)
├── sma_abc123.json
├── ema_def456.json
└── ...
Key Classes
IndicatorManager: Handles CRUD operations for user indicatorsUserIndicator: Data structure for indicator configurationIndicatorStyling: Appearance and styling configuration- Indicator Layers: Rendering classes for different indicator types
Current Indicators
Overlay Indicators
These indicators are displayed directly on the price chart:
| Indicator | Type | Parameters | Description |
|---|---|---|---|
| Simple Moving Average (SMA) | sma |
period (1-200) |
Average price over N periods |
| Exponential Moving Average (EMA) | ema |
period (1-200) |
Weighted average giving more weight to recent prices |
| Bollinger Bands | bollinger_bands |
period (5-100), std_dev (0.5-5.0) |
Price channels based on standard deviation |
Subplot Indicators
These indicators are displayed in separate panels:
| Indicator | Type | Parameters | Description |
|---|---|---|---|
| Relative Strength Index (RSI) | rsi |
period (2-50) |
Momentum oscillator (0-100 scale) |
| MACD | macd |
fast_period (2-50), slow_period (5-100), signal_period (2-30) |
Moving average convergence divergence |
User Interface
Adding Indicators
- Click "➕ Add New Indicator" button
- Configure Basic Settings:
- Name: Custom name for the indicator
- Type: Select from available indicator types
- Description: Optional description
- Set Parameters: Type-specific parameters appear dynamically
- Customize Styling:
- Color: Hex color code
- Line Width: 1-5 pixels
- Save: Creates a new JSON file and updates the UI
Managing Indicators
- ✅ Checkboxes: Toggle indicator visibility on chart
- ✏️ Edit Button: Modify existing indicator settings
- 🗑️ Delete Button: Remove indicator permanently
Real-time Updates
- Chart updates automatically when indicators are toggled
- Changes are saved immediately to JSON files
- No page refresh required
File Structure
Indicator JSON Format
{
"id": "ema_ca5fd53d",
"name": "EMA 10",
"description": "10-period Exponential Moving Average for fast signals",
"type": "ema",
"display_type": "overlay",
"parameters": {
"period": 10
},
"styling": {
"color": "#ff6b35",
"line_width": 2,
"opacity": 1.0,
"line_style": "solid"
},
"visible": true,
"created_date": "2025-06-04T04:16:35.455729+00:00",
"modified_date": "2025-06-04T04:54:49.608549+00:00"
}
Directory Structure
config/indicators/
└── user_indicators/
├── sma_abc123.json # Individual indicator files
├── ema_def456.json
├── rsi_ghi789.json
└── macd_jkl012.json
Adding New Indicators
For developers who want to add new indicator types to the system, please refer to the comprehensive step-by-step guide:
📋 Quick Guide: Adding New Indicators
This guide covers:
- ✅ Complete 11-step implementation checklist
- ✅ Full code examples (Stochastic Oscillator implementation)
- ✅ File modification requirements
- ✅ Testing checklist and common patterns
- ✅ Tips and best practices
Configuration Format
User Indicator Structure
@dataclass
class UserIndicator:
id: str # Unique identifier
name: str # Display name
description: str # User description
type: str # Indicator type (sma, ema, etc.)
display_type: str # "overlay" or "subplot"
parameters: Dict[str, Any] # Type-specific parameters
styling: IndicatorStyling # Appearance settings
visible: bool = True # Default visibility
created_date: datetime # Creation timestamp
modified_date: datetime # Last modification timestamp
Styling Options
@dataclass
class IndicatorStyling:
color: str = "#007bff" # Hex color code
line_width: int = 2 # Line thickness (1-5)
opacity: float = 1.0 # Transparency (0.0-1.0)
line_style: str = "solid" # Line style
Parameter Examples
# SMA/EMA Parameters
{"period": 20}
# RSI Parameters
{"period": 14}
# MACD Parameters
{
"fast_period": 12,
"slow_period": 26,
"signal_period": 9
}
# Bollinger Bands Parameters
{
"period": 20,
"std_dev": 2.0
}
API Reference
IndicatorManager Class
class IndicatorManager:
def create_indicator(self, name: str, indicator_type: str,
parameters: Dict[str, Any], **kwargs) -> Optional[UserIndicator]
def load_indicator(self, indicator_id: str) -> Optional[UserIndicator]
def update_indicator(self, indicator_id: str, **kwargs) -> bool
def delete_indicator(self, indicator_id: str) -> bool
def list_indicators(self) -> List[UserIndicator]
def get_indicators_by_type(self, display_type: str) -> List[UserIndicator]
Usage Examples
# Get indicator manager
manager = get_indicator_manager()
# Create new indicator
indicator = manager.create_indicator(
name="My SMA 50",
indicator_type="sma",
parameters={"period": 50},
description="50-period Simple Moving Average",
color="#ff0000"
)
# Load indicator
loaded = manager.load_indicator("sma_abc123")
# Update indicator
success = manager.update_indicator(
"sma_abc123",
name="Updated SMA",
parameters={"period": 30}
)
# Delete indicator
deleted = manager.delete_indicator("sma_abc123")
# List all indicators
all_indicators = manager.list_indicators()
# Get by type
overlay_indicators = manager.get_indicators_by_type("overlay")
subplot_indicators = manager.get_indicators_by_type("subplot")
Troubleshooting
Common Issues
-
Indicator not appearing in dropdown
- Check if registered in
INDICATOR_REGISTRY - Verify the indicator type matches the class name
- Check if registered in
-
Parameters not saving
- Ensure parameter fields are added to save callback
- Check parameter collection logic in
save_new_indicator
-
Chart not updating
- Verify the indicator layer implements
calculate_valuesandcreate_traces - Check if indicator is registered in the correct registry
- Verify the indicator layer implements
-
File permission errors
- Ensure
config/indicators/user_indicators/directory is writable - Check file permissions on existing JSON files
- Ensure
Debug Information
- Check browser console for JavaScript errors
- Look at application logs for Python exceptions
- Verify JSON file structure with a validator
- Test indicator calculations with sample data
Performance Considerations
- Indicators with large periods may take longer to calculate
- Consider data availability when setting parameter limits
- Subplot indicators require additional chart space
- Real-time updates may impact performance with many indicators
Best Practices
-
Naming Conventions
- Use descriptive names for indicators
- Include parameter values in names (e.g., "SMA 20")
- Use consistent naming patterns
-
Parameter Validation
- Set appropriate min/max values for parameters
- Provide helpful descriptions for parameters
- Use sensible default values
-
Error Handling
- Handle insufficient data gracefully
- Provide meaningful error messages
- Log errors for debugging
-
Performance
- Cache calculated values when possible
- Optimize calculation algorithms
- Limit the number of active indicators
-
User Experience
- Provide immediate visual feedback
- Use intuitive color schemes
- Group related indicators logically