Skip to content

Commit ed48584

Browse files
committed
Rename drawing functions for indicators enable / disable
1 parent 5ff87aa commit ed48584

File tree

2 files changed

+62
-41
lines changed

2 files changed

+62
-41
lines changed

finplotWindow.py

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,31 @@ def __init__(self, dockArea, dockChart):
1515
self.dockArea = dockArea
1616
self.dockChart = dockChart
1717

18+
self.IndIchimokuActivated = False
19+
self.IndRSIActivated = False
20+
self.IndStochasticActivated = False
21+
self.IndMAActivated = False
22+
23+
self.IndVolumesActivated = False
24+
1825
pass
1926

2027
#########
21-
# Draw chart
28+
# Prepare the plot widgets
2229
#########
23-
def drawFinPlots(self, data):
30+
def createPlotWidgets(self):
2431

25-
# Rest previous draws
26-
if hasattr(self, 'axo'):
27-
self.ax0.reset()
28-
if hasattr(self, 'ax1'):
29-
self.ax1.reset()
3032

31-
self.data = data
3233

3334
# fin plot
3435
self.ax0, self.ax1, self.ax2, self.ax3 = fplt.create_plot_widget(master=self.dockArea, rows=4, init_zoom_periods=100)
3536
self.dockArea.axs = [self.ax0, self.ax1, self.ax2, self.ax3]
3637
self.dockChart.addWidget(self.ax0.ax_widget, 1, 0, 1, 1)
38+
pass
3739

38-
fplt.candlestick_ochl(data['Open Close High Low'.split()], ax=self.ax0)
39-
#fplt.volume_ocv(data['Open Close Volume'.split()], ax=self.ax0.overlay())
40+
def drawCandles(self):
41+
42+
fplt.candlestick_ochl(self.data['Open Close High Low'.split()], ax=self.ax0)
4043

4144
#self.hover_label = fplt.add_legend('', ax=self.ax0)
4245
#fplt.set_time_inspector(self.update_legend_text, ax=self.ax0, when='hover', data=data)
@@ -251,38 +254,58 @@ def activateDarkMode(self, activated):
251254
#############
252255
# Indicators
253256
#############
254-
def setIndicator(self, indicatorName, activated):
255257

256-
if (indicatorName == "Ichimoku"):
258+
def resetPlots(self):
259+
# Entirely reset graph
260+
if (hasattr(self,"ax0")):
261+
self.ax0.reset()
262+
if (hasattr(self,"ax1")):
263+
self.ax1.reset()
264+
if (hasattr(self,"ax2")):
265+
self.ax2.reset()
266+
if (hasattr(self,"ax3")):
267+
self.ax3.reset()
257268

258-
if activated:
269+
pass
270+
271+
def setChartData(self, data):
272+
self.data = data
273+
pass
274+
275+
def updateChart(self):
276+
277+
# Entirely reset graph
278+
self.resetPlots()
279+
280+
if (hasattr(self,"data")):
281+
282+
# Start plotting indicators
283+
if self.IndIchimokuActivated:
259284
self.ichimoku_indicator = ichimoku.Ichimoku(self.data)
260285
self.ichimoku_indicator.draw(self.ax0)
261-
else:
262286

263-
for item in list(self.ax0.items):
264-
self.ax0.removeItem(item)
287+
if self.IndVolumesActivated:
288+
fplt.volume_ocv(self.data['Open Close Volume'.split()], ax=self.ax0.overlay())
289+
290+
# Finally draw candles
291+
self.drawCandles()
265292

266-
self.drawFinPlots(self.data)
293+
# Refresh view : auto zoom
294+
fplt.refresh()
267295

268-
# Refresh view
269-
self.ax0.vb.refresh_all_y_zoom()
270296
pass
271297

272-
def activate_volumes(self, activated):
273-
274-
if activated:
275-
fplt.volume_ocv(self.data['Open Close Volume'.split()], ax=self.ax0.overlay())
276-
else:
277-
#self.ax0.vb.reset()
278-
for item in list(self.ax0.items):
279-
self.ax0.removeItem(item)
280298

281-
self.drawFinPlots(self.data)
282-
#self.ax0.overlay().reset()
299+
def setIndicator(self, indicatorName, activated):
300+
301+
if (indicatorName == "Ichimoku"):
302+
self.IndIchimokuActivated = activated
303+
304+
if (indicatorName == "Volumes"):
305+
self.IndVolumesActivated = activated
306+
307+
self.updateChart()
283308

284-
# Refresh view
285-
self.ax0.vb.refresh_all_y_zoom()
286309
pass
287310

288311
#############

userInterface.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def createUIs(self):
110110

111111
# Create finplot Window
112112
self.createFinplotWindow()
113+
self.createControlPanel()
113114

114115
pass
115116

@@ -361,6 +362,7 @@ def fillSummaryUI(self, brokerCash, brokerValue, tradeAnalysis):
361362
def createFinplotWindow(self):
362363

363364
self.fpltWindow = finplotWindow.FinplotWindow(self.dockArea, self.dock_chart)
365+
self.fpltWindow.createPlotWidgets()
364366

365367
pass
366368

@@ -385,19 +387,16 @@ def getProgressBar(self):
385387
# Draw chart
386388
#########
387389
def drawChart(self, data):
388-
self.fpltWindow.drawFinPlots(data)
389-
self.createControlPanel()
390-
390+
self.fpltWindow.setChartData(data)
391+
self.fpltWindow.updateChart()
391392
pass
392393

393394
#########
394395
# Draw orders on chart
395396
#########
396397
def setOrders(self, orders):
397-
398398
#self.fillOrdersUI(self.myOrders)
399399
self.fpltWindow.drawOrders(orders)
400-
401400
pass
402401

403402

@@ -466,16 +465,15 @@ def dark_mode_toggle(self):
466465
self.fpltWindow.activateDarkMode(self.darkmodeCB.isChecked())
467466
pass
468467

469-
def volumes_toggle(self):
470-
self.fpltWindow.activate_volumes(self.volumesCB.isChecked())
471-
pass
472-
473468

474469
##########
475470
# INDICATORS
476471
##########
477472
def addIchimoku(self):
478-
self.fpltWindow.setIndicator( "Ichimoku", self.IchimokuPB.isChecked() )
473+
self.fpltWindow.setIndicator("Ichimoku", self.IchimokuPB.isChecked() )
474+
pass
475+
def volumes_toggle(self):
476+
self.fpltWindow.setIndicator("Volumes", self.volumesCB.isChecked())
479477
pass
480478

481479
#########

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy