Skip to content

Commit cd168db

Browse files
committed
Display / hide indicators
1 parent e5dded4 commit cd168db

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
lines changed

finplotWindow.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def createPlotWidgets(self):
5757
def drawCandles(self):
5858

5959
fplt.candlestick_ochl(self.data['Open Close High Low'.split()], ax=self.ax0)
60-
60+
6161
#self.hover_label = fplt.add_legend('', ax=self.ax0)
6262
#fplt.set_time_inspector(self.update_legend_text, ax=self.ax0, when='hover', data=data)
6363
#fplt.add_crosshair_info(self.update_crosshair_text, ax=self.ax0)
@@ -66,6 +66,22 @@ def drawCandles(self):
6666
#self.createControlPanel(self.ax0.ax_widget)
6767
pass
6868

69+
def drawExternalsIndicators(self):
70+
71+
#if self.IndRsiActivated:
72+
self.rsi_indicator = rsi.Rsi(self.data)
73+
self.rsi_indicator.draw(self.ax_rsi)
74+
75+
#if self.IndStochasticActivated:
76+
self.stochastic_indicator = stochastic.Stochastic(self.data)
77+
self.stochastic_indicator.draw(self.ax_stochastic)
78+
79+
#if self.IndStochasticRsiActivated:
80+
self.stochasticRsi_indicator = stochasticRsi.StochasticRsi(self.data)
81+
self.stochasticRsi_indicator.draw(self.ax_stochasticRsi)
82+
83+
pass
84+
6985
#########
7086
# Draw orders on charts (with arrows)
7187
#########
@@ -305,6 +321,9 @@ def refreshChart(self):
305321

306322
def setChartData(self, data):
307323
self.data = data
324+
325+
# Calculate indicators only one time when setting chart data
326+
self.drawExternalsIndicators()
308327
pass
309328

310329
def resetChart(self):
@@ -326,24 +345,9 @@ def updateChart(self):
326345
self.ichimoku_indicator = ichimoku.Ichimoku(self.data)
327346
self.ichimoku_indicator.draw(self.ax0)
328347

329-
if self.IndRsiActivated:
330-
self.rsi_indicator = rsi.Rsi(self.data)
331-
self.rsi_indicator.draw(self.ax_rsi)
332-
333-
if self.IndStochasticActivated:
334-
self.stochastic_indicator = stochastic.Stochastic(self.data)
335-
self.stochastic_indicator.draw(self.ax_stochastic)
336-
pass
337-
338-
if self.IndStochasticRsiActivated:
339-
self.stochasticRsi_indicator = stochasticRsi.StochasticRsi(self.data)
340-
self.stochasticRsi_indicator.draw(self.ax_stochasticRsi)
341-
pass
342-
343348
if self.IndVolumesActivated:
344349
fplt.volume_ocv(self.data['Open Close Volume'.split()], ax=self.ax0.overlay())
345350

346-
347351
# Finally draw candles
348352
self.drawCandles()
349353

@@ -355,28 +359,19 @@ def updateChart(self):
355359

356360
pass
357361

358-
362+
359363
def setIndicator(self, indicatorName, activated):
360364

361-
if (indicatorName == "Rsi"):
362-
self.IndRsiActivated = activated
363-
364-
if (indicatorName == "Stochastic"):
365-
self.IndStochasticActivated = activated
366-
367-
if (indicatorName == "StochasticRsi"):
368-
self.IndStochasticRsiActivated = activated
369-
370365
if (indicatorName == "Ichimoku"):
371366
self.IndIchimokuActivated = activated
372-
367+
373368
if (indicatorName == "Volumes"):
374369
self.IndVolumesActivated = activated
375370

376371
self.updateChart()
377372

378373
pass
379-
374+
380375
#############
381376
# Show finplot Window
382377
#############

userInterface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,24 +556,24 @@ def resetChart(self):
556556
self.fpltWindow.updateChart()
557557
pass
558558

559+
# indicators in external windows
559560
def addRsi(self):
560-
self.fpltWindow.setIndicator("Rsi", self.RsiPB.isChecked() )
561561
self.dock_rsi.show() if self.RsiPB.isChecked() else self.dock_rsi.hide()
562562
pass
563563

564564
def addStochastic(self):
565-
self.fpltWindow.setIndicator("Stochastic", self.StochasticPB.isChecked() )
566565
self.dock_stochastic.show() if self.StochasticPB.isChecked() else self.dock_stochastic.hide()
567566
pass
568567

569568
def addStochasticRsi(self):
570-
self.fpltWindow.setIndicator("StochasticRsi", self.StochasticRsiPB.isChecked() )
571569
self.dock_stochasticRsi.show() if self.StochasticRsiPB.isChecked() else self.dock_stochasticRsi.hide()
572570
pass
573571

572+
# On chart indicators
574573
def addIchimoku(self):
575574
self.fpltWindow.setIndicator("Ichimoku", self.IchimokuPB.isChecked() )
576575
pass
576+
577577
def volumes_toggle(self):
578578
self.fpltWindow.setIndicator("Volumes", self.volumesCB.isChecked())
579579
pass

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