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

Created on 20 May 2020  路  6Comments  路  Source: matplotlib/mplfinance

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.

enhancement question

Most helpful comment

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.

All 6 comments

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.

oh nice! Thanks for the advice ill do it.

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

Nice chart! Thanks for sharing!

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

```python
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)
]

```

Perfect! I thought its a limitation

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andresberejnoi picture andresberejnoi  路  6Comments

ismailbayram picture ismailbayram  路  4Comments

jainraje picture jainraje  路  4Comments

skfnxh picture skfnxh  路  3Comments

mattcambs picture mattcambs  路  3Comments