Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-scale Y-axis for indicators graph when zooming #356

Open
zlpatel opened this issue May 22, 2021 · 4 comments · May be fixed by #389
Open

Auto-scale Y-axis for indicators graph when zooming #356

zlpatel opened this issue May 22, 2021 · 4 comments · May be fixed by #389
Labels
enhancement New feature or request

Comments

@zlpatel
Copy link
Contributor

zlpatel commented May 22, 2021

Original Discussion Post: #355

There's something that I noticed which makes it difficult to view indicator graph on the chart if you're backtesting for longer period. Below is an example of an indicator view on the chart without zooming in. Notice the y axis scales.
Screenshot 2021-05-21 at 4 03 16 PM

Now, when I zoom in to focus on a specific period when ttm squeeze value stayed between -5 to +5, it still shows the full scale from -15 to+20. which makes it really hard to visualize the indicator chart. See below.
Screenshot 2021-05-21 at 4 09 25 PM

I know that re-scaling is allowed for the price chart/Volume. Is that something that can be implemented on the indicator charts as well?

@zlpatel
Copy link
Contributor Author

zlpatel commented May 22, 2021

I fiddled around with the code and made it work :)

Here's what I did:

I have added code

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')

right above

for j, arr in enumerate(value, 1):

then,

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})

right below these lines

if plot_volume:
custom_js_args.update(volume_range=fig_volume.y_range)

then,

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);
            }    
        }
    }
}

right below these lines

if (volume_range) {
max = Math.max.apply(null, source.data['Volume'].slice(i, j));
_bt_scale_range(volume_range, 0, max * 1.03, false);
}

Here's how it looks on the graph:

Without Zooming in:
Screenshot 2021-05-22 at 12 13 14 PM

When Zoomed in:
Screenshot 2021-05-22 at 12 13 36 PM

@kernc kernc added the enhancement New feature or request label May 23, 2021
@kernc kernc changed the title Allow Auto-scaling of Y axis values for Indicator(when overlay=False) when you zoom in or out the chart. Auto-scale Y-axis for indicators when zooming May 23, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue May 23, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue May 23, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue May 23, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue May 23, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue May 23, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue May 23, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 12, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021
@zlpatel zlpatel changed the title Auto-scale Y-axis for indicators when zooming Auto-scale Y-axis for indicators and Profit/Loss graph when zooming Jun 13, 2021
@zlpatel zlpatel changed the title Auto-scale Y-axis for indicators and Profit/Loss graph when zooming Auto-scale Y-axis for indicators and profit/loss graph when zooming Jun 13, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021
@zlpatel zlpatel changed the title Auto-scale Y-axis for indicators and profit/loss graph when zooming Auto-scale Y-axis for indicators graph when zooming Jun 13, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 13, 2021


Reverted: Auto-scale Y-axis for Profit/Loss chart when zooming kernc#356
@zlpatel
Copy link
Contributor Author

zlpatel commented Jun 13, 2021

@kernc can you review my fix for this?

zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 15, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 15, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 17, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 17, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 17, 2021
zlpatel added a commit to zlpatel/backtesting.py that referenced this issue Jun 17, 2021
@kernc kernc linked a pull request Jun 23, 2021 that will close this issue
@lkfrota
Copy link

lkfrota commented Dec 2, 2021

Thank you for the great work. That is something that I was looking for and made the job.
However, did you notice that it works only if the volume is plotted along (i.e. plot_volume=True)?
...or did I miss something (I'm not an experienced user).

@zlpatel
Copy link
Contributor Author

zlpatel commented Dec 13, 2021

Thank you for the great work. That is something that I was looking for and made the job. However, did you notice that it works only if the volume is plotted along (i.e. plot_volume=True)? ...or did I miss something (I'm not an experienced user).

Thanks for pointing it out. I will need to figure out the dependency on volume chart and separate it from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants