eshan6704 commited on
Commit
cca6542
·
verified ·
1 Parent(s): 066999b

Delete chart_builder.py

Browse files
Files changed (1) hide show
  1. chart_builder.py +0 -68
chart_builder.py DELETED
@@ -1,68 +0,0 @@
1
- import plotly.graph_objects as go
2
- from plotly.subplots import make_subplots
3
-
4
- def build_chart(df, indicators):
5
- """
6
- df: OHLCV DataFrame
7
- indicators: dict returned from indicater.py
8
- Returns Plotly HTML with embedded JS to enable/disable indicators
9
- """
10
- fig = make_subplots(rows=6, cols=1,
11
- shared_xaxes=True,
12
- row_heights=[0.5,0.2,0.2,0.2,0.2,0.2],
13
- vertical_spacing=0.02,
14
- subplot_titles=["Price", "Volume", "MACD", "RSI", "SuperTrend", "ZigZag/Swing"])
15
-
16
- # ---------------- Price Candlestick ----------------
17
- fig.add_trace(go.Candlestick(
18
- x=df.index, open=df['Open'], high=df['High'],
19
- low=df['Low'], close=df['Close'],
20
- name='Price', row=1, col=1
21
- ))
22
-
23
- # Moving Averages on main chart
24
- for ma in ['MA10','MA50','MA200']:
25
- fig.add_trace(go.Scatter(
26
- x=df.index, y=indicators[ma],
27
- name=ma, visible='legendonly', row=1, col=1
28
- ))
29
-
30
- # Volume subplot
31
- fig.add_trace(go.Bar(x=df.index, y=df['Volume'], name='Volume', row=2, col=1))
32
-
33
- # MACD subplot
34
- fig.add_trace(go.Scatter(x=df.index, y=indicators['MACD']['macd'], name='MACD', visible='legendonly', row=3, col=1))
35
- fig.add_trace(go.Scatter(x=df.index, y=indicators['MACD']['signal'], name='MACD Signal', visible='legendonly', row=3, col=1))
36
- fig.add_trace(go.Bar(x=df.index, y=indicators['MACD']['hist'], name='MACD Hist', visible='legendonly', row=3, col=1))
37
-
38
- # RSI subplot
39
- fig.add_trace(go.Scatter(x=df.index, y=indicators['RSI'], name='RSI', visible='legendonly', row=4, col=1))
40
-
41
- # SuperTrend subplot
42
- fig.add_trace(go.Scatter(x=df.index, y=indicators['SUPERTREND'], name='SuperTrend', visible='legendonly', row=5, col=1))
43
-
44
- # ZigZag/Swing subplot
45
- fig.add_trace(go.Scatter(x=df.index, y=indicators['ZIGZAG'], name='ZigZag', visible='legendonly', row=6, col=1))
46
- fig.add_trace(go.Scatter(x=df.index, y=indicators['SWING'], name='Swing', visible='legendonly', row=6, col=1))
47
-
48
- fig.update_layout(
49
- height=1000,
50
- xaxis_rangeslider_visible=False,
51
- legend=dict(itemclick="toggleothers"),
52
- title="Stock Chart with Indicators"
53
- )
54
-
55
- html_chart = fig.to_html(full_html=False, include_plotlyjs=True)
56
-
57
- # Inject JS to enable/disable indicators dynamically
58
- script = """
59
- <script>
60
- document.querySelectorAll('.legendtoggle').forEach(item=>{
61
- item.addEventListener('click', e=>{
62
- console.log('Toggle indicator:', e);
63
- });
64
- });
65
- </script>
66
- """
67
-
68
- return html_chart + script