import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class ChartService { constructor() { } getChartOptions(strategyName: any, fetchData: any): any[] { const strategyConfig: any = { 'RSI 14': { panels: [ { indicators: ['RSI 14'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } } ] }, 'Overbought/Oversold': { panels: [ { indicators: ['RSI 14'], showAnnotations: true, levels: [ { value: 70, color: '#FF0000', label: 'Overbought (70)' }, { value: 30, color: '#008000', label: 'Oversold (30)' } ], yaxisconfig: { min: 0, max: 100 } } ] }, 'RSI Swing Rejection': { panels: [ { indicators: ['RSI 14'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } } ] }, 'RSI Divergence': { panels: [ { indicators: ['RSI 14'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } } ] }, 'RSI 5/14 Crossover': { panels: [ { indicators: ['RSI 14', 'RSI 5'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } } ] }, 'RSI Trend 50 Confirmation': { panels: [ { indicators: ['RSI 14'], showAnnotations: true, levels: [ { value: 70, color: '#FF0000', label: 'Overbought (70)' }, { value: 50, color: '#775DD0', label: 'RSI (50)' }, { value: 30, color: '#008000', label: 'Oversold (30)' } ], yaxisconfig: { min: 0, max: 100 } } ] }, 'Mean Reversion': { panels: [ { indicators: ['RSI 14'], showAnnotations: true, levels: [ { value: 80, color: '#FF0000', label: 'Overbought (80)' }, { value: 20, color: '#008000', label: 'Oversold (20)' } ], yaxisconfig: { min: 0, max: 100 } } ] }, 'RSI_Bollinger Band': { panels: [ { indicators: ['RSI 14'], showAnnotations: true, levels: [ { value: 70, color: '#FF0000', label: 'Overbought (70)' }, { value: 30, color: '#008000', label: 'Oversold (30)' } ], yaxisconfig: { min: 0, max: 100 } }, { indicators: ['Close', 'UpperBB', 'LowerBB'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'RSI_MA': { panels: [ { indicators: ['RSI 14'], showAnnotations: true, levels: [ { value: 70, color: '#FF0000', label: 'Overbought (70)' }, { value: 30, color: '#008000', label: 'Oversold (30)' } ], yaxisconfig: { min: 0, max: 100 } }, { indicators: ['Close', 'MA_20'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'MACD': { panels: [ { indicators: ['MACDLine'], showAnnotations: false, levels: [], yaxisconfig: {} } ] }, 'MACD Line Crossover': { panels: [ { indicators: ['MACDLine', 'MACDSignalLine', 'MACDHistogram'], showAnnotations: false, levels: [], yaxisconfig: {} } ] }, 'MACD Zero-Line Crossover': { panels: [ { indicators: ['MACDLine'], showAnnotations: true, levels: [{ value: 0, color: '#FF0000', label: 'MACD ZeroLine' },], yaxisconfig: {} } ] }, 'MACD Momentum': { panels: [ { indicators: ['MACDLine', 'MACDSignalLine', 'MACDHistogram'], showAnnotations: false, levels: [{ value: 0, color: '#FF0000', label: 'MACD ZeroLine' },], yaxisconfig: {} } ] }, 'ATR': { panels: [ { indicators: ['ATRValue'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'ATR Breakout': { panels: [ { indicators: ['ATRValue'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling }, { indicators: ['Close'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling for Close Price } ] }, 'ATR Expansion': { panels: [ { indicators: ['ATRValue'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'ATR Squeeze': { panels: [ { indicators: ['ATRValue'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'ATR Trend Reversal': { panels: [ { indicators: ['ATRValue'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'EMA 20': { panels: [ { indicators: ['EMA 20'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'EMA 50': { panels: [ { indicators: ['EMA 50'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'EMA Crossover': { panels: [ { indicators: ['EMA 20', 'EMA 50'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'EMA Price Crossover': { panels: [ { indicators: ['EMA 20', 'Close'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'Triple EMA': { panels: [ { indicators: ['EMA 5', 'EMA 20', 'EMA 50'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'ADX': { panels: [ { indicators: ['ADX_Indicator'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } } ] }, 'ADX + DI Crossover': { panels: [ { indicators: ['ADX_Indicator', 'PLUS_DI', 'MINUS_DI'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } } ] }, 'ADX Divergence': { panels: [ { indicators: ['ADX_Indicator'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } }, { indicators: ['Close'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scale for price } ] }, 'ADX Slope': { panels: [ { indicators: ['ADX_Indicator'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } } ] }, 'ADX Breakout': { panels: [ { indicators: ['ADX_Indicator'], showAnnotations: false, levels: [], yaxisconfig: { min: 0, max: 100 } }, { indicators: ['Close'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scale for price } ] }, 'Fibonacci Retracement Bounce': { panels: [ { indicators: ['Candlestick'], showAnnotations: true, levels: [ { value: 0.382, color: '#00008B', label: '38.2%' }, { value: 0.5, color: '#FF0000', label: '50%' }, { value: 0.618, color: '#FF5722', label: '61.8%' } ], yaxisconfig: {} // auto-scaling } ] }, 'Fibonacci Breakout': { panels: [ { indicators: ['Candlestick'], showAnnotations: true, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'Fibonacci Confluence': { panels: [ { indicators: ['Close', 'EMA9'], showAnnotations: true, levels: [], // dynamically filled yaxisconfig: {} // auto-scaling } ] }, 'Golden Pocket Reversal': { panels: [ { indicators: ['Candlestick'], showAnnotations: true, levels: [ { value: fetchData.FIB_61_8, color: '#FF0000', label: '61.8%' }, { value: fetchData.FIB_65, color: '#FFC107', label: '65%' } ], yaxisconfig: {} // auto-scaling } ] }, 'BB Squeeze': { panels: [ { indicators: ['Close', 'UpperBB', 'LowerBB'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'BB Breakout': { panels: [ { indicators: ['Close', 'UpperBB', 'LowerBB'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, 'BB Reversal': { panels: [ { indicators: ['Close', 'UpperBB', 'LowerBB'], showAnnotations: false, levels: [], yaxisconfig: {} // auto-scaling } ] }, }; const config = strategyConfig[strategyName]; if (strategyName === 'Fibonacci Breakout') { config.panels[0].levels = [ { value: fetchData.FIB_61_8, color: '#FF5722', label: '61.8% Breakout' } ]; } // For Fibonacci Retracement Bounce, convert levels to price-based annotations if (strategyName === 'Fibonacci Retracement Bounce') { config.panels[0].levels = [ { value: fetchData.FIB_38_2, color: '#00008B', label: '38.2%' }, { value: fetchData.FIB_50, color: '#FF0000', label: '50%' }, { value: fetchData.FIB_61_8, color: '#FF5722', label: '61.8%' } ]; } if (strategyName === 'Fibonacci Confluence') { config.panels[0].levels = [ { value: fetchData.FIB_61_8, color: '#FF5722', label: '61.8% Confluence' } ]; } const chartOptionsArray = config.panels.map((panel: any) => { const referenceData = fetchData[panel.indicators[0]]; const categories = Object.keys(referenceData); const series = panel.indicators.map((indicator: string) => { const indicatorData = fetchData[indicator]; if (indicator === 'Candlestick') { return { name: 'Candlestick', type: 'candlestick', data: indicatorData // already in [{x, y: [o,h,l,c]}] format }; } return { name: indicator, type: indicator === 'MACDHistogram' ? 'bar' : 'line', data: indicatorData ? Object.entries(indicatorData).map(([x, y]) => ({ x, y })) : [] }; }); const annotations = panel.showAnnotations ? { yaxis: panel.levels.map((level: any) => ({ y: level.value, borderColor: level.color, label: { borderColor: level.color, style: { color: '#fff', background: level.color }, text: level.label } })) } : {}; return { series: series, chart: { type: 'line', height: 500, width: 1300 }, xaxis: { categories: categories }, yaxis: panel.yaxisconfig || {}, stroke: { curve: 'smooth', width: 2 }, tooltip: { theme: 'dark' }, annotations: annotations }; }); return chartOptionsArray; } }