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

Add Histogram indicator plot style kernc#195 #384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zlpatel
Copy link
Contributor

@zlpatel zlpatel commented Jun 16, 2021

added an option histogram=True for I() function. it plots histogram using vbar function of bokeh js.

Fixes #195

@AGG2017
Copy link

AGG2017 commented Aug 13, 2021

Great idea to add histograms to the charts. I tested that with many combinations of indicators and it perfectly works. Couldn't find an easy way to use factor_cmap to make one indicator with two colors (let say green for + values and red for - values). To add color horizontal lines at fixed levels is much easier. Thanks for the proposal and will wait to see it in the next official updates.

@zlpatel
Copy link
Contributor Author

zlpatel commented Aug 13, 2021

@AGG2017 thanks for your feedback. you can look at #382 for sample. I have positive and negative values as separate arrays/series. and then I assign specific color to each series. That's how I show red for negative and green for positive values.

@AGG2017
Copy link

AGG2017 commented Aug 13, 2021

@zlpatel Thanks for the idea. It is not practical when using standard TA libraries but for some custom indicators is perfect. I had some success using linear_cmap with providing low/high values and their colors. It works good for two colors but is not practical for the squeeze momentum indicator where I will need 4 colors. Anyway, I will try to rewrite all plot parameters for the indicators to have only one dict parameter style, one for each element of the indicator in a list. Then I can select the style for each part of the indicator like for example MACD needs two lines and one histogram.

@zlpatel
Copy link
Contributor Author

zlpatel commented Aug 13, 2021

@zlpatel Thanks for the idea. It is not practical when using standard TA libraries but for some custom indicators is perfect. I had some success using linear_cmap with providing low/high values and their colors. It works good for two colors but is not practical for the squeeze momentum indicator where I will need 4 colors. Anyway, I will try to rewrite all plot parameters for the indicators to have only one dict parameter style, one for each element of the indicator in a list. Then I can select the style for each part of the indicator like for example MACD needs two lines and one histogram.

@AGG2017 I see what you're saying. I did think about that but couldn't find an easy way to allow multiple style plots into a single indicator. May be we can explore a little more. May be we need to have a new Indicator class which can allow grouping multiple I() in a single plot.

@AGG2017
Copy link

AGG2017 commented Aug 13, 2021

@zlpatel I want just to add one more parameter style to replace everything else when defined in order to be compatible with all the rest. Let say you have predefined style_macd={'names':['macd','sig','hist'], 'styles':['line','line','histogram'], 'colors':['blue','black','green(+):red(-)']} and then just use in indicator parameters only style=style_macd. Something like that. Each element of one complex indicator will have its own style parameter, predefined in advance for the most used one. skip style will be very useful to hide some elements of one indicator.
Sorry for this flooding of your thread but I'm very new to this backtesting library and I'm so excited with the tons of possibilities and your efforts to become even better.

@ghost
Copy link

ghost commented Nov 16, 2021

3 month passed but code is still not in official repo :(

@kernc kernc force-pushed the master branch 3 times, most recently from 7fd493d to e7981c7 Compare December 13, 2021 01:18
@quantrung9
Copy link

Hi @kernc,

It would be great if you could take a look at this one. I think this is the missing piece that everyone is looking for.

@kernc kernc force-pushed the master branch 9 times, most recently from 60eff81 to 109c352 Compare November 28, 2022 22:33
@ivaigult
Copy link
Contributor

ivaigult commented May 3, 2023

I appreciate that @kernc does not want to extend the API to allow charts customization (see this discussion).

and backtesting.py could never strive to replace TradingView

I tend to agree that it would be hard to extend the existing I interface to add all possible charting styles. This can be a nightmare from the maintenance and API perspective. However, this is what the customers want (including myself). So my question is:

Can we tweak the I interface somehow s.t. the users get the raw access to bokeh? For instance they can set some "unspecified" or "unchecked" arguments of I, and they are just get piped to bokeh as they are. Something like:

self.I(my_indicator, self.close, bokeh_fn="vbar", bokeh_args={"width": 42})

or something even more flexible, so plotting is completely decoupled from the indicators.

Thoughts?

@kernc kernc force-pushed the master branch 5 times, most recently from 428c361 to 0ce6cab Compare January 21, 2025 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Histogram indicator plot style
5 participants