Skip to content
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

Chart does not look harmonious with new candles #174

Closed
fxhuhn opened this issue Jun 14, 2020 · 11 comments
Closed

Chart does not look harmonious with new candles #174

fxhuhn opened this issue Jun 14, 2020 · 11 comments
Labels
enhancement New feature or request question Further information is requested released code merged into repo AND released to Pypi

Comments

@fxhuhn
Copy link
Contributor

fxhuhn commented Jun 14, 2020

When I look at the new narrow candles, they look kind of disharmonious. The candles have become very narrow compared to the volume boxes.

ICE_DAX_1COV

The wicks and fuses don't seem to be centered. Would it be possible to additionally frame the candle body?

cov

What do you think?

@fxhuhn fxhuhn added the question Further information is requested label Jun 14, 2020
@DanielGoldfarb
Copy link
Collaborator

If the candles were as wide as the volume boxes, they would be touching each other. My impression is that most people prefer the candles not to touch; but if enough people would prefer wider candles, we can modify the default "width adjustment" algorithm to provide generally wider candles.

For my own taste, I think I'd prefer the candles a little bit wider. Perhaps I will tweak the algorithm as such.

Meanwhile take a look at this notebook to see how you can tweak the candle part of the algorithm to be a little wider. For example you can set kwarg scale_width_adjustment=dict(candle=1.25) in your call to plot:

mpf.plot(data,...,scale_width_adjustment=dict(candle=1.25))

Let me know how that works out for you.

@DanielGoldfarb
Copy link
Collaborator

If you don't mind, I'd like to ask you to make a small change to to the code on your local machine and let me know you opinion of how it makes the candles look.

Please find this line of code in _widths.py:

widths['cw']  = candle_width

which is here:
https://github.com/matplotlib/mplfinance/blob/master/src/mplfinance/_widths.py#L24

And change it to use 65% of the volume width:

widths['cw']  = tuple( [ v * 0.65 for v in volume_width ] )

If you have some time, please do that and let me know what you think.
All the best. Thanks. --Daniel

@fxhuhn
Copy link
Contributor Author

fxhuhn commented Jun 14, 2020

mpf.plot(data,...,scale_width_adjustment=dict(candle=1.25))

Yes, that helps. Not 100% (candles still not centered), but much better!

ICE_DAX_1COV

@fxhuhn
Copy link
Contributor Author

fxhuhn commented Jun 14, 2020

ICE_DAX_1COV

in my case 0.48 looks better.

widths['cw'] = tuple( [ v * 0.48 for v in volume_width ] )

@DanielGoldfarb
Copy link
Collaborator

Regarding candle wicks being slightly off-center, especially when there is a lot of data, that is a problem that pretty much all graphics packages will have, and depends very much on how much data is presented, screen resolution, and plot size. That said, with considerable work, I'm sure we could make it, on average, better. See these two comments which mention the issue:

  1. Feature Request: Alternative method to calculate bar widths #115 (comment)
  2. Feature Request: Alternative method to calculate bar widths #115 (comment)

Please feel free to investigate and propose a solution.

@manuelwithbmw
Copy link

If the candles were as wide as the volume boxes, they would be touching each other. My impression is that most people prefer the candles not to touch; but if enough people would prefer wider candles, we can modify the default "width adjustment" algorithm to provide generally wider candles.

For my own taste, I think I'd prefer the candles a little bit wider. Perhaps I will tweak the algorithm as such.

Meanwhile take a look at this notebook to see how you can tweak the candle part of the algorithm to be a little wider. For example you can set kwarg scale_width_adjustment=dict(candle=1.25) in your call to plot:

mpf.plot(data,...,scale_width_adjustment=dict(candle=1.25))

Let me know how that works out for you.

If the candles were as wide as the volume boxes, they would be touching each other. My impression is that most people prefer the candles not to touch; but if enough people would prefer wider candles, we can modify the default "width adjustment" algorithm to provide generally wider candles.

For my own taste, I think I'd prefer the candles a little bit wider. Perhaps I will tweak the algorithm as such.

Meanwhile take a look at this notebook to see how you can tweak the candle part of the algorithm to be a little wider. For example you can set kwarg scale_width_adjustment=dict(candle=1.25) in your call to plot:

mpf.plot(data,...,scale_width_adjustment=dict(candle=1.25))

Let me know how that works out for you.

Sure, candles should not touch but they would have to be a little wider by default. I have never seen such thin widths in other financial packages. I understand we can already control that linking candle_width to volume_width ourselves, good I will try!

@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Jun 15, 2020

@manuelwithbmw

I will change the default to be somewhat wider ...

probably approximately along the lines of what @fxhuhn found by modifying the code to be widths['cw'] = tuple( [ v * 0.48 for v in volume_width ] ).

Let us know if you agree with that setting as a default. Thanks for the input. Much appreciated.

@manuelwithbmw , @fxhuhn - Please note: the above mentioned line-of-code change will make the default candle with wider for use-cases with a lot of data, but will actually make the default candle width smaller than it is now, for cases of much less data (for example only 20 to 50 data points). Please check with that code change, if you don't mind, and let me know your opinions for cases of less data. If, in your opinions, those (less data) cases are too narrow with the new default, I will come up with an adjustment to the default width that modifies only the default for cases with a lot of data.

I hope to make and release this change to the default width this week.

@DanielGoldfarb DanielGoldfarb added the enhancement New feature or request label Jun 15, 2020
@manuelwithbmw
Copy link

Not sure how to use a 'fork' procedure, trying it now for the first time.
So:
I just tried to change widths['cw'] = candle_width into widths['cw'] = tuple( [ v * 0.65 for v in volume_width ] )
but I do not know how to save and call/run this _widths.py code from my main python code

@manuelwithbmw
Copy link

ICE_DAX_1COV

in my case 0.48 looks better.

widths['cw'] = tuple( [ v * 0.48 for v in volume_width ] )

@DanielGoldfarb FYI personally I find these candles too close to each other. I am trying to test 0.65 and 0.48 with my code but not sure how to 'fork' the code.

Chart with scale_width_adjustment=dict(candle=1.25) added above looked better

@DanielGoldfarb
Copy link
Collaborator

@manuelwithbmw

Manuel,
Thanks.

Chart with scale_width_adjustment=dict(candle=1.25) added above looked better

This gives me enough information; I can extrapolate from there, so you don't have to do widths['cw'] = tuple( [ v * 0.48 for v in volume_width ] )


That said, since it's good to know how to install a local fork/clone:

Once you have a git clone local copy of mplfinance on your machine, you can install it as follows:

  • cd into the main mplfinance directory (the mplfinance directory that contains file setup.py)
  • run pip install -e . <Enter> (Notice the dot at the end just before <Enter>)

The above pip will install the locally cloned package. The -e stands for "editable" which means that if you make changes to the locally cloned package, those changes will be immediately reflected in the installed package (no need to re-install every time you edit a file). This is the set up that I use when developing.

After you are done working with the locally cloned package, you simply pip uninstall mplfinance and then pip install mplfinance (or pip install --upgrade mplfinance). This will re-install the "production" version from Pypi.

If you ever loose track of which one is installed you can run the following command:

python -c 'import mplfinance as mpf;print(mpf.__file__)'

That will print out the location of mplfinance's __init__.py file, which will show the path to your locally cloned version if that is what is presently installed, or will show a path that includes something like .../lib/python3.../site-packages/... if the "production" version is installed.

(Some people do the above local install in a virtual environment to keep it isolated from the rest of the machine. I personally don't bother with virtual environments when working on my own machine: only when I'm working on a shared server with other people, or if I am trying to reproduce a problem that someone else is having and I want to reproduce their whole environment).

All the best. --Daniel

@DanielGoldfarb
Copy link
Collaborator

mplfinance 0.12.5a3 is now on Pypi and addresses the issue of candlewidth defaults.

The fact that at certain resolutions, and/or for relatively larger amounts of data, the candle wicks are sometimes not centered on every candle, is a more complex problem to solve, and will not be addressed at this time.

@DanielGoldfarb DanielGoldfarb added released code merged into repo AND released to Pypi and removed in progress labels Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested released code merged into repo AND released to Pypi
Projects
None yet
Development

No branches or pull requests

3 participants