Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw the support and resistance lines on a candlestick graph using mplfinance?

I need to draw two horizontal lines to show support and resistance.

Here is my code:

from alpha_vantage.timeseries import TimeSeries
import mplfinance as mpf
ts = TimeSeries(key='', output_format='pandas', indexing_type='date')
data, meta_data = ts.get_daily(symbol='MSFT', outputsize='compact')
data = data.sort_values(by=['date'])
data.rename(columns={'date':'Date','1. open':'Open','2. high':'High','3. low':'Low','4. close':'Close','5. volume':'Volume'}, inplace=True)
mpf.plot(data, title='MSFT', ylabel='Price', ylabel_lower='Volume', type='candle', style='charles', volume=True, mav=(50, 200), savefig='test-mplfiance.png')

How can I do that?, I managed to draw the candlesticks on the graph but I can't draw the lines.

like image 787
Claudio Rodrigo Avatar asked Sep 17 '25 06:09

Claudio Rodrigo


1 Answers

Hope this thing works. Try to find the support and resistance and add it to hlines

mpf.plot(data,hlines=dict(hlines=[support,resistance],colors=['g','r'],linestyle='-.'), title='MSFT', ylabel='Price', ylabel_lower='Volume', type='candle', style='charles', volume=True, mav=(50, 200), savefig='test-mplfiance.png')
like image 172
Ripper Avatar answered Sep 19 '25 14:09

Ripper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!