Bar colors based on indicator value
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.
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).
Yes those bars, although it would be nice for candlesticks also. That sounds like a workable solution. Thanks, Daniel.
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
@geirak thanks for chiming in: it helps prioritize enhancements.
Here's what I am thinking:
- a kwarg,
usercolorsthat applies only totype='ohlc'ortype='candle' usercolorsis 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,usercolorsmay optionally be adictwith 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.
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 :-)
Should this issue be marked as closed since marketcolor_overrides kwargs seem to deliver this feature?
@siddiqaa Yes. Thanks.