Skip to content

Commit 2cc6724

Browse files
authored
Merge pull request #1 from zlpatel/kernc#356
Merging kernc#356
2 parents 0a76e96 + bf03b63 commit 2cc6724

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

backtesting/_plotting.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ def __eq__(self, other):
523523
colors = colors and cycle(_as_list(colors)) or (
524524
cycle([next(ohlc_colors)]) if is_overlay else colorgen())
525525
legend_label = LegendStr(value.name)
526+
indicator_max = value.df.max(axis='columns')
527+
indicator_min = value.df.min(axis='columns')
528+
source.add(indicator_max, f'indicator_{i}_range_max')
529+
source.add(indicator_min, f'indicator_{i}_range_min')
526530
for j, arr in enumerate(value, 1):
527531
color = next(colors)
528532
source_name = f'{legend_label}_{i}_{j}'
@@ -609,7 +613,11 @@ def __eq__(self, other):
609613
source=source)
610614
if plot_volume:
611615
custom_js_args.update(volume_range=fig_volume.y_range)
612-
616+
indicator_ranges = {}
617+
for idx, indicator in enumerate(indicator_figs):
618+
indicator_range_key = f'indicator_{idx}_range'
619+
indicator_ranges.update({indicator_range_key: indicator.y_range})
620+
custom_js_args.update({'indicator_ranges': indicator_ranges})
613621
fig_ohlc.x_range.js_on_change('end', CustomJS(args=custom_js_args,
614622
code=_AUTOSCALE_JS_CALLBACK))
615623

backtesting/autoscale_cb.js

+13
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,18 @@ window._bt_autoscale_timeout = setTimeout(function () {
3131
max = Math.max.apply(null, source.data['Volume'].slice(i, j));
3232
_bt_scale_range(volume_range, 0, max * 1.03, false);
3333
}
34+
35+
if(indicator_ranges){
36+
let keys = Object.keys(indicator_ranges);
37+
for(var count=0;count<keys.length;count++){
38+
if(keys[count]){
39+
max = Math.max.apply(null, source.data[keys[count]+'_max'].slice(i, j));
40+
min = Math.min.apply(null, source.data[keys[count]+'_min'].slice(i, j));
41+
if(min && max){
42+
_bt_scale_range(indicator_ranges[keys[count]], min, max, true);
43+
}
44+
}
45+
}
46+
}
3447

3548
}, 50);

0 commit comments

Comments
 (0)