Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I import candlestick_ohlc from mplfinance

So I have been able to successfully install mplfinance with pip and when I import it alone I receive no error. Though when I do: from mplfinance import candlestick_ohlc I get the error ImportError: cannot import name 'candlestick_ohlc' from 'mplfinance' I have checked command prompt again, and it says it has successfully installed mplfinance. Why am I receiving this error?

like image 736
benito.cano Avatar asked Apr 15 '20 20:04

benito.cano


2 Answers

So from what I understand the Matplotlib for finance has changed so that:

To access the old API with the new mplfinance package installed, change statments

from:

from mpl_finance import 

to:

    from mplfinance.original_flavor import candlestick_ohlc

and then it should work fine.

like image 177
benito.cano Avatar answered Sep 20 '22 19:09

benito.cano


You do not have to import 'candlestick_ohlc' anymore.

'mplfinance.plot()' defaults to ohlc style charts.

These links provide good examples. The second one uses candlesticks. You can change that arg.

https://towardsdatascience.com/trading-toolbox-03-ohlc-charts-95b48bb9d748

https://openwritings.net/pg/mplfinance/python-draw-candlestickohlc-using-new-mplfinance

like image 21
Nicholas Portalupi Avatar answered Sep 21 '22 19:09

Nicholas Portalupi