matplotlib / mplfinance

Financial Markets Data Visualization using Matplotlib
https://pypi.org/project/mplfinance/
Other
3.61k stars 624 forks source link

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

Open TraderMan999 opened 1 year ago

TraderMan999 commented 1 year ago

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)

DanielGoldfarb commented 1 year ago

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.

DanielGoldfarb commented 1 year ago

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 commented 1 year ago

Yes that’s the issue. I want the candle color To be relative to the close of the prior candle. Not relative to its own open price

Get Outlook for iOShttps://aka.ms/o0ukef


From: Daniel Goldfarb @.> Sent: Tuesday, July 4, 2023 6:50:09 AM To: matplotlib/mplfinance @.> Cc: TraderMan999 @.>; Author @.> Subject: Re: [matplotlib/mplfinance] When saving candle charts to file, the candles are red when should be green. why? (Issue #639)

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 yahoohttps://github.com/matplotlib/mplfinance/blob/master/src/mplfinance/_styledata/yahoo.py, 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.

— Reply to this email directly, view it on GitHubhttps://github.com/matplotlib/mplfinance/issues/639#issuecomment-1620100703, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZCNE6KBAT24NVOKE6GVZKTXOP7PDANCNFSM6AAAAAAZ3YOQTU. You are receiving this because you authored the thread.Message ID: @.***>

DanielGoldfarb commented 1 year ago

@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 commented 1 year ago

Thank you. Yes #2 is my preference. I understand there are multiple ways people consider “normal” and for the charts I produce the green and red is more normal to be based in the precious candle

Is that value available already in the api? How should I start? I’m new to extending this api

Much appreciated!

Get Outlook for iOShttps://aka.ms/o0ukef


From: Daniel Goldfarb @.> Sent: Sunday, July 9, 2023 5:48:23 PM To: matplotlib/mplfinance @.> Cc: TraderMan999 @.>; Mention @.> Subject: Re: [matplotlib/mplfinance] When saving candle charts to file, the candles are red when should be green. why? (Issue #639)

@TraderMan999https://github.com/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.

— Reply to this email directly, view it on GitHubhttps://github.com/matplotlib/mplfinance/issues/639#issuecomment-1627851261, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZCNE6OHSTBMIFVCLT3VKB3XPMYLPANCNFSM6AAAAAAZ3YOQTU. You are receiving this because you were mentioned.Message ID: @.***>

DanielGoldfarb commented 1 year ago

@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.

TraderMan999 commented 1 year ago

Ok I will try that when I get home. Would be awesome if something as simple does it!

Get Outlook for iOShttps://aka.ms/o0ukef


From: Daniel Goldfarb @.> Sent: Wednesday, July 12, 2023 11:32:56 AM To: matplotlib/mplfinance @.> Cc: TraderMan999 @.>; Mention @.> Subject: Re: [matplotlib/mplfinance] When saving candle charts to file, the candles are red when should be green. why? (Issue #639)

@TraderMan999https://github.com/TraderMan999 I finally took the time to read thinkorswimhttps://tlc.thinkorswim.com/center and, from what I can tell, the CANDLE TREND Charthttps://tlc.thinkorswim.com/center/howToTos/thinkManual/charts/Chart-Modes/Chart-Types/candletrend 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 thinkorswimhttps://tlc.thinkorswim.com/center describes as a Candle Trend Chart.

— Reply to this email directly, view it on GitHubhttps://github.com/matplotlib/mplfinance/issues/639#issuecomment-1632859910, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZCNE6O4BPCXHDCII3ZWPEDXP3GTRANCNFSM6AAAAAAZ3YOQTU. You are receiving this because you were mentioned.Message ID: @.***>

TraderMan999 commented 1 year ago

I forgot to respond but that did what I needed.

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?

Get Outlook for iOShttps://aka.ms/o0ukef


From: Steve Conlon @.> Sent: Wednesday, July 12, 2023 3:44:12 PM To: matplotlib/mplfinance @.>; matplotlib/mplfinance @.> Cc: Mention @.> Subject: Re: [matplotlib/mplfinance] When saving candle charts to file, the candles are red when should be green. why? (Issue #639)

Ok I will try that when I get home. Would be awesome if something as simple does it!

Get Outlook for iOShttps://aka.ms/o0ukef


From: Daniel Goldfarb @.> Sent: Wednesday, July 12, 2023 11:32:56 AM To: matplotlib/mplfinance @.> Cc: TraderMan999 @.>; Mention @.> Subject: Re: [matplotlib/mplfinance] When saving candle charts to file, the candles are red when should be green. why? (Issue #639)

@TraderMan999https://github.com/TraderMan999 I finally took the time to read thinkorswimhttps://tlc.thinkorswim.com/center and, from what I can tell, the CANDLE TREND Charthttps://tlc.thinkorswim.com/center/howToTos/thinkManual/charts/Chart-Modes/Chart-Types/candletrend 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 thinkorswimhttps://tlc.thinkorswim.com/center describes as a Candle Trend Chart.

— Reply to this email directly, view it on GitHubhttps://github.com/matplotlib/mplfinance/issues/639#issuecomment-1632859910, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZCNE6O4BPCXHDCII3ZWPEDXP3GTRANCNFSM6AAAAAAZ3YOQTU. You are receiving this because you were mentioned.Message ID: @.***>

DanielGoldfarb commented 1 year ago

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 commented 1 year ago

For example if mi wanted to set it up for different charts to show midnight, 930am est etc bs the random times circled below:

[Image]

Get Outlook for iOShttps://aka.ms/o0ukef


From: Daniel Goldfarb @.> Sent: Sunday, August 6, 2023 6:11:55 PM To: matplotlib/mplfinance @.> Cc: TraderMan999 @.>; Mention @.> Subject: Re: [matplotlib/mplfinance] When saving candle charts to file, the candles are red when should be green. why? (Issue #639)

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?

— Reply to this email directly, view it on GitHubhttps://github.com/matplotlib/mplfinance/issues/639#issuecomment-1666999983, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZCNE6JU5S4CPKKY2EXLCUTXUAQDXANCNFSM6AAAAAAZ3YOQTU. You are receiving this because you were mentioned.Message ID: @.***>

DanielGoldfarb commented 1 year ago

@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 commented 1 year ago

[Image] Trying again

Get Outlook for iOShttps://aka.ms/o0ukef


From: Daniel Goldfarb @.> Sent: Wednesday, August 9, 2023 9:22:29 PM To: matplotlib/mplfinance @.> Cc: TraderMan999 @.>; Mention @.> Subject: Re: [matplotlib/mplfinance] When saving candle charts to file, the candles are red when should be green. why? (Issue #639)

@TraderMan999https://github.com/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 herehttps://github.com/matplotlib/mplfinance/issues/639

— Reply to this email directly, view it on GitHubhttps://github.com/matplotlib/mplfinance/issues/639#issuecomment-1672442064, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZCNE6MOWDHE37OKEONUECTXURAWLANCNFSM6AAAAAAZ3YOQTU. You are receiving this because you were mentioned.Message ID: @.***>

DanielGoldfarb commented 1 year ago

@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.