File size: 1,361 Bytes
e42e5e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import ollama
from lightweight_charts import Chart

class IndicatorGenerator:
    def __init__(self):
        self.client = ollama.Client()
        self.code_model = "codellama:latest"
        self.indicators = [
            'rsi', 'macd', 'bollinger_bands', 'moving_averages',
            'stochastic', 'atr', 'volume_profile'
        ]
    
    def generate_all_indicators(self, historical_data):
        indicator_charts = []
        for indicator in self.indicators:
            # Generate code for indicator using CodeLlama
            code_prompt = f"Generate Lightweight Charts code for {indicator} indicator with proper styling and configuration"
            code_response = self.client.generate(
                model=self.code_model,
                prompt=code_prompt
            )
            
            # Create chart using generated code
            chart = Chart()
            chart.set(code_response)  # Applies the generated configuration
            chart.add_data(historical_data)
            
            indicator_charts.append(chart)
        
        return indicator_charts

    def _create_indicator_chart(self, data, indicator_type):
        chart = Chart()
        # Specific indicator configurations using Lightweight Charts
        chart.add_indicator(indicator_type, data)
        return chart