diff --git a/backtesting/_plotting.py b/backtesting/_plotting.py index bec6757a..424dd18a 100644 --- a/backtesting/_plotting.py +++ b/backtesting/_plotting.py @@ -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}' @@ -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)) diff --git a/backtesting/autoscale_cb.js b/backtesting/autoscale_cb.js index da888ecf..63135615 100644 --- a/backtesting/autoscale_cb.js +++ b/backtesting/autoscale_cb.js @@ -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