19
19
import backtrader as bt
20
20
from pyqtgraph import mkColor , mkBrush
21
21
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
+
22
29
class FinplotWindow ():
23
30
24
31
def __init__ (self , dockArea , dockChart , interface ):
@@ -65,11 +72,11 @@ def createPlotWidgets(self, timeframe):
65
72
66
73
def drawCandles (self ):
67
74
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 )
69
76
70
77
#self.hover_label = fplt.add_legend('', ax=self.ax0)
71
78
#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 )
73
80
74
81
# Inside plot widget controls
75
82
#self.createControlPanel(self.ax0.ax_widget)
@@ -231,7 +238,8 @@ def update_legend_text(self, x, y, ax, data):
231
238
pass
232
239
233
240
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 )
235
243
return xtext , ytext
236
244
237
245
def activateDarkMode (self , activated ):
@@ -459,4 +467,3 @@ def hidePnL(self):
459
467
self .axPnL .hide ()
460
468
self .axPnL .ax_widget .hide ()
461
469
pass
462
-
0 commit comments