6
6
import numpy as np
7
7
import pandas as pd
8
8
9
+ from bokeh .colors .named import (
10
+ lime as BULL_COLOR ,
11
+ tomato as BEAR_COLOR
12
+ )
9
13
from bokeh .plotting import figure as _figure
10
14
from bokeh .models import (
11
15
CustomJS ,
@@ -59,6 +63,12 @@ def colorgen():
59
63
yield from cycle (Category10 [10 ])
60
64
61
65
66
+ def lightness (color , lightness = .94 ):
67
+ color = color .to_hsl ()
68
+ color .l = lightness
69
+ return color .to_rgb ()
70
+
71
+
62
72
def plot (* , results , df , indicators , filename = '' , plot_width = 1200 ,
63
73
plot_equity = True , plot_pl = True ,
64
74
plot_volume = True , plot_drawdown = False ,
@@ -73,8 +83,7 @@ def plot(*, results, df, indicators, filename='', plot_width=1200,
73
83
# TestPlot.test_file_size() test was failing).
74
84
_bokeh_reset (filename )
75
85
76
- COLORS = ['tomato' , 'lime' ]
77
- COLORS_LIGHT = ['#ffe3e3' , '#e3ffe3' ]
86
+ COLORS = [BEAR_COLOR , BULL_COLOR ]
78
87
79
88
orig_trade_data = trade_data = results ._trade_data .copy (False )
80
89
@@ -134,6 +143,9 @@ def plot(*, results, df, indicators, filename='', plot_width=1200,
134
143
135
144
inc_cmap = factor_cmap ('inc' , COLORS , ['0' , '1' ])
136
145
cmap = factor_cmap ('returns_pos' , COLORS , ['0' , '1' ])
146
+ colors_darker = [lightness (BEAR_COLOR , .35 ),
147
+ lightness (BULL_COLOR , .35 )]
148
+ trades_cmap = factor_cmap ('returns_pos' , colors_darker , ['0' , '1' ])
137
149
138
150
if is_datetime_index and omit_missing :
139
151
fig_ohlc .xaxis .formatter = FuncTickFormatter (
@@ -368,8 +380,10 @@ def _plot_superimposed_ohlc():
368
380
df2 .index .name = None
369
381
source2 = ColumnDataSource (df2 )
370
382
fig_ohlc .segment ('index' , 'High' , 'index' , 'Low' , source = source2 , color = '#bbbbbb' )
383
+ colors_lighter = [lightness (BEAR_COLOR , .92 ),
384
+ lightness (BULL_COLOR , .92 )]
371
385
fig_ohlc .vbar ('index' , width2 , 'Open' , 'Close' , source = source2 , line_color = None ,
372
- fill_color = factor_cmap ('inc' , COLORS_LIGHT , ['0' , '1' ]))
386
+ fill_color = factor_cmap ('inc' , colors_lighter , ['0' , '1' ]))
373
387
374
388
def _plot_ohlc ():
375
389
"""Main OHLC bars"""
@@ -378,16 +392,16 @@ def _plot_ohlc():
378
392
line_color = "black" , fill_color = inc_cmap )
379
393
return r
380
394
381
- def _plot_ohlc_orders ():
382
- """Order entry / exit markers on OHLC plot"""
395
+ def _plot_ohlc_trades ():
396
+ """Trade entry / exit markers on OHLC plot"""
383
397
exit_price = trade_data ['Exit Price' ].dropna ()
384
398
entry_price = trade_data ['Entry Price' ].dropna ().iloc [:exit_price .size ] # entry can be one more at the end # noqa: E501
385
399
trade_source .add (np .column_stack ((entry_price .index , exit_price .index )).tolist (),
386
400
'position_lines_xs' )
387
401
trade_source .add (np .column_stack ((entry_price , exit_price )).tolist (),
388
402
'position_lines_ys' )
389
403
fig_ohlc .multi_line (xs = 'position_lines_xs' , ys = 'position_lines_ys' ,
390
- source = trade_source , line_color = cmap ,
404
+ source = trade_source , line_color = trades_cmap ,
391
405
legend = 'Trades' ,
392
406
line_width = 8 , line_alpha = 1 , line_dash = 'dotted' )
393
407
@@ -501,7 +515,7 @@ def __eq__(self, other):
501
515
_plot_superimposed_ohlc ()
502
516
503
517
ohlc_bars = _plot_ohlc ()
504
- _plot_ohlc_orders ()
518
+ _plot_ohlc_trades ()
505
519
_plot_indicators ()
506
520
507
521
set_tooltips (fig_ohlc , ohlc_tooltips , vline = True , renderers = [ohlc_bars ])
0 commit comments