Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Auto-scale Y-axis for indicators when zooming #356
  • Loading branch information
zlpatel authored May 23, 2021
commit 0581c550e0f654fd683f6fce8fa4db2b7db859cf
12 changes: 12 additions & 0 deletions backtesting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ 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_{j}_range_max')
source.add(indicator_min,f'indicator_{j}_range_min')

for j, arr in enumerate(value, 1):
color = next(colors)
source_name = f'{legend_label}_{i}_{j}'
Expand Down Expand Up @@ -609,6 +615,12 @@ 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