matplotlib/mplfinance

When saving candle charts to file, the candles are red when should be green. why?

TraderMan999 opened this issue · 13 comments

in think or swim for example, this is the difference between the "CANDLE" style and the "CANDLE TREND" style.

What it appears is happening in MPL Finance using the yahoo style is if the close is below the open then the candle is RED, EVEN IF the close is above the previous days close.

This is very confusing to me and i want to have the candle be green if it closes higher than the previous days close.

Any suggestions?

Here's an example:

https://ibb.co/25hgDLD

Code:

mpf.plot(data, type='candle', style='yahoo', title=title + charttitle + ' ' + keyDateForImageTitle, marketcolor_overrides=mco, savefig=savedPlotFileName,addplot=apd)

Please provide the exact data and code used to generate the example plot, so that the questionable candle is 100% reproducible from the data and code.

As a general rule, for all traditional candlestick charts, the color of a candle depends entirely on whether the Close for that candle is higher than the Open of the same candle (green) or whether the Close is lower than the Open (red), with no dependence on previous candles.

Within mplfinance styles, there is a parameter 'vcdopcod' which stands for "volume color depends on previous close on day," which happens to be True for style yahoo, however this only affects the volume bar colors and not the candle colors.

Additionally, mplfinance now supports type='hollow', aka type='hollow_and_filled', which differs from type='candle' in that the color of the candle does depend on the change from the previous Close, while the body of the candle is filled or hollow based on whether the Close is down from the Open, or up from the Open.

@TraderMan999
As mentioned, traditional candlestick charts are colored based on the difference between the open and the close for each candle, so you have two alternatives: (1) use hollow and filled candles, or (2) enhance mplfinance to accept a kwarg that says to color each candle based the difference between the candle's close and the previous candle's close. If you want to do (2), and are unsure how to do it, then I can guide you through the process.

@TraderMan999
I finally took the time to read thinkorswim and, from what I can tell, the CANDLE TREND Chart is exactly what mplfinance calls type='hollow'.

I suggest you try using type='hollow' in your call to mpf.plot(). That should give you exactly what thinkorswim describes as a Candle Trend Chart.

Now by default the times on the x axis are not what I want. I’d rather they show the 930 est open etc. Is there a way to change those to be the ones I want?

I don't know what you are asking. What exactly are you seeing? What exactly do you want to see instead?

@TraderMan999
The image you tried to attach does not show.
Do not reply by email. It does not work!

Rather go to GitHub.com and add your comment and images here

@TraderMan999

Posting to GitHub by email does NOT work (they have bugs).

You need to go directly to the issue on the github website and post there.