mplfinance
mplfinance copied to clipboard
Document **vcdopcod** (Volume Color Depends on Price Change on Day) feature of mplfinance styles.
Describe the bug
Using style as charles or yahoo with candle and volume chart, some of their color don't match. This is not happening to starsandstripes styled chart.
To Reproduce
Please take a look at charles or yahoo styled chart in the example page. https://github.com/matplotlib/mplfinance/blob/master/examples/styles.ipynb
The second candle from the left is red in the chart but its volume bar is green. The fifth candle from the left is red but its volume bar is green.
This is happening to my project as well.
Cheers
@tech-a-go-go You are the first to point this out! It's nice to know that someone is paying close attention (and close enough to notice that it is only these two styles!).
This is not a bug, but is actually an undocumented feature (I really should document it) that you can see as the default chart behavior on yahoo.com or on schwab.com. For example, take a look at this chart on yahoo: notice 30-July, 13-Aug, and 14-Aug. On those days the volume is red while the candle is green. This is because the volume color depends on the price change on day. So, for these two styles that you noted ('charles' and 'yahoo')
- Candle color depends on whether today's close is higher (up) or lower (down) than today's open, but
- Volume color depends on whether today's close is higher (up) or lower (down) than yesterday's close.
In Mplfinance, this is controlled by the vcdopcod
parameter in the style data which you can see, for example, here and here.
This concept, of of distinguishing between intraday change (Open->Close) and "change on day" (Close->Close) is also the basis for "Four Color Candles" aka "Hollow Candles", a feature which is not yet implemented.
Hi, @DanielGoldfarb
Thank you for the reason ! I didn't know that rule. That's smart =)
@DanielGoldfarb Hello Daniel, just a clarification, can we or can't we use the 'vcdopcod' feature if we do not use Yahoo or Charles style? I am using my own custom style with 'Inherit' on from Candles to Volumes, but it would be nice to have this 'vcdopcod' with my custom style indeed. Thank you
vcdopcod
can be used with any custom style, however presently there is no vcdopcod
kwarg to mpf.make_mpf_style()
which means, if you want to use vcdopcod
, for the time being you have two choices:
-
add
vcdopcod
as a kwarg tompf.make_mpf_style()
. (This should be relatively easy if you want to submit a PR). -
create your own
.py
style file similar to those here: https://github.com/matplotlib/mplfinance/tree/master/src/mplfinance/_styledata, and in the file set'vcdopcod' : True,
, and place the file in the_styledata
directory of your mplinance install (or submit a PR to add your style permanently to mplfinance and make it available for others to use. This is also relatively easy to do).