Skip to content

Commit a88890a

Browse files
author
michael xu
committed
add open/close/high/low info on crosshair line
1 parent 22a6c5f commit a88890a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

finplotWindow.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
import backtrader as bt
2020
from pyqtgraph import mkColor, mkBrush
2121

22+
def chinese_price_colorfilter(item, datasrc, df):
23+
opencol = df.columns[1]
24+
closecol = df.columns[2]
25+
is_up = df[opencol] <= df[closecol] # open lower than close = goes up
26+
yield item.rowcolors('bear') + [df.loc[is_up, :]]
27+
yield item.rowcolors('bull') + [df.loc[~is_up, :]]
28+
2229
class FinplotWindow():
2330

2431
def __init__(self, dockArea, dockChart, interface):
@@ -65,11 +72,11 @@ def createPlotWidgets(self, timeframe):
6572

6673
def drawCandles(self):
6774

68-
fplt.candlestick_ochl(self.data['Open Close High Low'.split()], ax=self.ax0)
75+
fplt.candlestick_ochl(self.data['Open Close High Low'.split()], ax=self.ax0,colorfunc=chinese_price_colorfilter)
6976

7077
#self.hover_label = fplt.add_legend('', ax=self.ax0)
7178
#fplt.set_time_inspector(self.update_legend_text, ax=self.ax0, when='hover', data=data)
72-
#fplt.add_crosshair_info(self.update_crosshair_text, ax=self.ax0)
79+
fplt.add_crosshair_info(self.update_crosshair_text, ax=self.ax0)
7380

7481
# Inside plot widget controls
7582
#self.createControlPanel(self.ax0.ax_widget)
@@ -231,7 +238,8 @@ def update_legend_text(self, x, y, ax, data):
231238
pass
232239

233240
def update_crosshair_text(self,x, y, xtext, ytext):
234-
ytext = '%s (Close%+.2f)' % (ytext, (y - self.data.iloc[x].Close))
241+
ytext = '%s \n open: %.4f\n close: %.4f\n high: %.4f\n low: %.4f' \
242+
% (ytext, self.data.iloc[x].Open, self.data.iloc[x].Close, self.data.iloc[x].High, self.data.iloc[x].Low)
235243
return xtext, ytext
236244

237245
def activateDarkMode(self, activated):
@@ -459,4 +467,3 @@ def hidePnL(self):
459467
self.axPnL.hide()
460468
self.axPnL.ax_widget.hide()
461469
pass
462-

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