Skip to content

Commit

Permalink
Merge pull request #1 from zlpatel/kernc#356
Browse files Browse the repository at this point in the history
Merging kernc#356
  • Loading branch information
zlpatel authored Jun 12, 2021
2 parents 0a76e96 + bf03b63 commit 2cc6724
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backtesting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ def __eq__(self, other):
colors = colors and cycle(_as_list(colors)) or (
cycle([next(ohlc_colors)]) if is_overlay else colorgen())
legend_label = LegendStr(value.name)
indicator_max = value.df.max(axis='columns')
indicator_min = value.df.min(axis='columns')
source.add(indicator_max, f'indicator_{i}_range_max')
source.add(indicator_min, f'indicator_{i}_range_min')
for j, arr in enumerate(value, 1):
color = next(colors)
source_name = f'{legend_label}_{i}_{j}'
Expand Down Expand Up @@ -609,7 +613,11 @@ def __eq__(self, other):
source=source)
if plot_volume:
custom_js_args.update(volume_range=fig_volume.y_range)

indicator_ranges = {}
for idx, indicator in enumerate(indicator_figs):
indicator_range_key = f'indicator_{idx}_range'
indicator_ranges.update({indicator_range_key: indicator.y_range})
custom_js_args.update({'indicator_ranges': indicator_ranges})
fig_ohlc.x_range.js_on_change('end', CustomJS(args=custom_js_args,
code=_AUTOSCALE_JS_CALLBACK))

Expand Down
13 changes: 13 additions & 0 deletions backtesting/autoscale_cb.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,18 @@ window._bt_autoscale_timeout = setTimeout(function () {
max = Math.max.apply(null, source.data['Volume'].slice(i, j));
_bt_scale_range(volume_range, 0, max * 1.03, false);
}

if(indicator_ranges){
let keys = Object.keys(indicator_ranges);
for(var count=0;count<keys.length;count++){
if(keys[count]){
max = Math.max.apply(null, source.data[keys[count]+'_max'].slice(i, j));
min = Math.min.apply(null, source.data[keys[count]+'_min'].slice(i, j));
if(min && max){
_bt_scale_range(indicator_ranges[keys[count]], min, max, true);
}
}
}
}

}, 50);

0 comments on commit 2cc6724

Please sign in to comment.