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

How to add Horizontal Line in make_addplot? make_addplot(rsi,panel='lower',color='g',hlines=[20,80]) #140

Open
toksis opened this issue May 20, 2020 · 8 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@toksis
Copy link

toksis commented May 20, 2020

I have this code.

 apds = [mpf.make_addplot(buy_signal,scatter=True,markersize=100,marker='^'),
                    mpf.make_addplot(sell_signal,scatter=True,markersize=100,marker='v'),
                    mpf.make_addplot(close_signal,scatter=True,markersize=100,marker='o'),
                    mpf.make_addplot(rsi,panel='lower',color='g',hlines=[20,80])         

  mpf.plot(self.df,addplot=apds,figscale=2,volume=False,type = type,
                 title= str(self.info)
                 )

I want to put a horizontal line for my RSI. But there is a kwargs error which says hline is not found.

@toksis toksis added the question Further information is requested label May 20, 2020
@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented May 20, 2020

hlines is a kwarg to mpf.plot() ( not to mplf.make_addplot())

Presently all of the lines kwargs (hlines,vlines, tlines, alines) assume the main panel axes.

I was thinking to add a panel kwarg to the lines dict, rather than have the kwarg available to addplot.

I will come up with something, and include it in my next pull request, which I hope to make by the end of this week.

In the meantime you can accomplish a horizontal line on the lower panel by creating a sequence of data points all the same value, and passing that as the data for a different make_addplot() call.

@DanielGoldfarb DanielGoldfarb added in progress enhancement New feature or request labels May 20, 2020
@toksis
Copy link
Author

toksis commented May 20, 2020

oh nice! Thanks for the advice ill do it.

@toksis
Copy link
Author

toksis commented May 20, 2020

Done it! woot!

     apds = [mpf.make_addplot(buy_signal,scatter=True,markersize=100,marker='^'),
                    mpf.make_addplot(sell_signal,scatter=True,markersize=100,marker='v'),
                    mpf.make_addplot(close_signal,scatter=True,markersize=100,marker='o'),
                    mpf.make_addplot(line80,panel='lower',color='r'),
                    mpf.make_addplot(line20,panel='lower',color='g'), 
                    mpf.make_addplot(rsi,panel='lower',color='g')                    ]
            

image

@DanielGoldfarb
Copy link
Collaborator

Nice chart! Thanks for sharing!

@rohanchopra
Copy link

rohanchopra commented May 21, 2020

@toksis, You should use secondary_y. Your RSI plot and lines have a different axis.

 apds = [mpf.make_addplot(buy_signal,scatter=True,markersize=100,marker='^'),
              mpf.make_addplot(sell_signal,scatter=True,markersize=100,marker='v'),
              mpf.make_addplot(close_signal,scatter=True,markersize=100,marker='o'),
              mpf.make_addplot(line80,panel='lower',color='r',secondary_y=False),
              mpf.make_addplot(line20,panel='lower',color='g',secondary_y=False), 
              mpf.make_addplot(rsi,panel='lower',color='g',secondary_y=False)
   ]
            

@toksis
Copy link
Author

toksis commented May 21, 2020

Perfect! I thought its a limitation

image

@dss010101
Copy link

dss010101 commented May 20, 2021

Nice chart! Thanks for sharing!

Done it! woot!

     apds = [mpf.make_addplot(buy_signal,scatter=True,markersize=100,marker='^'),
                    mpf.make_addplot(sell_signal,scatter=True,markersize=100,marker='v'),
                    mpf.make_addplot(close_signal,scatter=True,markersize=100,marker='o'),
                    mpf.make_addplot(line80,panel='lower',color='r'),
                    mpf.make_addplot(line20,panel='lower',color='g'), 
                    mpf.make_addplot(rsi,panel='lower',color='g')                    ]
            

image

I have a few questions on this:

  1. is line80 and line20 a series or a single int/float value?
  2. you have "panel='lower'", from documentation i have been reading, shouldn't that be an integer value indicating the index of the panel?
  3. you have "scatter = True", should that be now type = "Scatter"

I prefer this method of adding horizontal or vertical lines as it's line with keeping all plots as some sort of series..as opposed to adding an argument to the plot or add_plot functions. It also helps when trying to write generic code for plotting any type of series.

@msampathkumar
Copy link

line80/line20 => a series of y values

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
Projects
None yet
Development

No branches or pull requests

5 participants