mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

Document **vcdopcod** (Volume Color Depends on Price Change on Day) feature of mplfinance styles.

Open tech-a-go-go opened this issue 4 years ago • 4 comments

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 avatar Aug 23 '20 08:08 tech-a-go-go

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

  1. Candle color depends on whether today's close is higher (up) or lower (down) than today's open, but
  2. 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.

DanielGoldfarb avatar Aug 23 '20 12:08 DanielGoldfarb

Hi, @DanielGoldfarb

Thank you for the reason ! I didn't know that rule. That's smart =)

tech-a-go-go avatar Aug 23 '20 16:08 tech-a-go-go

@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

manuelwithbmw avatar Sep 14 '20 09:09 manuelwithbmw

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 to mpf.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).

DanielGoldfarb avatar Sep 14 '20 15:09 DanielGoldfarb