-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set single candle color #451
Conversation
I've started testing and going through the code. There will be probably a few changes. Overall it looks good. I have found that when passing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, some comments and minor changes to consider (see within the diff below).
Also, I wrote some test code based on the example in Issue #378 which you may want to use for some testing:
import pandas as pd
import mplfinance as mpf
df = pd.read_csv('data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True)
clist = [None]*len(df)
cseries = pd.Series(clist,index=df.index)
cseries.at['2019-11-08'] = 'yellow'
cseries.at['2019-11-15'] = 'yellow'
cseries.at['2019-11-19'] = 'yellow'
mpf.plot(df,type='candle',colors=list(cseries.array),style='yahoo',block=False)
mc = mpf.make_marketcolors(base_mpf_style='default',up='yellow',down='yellow')
cseries = pd.Series(clist,index=df.index)
cseries.at['2019-11-08'] = mc
cseries.at['2019-11-15'] = mc
cseries.at['2019-11-19'] = mc
mpf.plot(df,type='candle',colors=list(cseries.array),style='yahoo')
The first mpf.plot()
above, should produce three completely yellow candles.
The second mpf.plot()
should produce three candles with yellow bodies but with black edges and wicks similar to the example in the Issue.
(Note: the black edges and wicks come from the style 'default' that was specified in the call to make_marketcolors()
; Even if unspecified, 'default' would still have be used for the edges and wicks because the call to make_marketcolors()
only specifies up
and down
).
Hey @DanielGoldfarb, |
Shivansh,
Let me explain my thinking on the matter: From the user's perspective, the user can specify My thinking was originally (will clarify below why I say "originally" here) that
So there should be no code that manipulates any of the marketcolor attributes, other than the code that converts a string type color specifier to a marketcolor dict where all the attributes are the same (specified) color. Note: when the user creates marketcolor objects (using If the user forgot to specify I still think we should not have such code. However now, based on your comments, I am now thinking that we may either keep my original thinking and push the entire responsibility back on the user to get the marketcolors correct, or we recognize that specifying only the candle body may be a common thing to do, and we might create a relatively easy way for the user to do this such that the user need only specify the color, or up/down, and the rest of the marketcolor attributes come from the style that was passed into I hope this is making sense. Let me know if you have questions. I have some ideas as to how we might implement this last idea (giving the user an easy way to specify up/down and use the remaining attributes from the plot's marketcolors). As I am writing this, however, I am also considering staying with the original idea of putting the entire responsibility on the user to call Thanks. --Daniel |
@AurumnPegasus |
hey @DanielGoldfarb I am so sorry for the delay, the last month of semester really is awful with respect to deadlines. If you can, please give me another day to complete this, I will have it done by 4th dec |
no problem. thank you. |
Hey @DanielGoldfarb, Again, sorry for the delay, hope the code is acceptable now! |
@AurumnPegasus
Thank you. --Daniel |
|
@AurumnPegasus I've been playing around with the code and it seems to be working well. I do believe that we can make the algorithm simpler (and thereby easier to maintain). That said, I should point out that, when I started actually playing with the code, I realized that it is not so trivial to override the marketcolors on a per-candle basis. I am therefore even more grateful for your contribution. Thank you so much! In order to simplify the code, I had to completely rewrite In the meantime, I need to regression test thoroughly to make sure we have not broken any of the established features of mplfinance. I also want to set up some regression tests and examples specifically for this new feature. This is working now for candlesticks. I would like to be able to make it also work for hollow candles, for ohlc bars, and possibly also for renko and point and figure charts. Stay tuned. |
OK. I have updated
|
Hey @DanielGoldfarb , I went through the tutorial notebook, and that looks really good! I also went through the changes you made in the code and liked them (really helps me improve my own coding). It works well from my use case perspective. Thanks! |
@AurumnPegasus |
Hey @DanielGoldfarb ,
I have completed and tested (from my side) the code for #378 as we had discussed.
I have:
If I must make some improvements let me know! Hope it is satisfactory 😄