Giter Club home page Giter Club logo

Comments (11)

DanielGoldfarb avatar DanielGoldfarb commented on May 21, 2024 2

At present there is no way to do this. You can sort of fake it out with mpf.make_addplot() by passing in a list of data (the same length as your dataframe) that is all nan except for two points (where you want the vertical line). If your data series has a lot of points, it will look like a vertical line. (But if your data series is relatively short, then it will be obvious that the line is on a slight angle ;-)


There is a plan to add two kwargs to mpf.plot(), vline= and hline=

For example, for a vertical line you could specify vline=<someTimeStamp> and you would get a vertical line at that timestamp, or for a horizontal line hline=<somePriceValue> and you would get a horizontal line at that value. Alternatively you could specify a list of timestamps for vline, and/or a list of values for hline, in order to plot more than one vertical or horizontal line (one line for each value in the list).

If you have a different idea as to how the interface should be, that you think may have an advantage over the vline and hline idea, please feel free to describe it here.

If you are interested in coding this vline and hline enhancement, I will be happy to guide you through the code. (Otherwise, I am hoping to code it myself maybe sometime in the next 4 to 8 weeks).


from mplfinance.

Brechard avatar Brechard commented on May 21, 2024 1

I've tried this and works perfectly thanks! Can we get it in make_addplot function too so it can be used for indicators in the lower pannel?

from mplfinance.

coffincw avatar coffincw commented on May 21, 2024

I'd like to vouch for this enhancement, currently, with my project, I'm using the workaround @DanielGoldfarb describes, but the line doesn't look quite straight sometimes.

from mplfinance.

free-soellingeraj avatar free-soellingeraj commented on May 21, 2024

@DanielGoldfarb Let me know if I can help test or implement something on this.

from mplfinance.

DanielGoldfarb avatar DanielGoldfarb commented on May 21, 2024

@free-soellingeraj
Aaron,
Thank you very much for offering to contribute. This is almost done. I have vlines (vertical), hlines (horizontal), and alines (arbitrary) working. I am presently developing tlines (trend), which I expect to finish some time today. If you would like to help test before I enter a PR, you can pick up the code from here. ... and you can see how it works by looking at the following three scratch notebooks:

If you'd rather wait to test in a day (or two, I have some other cleanup to do too) for the PR to be in place, no worries. Up to you. In terms of implementation, if you would like to implement regression tests for this that would also be helpful. Take a look at this test folder and create test_lines.py (or perhaps there should be a separate file for each: test_vlines.py, test_hlines.py, etc. so that the files are more reasonable in size). You can follow the general pattern of what's being done there for other features. Please let me know if any of this is of interest and if you have the time to move forward on any of it.

All the best. --Daniel

from mplfinance.

free-soellingeraj avatar free-soellingeraj commented on May 21, 2024

Sure, I will take a look. I had a need specifically for several of these features. I will let you know.

from mplfinance.

Brechard avatar Brechard commented on May 21, 2024

also being able to choose colors could be interesting

from mplfinance.

DanielGoldfarb avatar DanielGoldfarb commented on May 21, 2024

@Brechard
Rodrigo,

Thanks for the idea regarding make_addplot(). I've been thinking that ideally mpf.make_addplot() should support all the same kwargs that mpf.plot() does. At this point I am not sure if we can support all of them, but certainly some of them should be do-able.

Regarding choosing colors, this is already supported for vlines, hlines, etc.
See the documentation here. You can control colors, linestyle, linewidths, and alpha.

All the best. --Daniel

from mplfinance.

gambitov avatar gambitov commented on May 21, 2024

Dear @DanielGoldfarb, congratulation for your work, it is very helpful.
I am trying to use horizontal lines with different linestyles, I organize data in a list with price (niveles) and style (estilo).

mpf.plot(TA_data, type='candle', axtitle=(symbol), style='yahoo', ax=ax1, volume=ax2,
                xrotation=0, addplot=apds, hlines=dict(hlines=niveles, linewidths=1, colors='k', linestyle=estilo))

but I get next error:

TypeError: kwarg "linestyle" validator returned False for value: "['--', '--', '--', '--', '--', '--', '--']"
    'Validator'   : lambda value: value is None or value in valid_linestyles },

may you help me? please.

from mplfinance.

DanielGoldfarb avatar DanielGoldfarb commented on May 21, 2024

@gambitov
mplfinance [hvta]lines kwargs accept only a single value for linestyle.

However, it does appear from the code that multiple values (list,tuple) are possible for colors and for linewidths. So you may consider using colors= to differentiate your various hlines.

Alternatively, as a work-around, you may draw each horizontal line using mpf.make_addplot() which will allow you to assign a different linestyle to each horizontal line. For example, suppose you want a horizontal lines at values of 185.0 195.0 and 210.0, then, in order to have a different line-type for each line, do the following:

apds = [ 
         mpf.make_addplot( [185.0]*len(TA_data), linestyle='-' ),
         mpf.make_addplot( [195.0]*len(TA_data), linestyle='--' ),
         mpf.make_addplot( [210.0]*len(TA_data), linestyle='-.' )
       ]

Given that colors and linewidths appear to accept multiple values, it seems a reasonable enahncement request for linestyle also to accept multiple values. I will have to investigate: It is certainly reasonable to accept a list or tuple for linestyle for hlines and vlines (assuming the list is the same length as the number of lines requested), but it may raise complications for tlines and alines (if so, then a list or tuple will not be supported for those types of lines).

HTH. All the best. --Daniel

from mplfinance.

fxhuhn avatar fxhuhn commented on May 21, 2024

Hi @DanielGoldfarb ,
it seems that it fits to my hlines proposal mentioned in #219 a dict of dicts ;-)
hlines = [dict_support_lines, dict_resistence_lines]

Regards, Markus

from mplfinance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.