Skip to content

Bar colors based on indicator value #205

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

Closed
hrpomrx opened this issue Jul 3, 2020 · 8 comments
Closed

Bar colors based on indicator value #205

hrpomrx opened this issue Jul 3, 2020 · 8 comments
Labels
enhancement New feature or request question Further information is requested released code merged into repo AND released to Pypi

Comments

@hrpomrx
Copy link

hrpomrx commented Jul 3, 2020

Is there a way to color bars based on TA indicator values (obtained using TA-lib or similar) or based on aggregate values of multiple indicators, e.g. 3 different ohlc bar colors representing “long”, “short” and “no trade”? Thank you for any insight.

@hrpomrx hrpomrx added the question Further information is requested label Jul 3, 2020
@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Jul 5, 2020

When you say "ohlc bar" colors, I assume you mean ohlc bars like this: https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_4_1.png

Presently there is no way to color them other than upcolor/downcolor, however possibly, as an relatively easy enhancement, we could allow the caller to pass in a list of colors, where the list is the same length as the data, and each ohlc bar would be colored according the color at that corresponding point in the list. It would then be up to the caller to pass in the appropriate color for each ohlc data point (whether the total number of different colors is two, or three, or more).

@hrpomrx
Copy link
Author

hrpomrx commented Jul 5, 2020

Yes those bars, although it would be nice for candlesticks also. That sounds like a workable solution. Thanks, Daniel.

@geirak
Copy link

geirak commented Feb 23, 2021

as an relatively easy enhancement, we could allow the caller to pass in a list of colors, where the list is the same length as the data, and each ohlc bar would be colored according the color at that corresponding point in the list.

Hi Daniel
thank you for the awesome functionality and obviously the amount of work you are putting into this.

I have a use case which would be solved by your proposed enhancement as well.

Best regards

@DanielGoldfarb
Copy link
Collaborator

@geirak
thanks for chiming in: it helps prioritize enhancements.

@DanielGoldfarb
Copy link
Collaborator

Here's what I am thinking:

  • a kwarg, usercolors that applies only to type='ohlc' or type='candle'
  • usercolors is an array or list of the same length as the ohlc data
  • every entry in the list must be either a valid color, or None
    • if a valid color, then the normal candle/ohlc-bar color will be replaced with that user color.
    • if None, then the candle/ohlc-bar will maintain its normal up/down coloring according to the style chosen.

I am also considering the following, if there is need for it:

  • for type='candle' only, usercolors may optionally be a dict with one or more of the following keys:
    • 'candle', 'edge', 'wick'
  • the value for each key is an array or list, with the same specifications as described above (same length as data, and each entry is eitther a valid color or None).
  • This will allow you, for example, to use a signal color for the candle body, while keeping the wicks and/or edges of the candle the normal up/down colors, or while making the wicks and edges all one color.
    • As an example, it may be useful to keep all the wicks and edges black, and coloring only the candle body, effectively outlining the candle.
    • Some styles do this normally, outlining a candle color that otherwise would blend in with the background of the plot (See mplfinance style reference).
  • Please let me know if there is a desire to color wicks and edges separately from candle bodies.

@geirak
Copy link

geirak commented Feb 24, 2021

Your first proposal would solve my requirement to color the candles according to custom logic (showing momentum/lack of momentum according to a given rule set).

Optionally using a dict instead of an array/list for type='candle' would open up a range of new possibilities, which I see myself utilizing. It is an elegant solution, which requires additional user code only if necessary, but gives flexibility when needed.

If the dict implementation involves a lot more work for you and would significantly impact prioritization, then your first idea sounds more tempting :-)

@siddiqaa
Copy link

siddiqaa commented Sep 10, 2022

Should this issue be marked as closed since marketcolor_overrides kwargs seem to deliver this feature?

@DanielGoldfarb
Copy link
Collaborator

@siddiqaa
Yes. Thanks.

@DanielGoldfarb DanielGoldfarb added the released code merged into repo AND released to Pypi label Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested released code merged into repo AND released to Pypi
Projects
None yet
Development

No branches or pull requests

4 participants