How do I create a buy indicator using mplfinance?
CamTheMyth opened this issue · 1 comments
mplfinance presently does not contain any code to find and indicate where moving averages are meeting or crossing.
You will need to access the moving average data, and write some code yourself to find where they meet, and then use mpf.make_addplot(...type='scatter'...)
to plot markers where you want them.
There are two ways to access the moving average data:
-
Call
mpf.plot()
twice. The first time, as above, but using thereturn_calculated_values
kwarg. This will give you the moving averages that mplfinance calculated. You can then use that data to find where they cross, and then callmpf.plot()
again with the additionalmpf.make_addplot(...type='scatter'...)
to plot markers to highlight where the moving averages meet. -
Calculate the moving averages yourself, find where they meet, and then call
mpf.plot()
with the appropriatempf.make_addplot(...type='scatter'...)
to highlight where the moving averages meet.
I recommend method 2, because it is simpler.
Using Pandas, the code to calculate a simple moving average is easy and can be seen here.
(or, if you want an exponential moving average, see here).