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 do I create a buy indicator using mplfinance? #660

Open
CamTheMyth opened this issue Feb 24, 2024 · 1 comment
Open

How do I create a buy indicator using mplfinance? #660

CamTheMyth opened this issue Feb 24, 2024 · 1 comment
Labels
question Further information is requested

Comments

@CamTheMyth
Copy link

Ask anything you want about mplfinance usage, project philosophy and/or priorities, or anything else related to mplfinance.
How do I create a buy indicator using mplfinance that displays an arrow under a candle where the short and long term moving averages meet?
Screenshot 2024-02-24 000308
download

@CamTheMyth CamTheMyth added the question Further information is requested label Feb 24, 2024
@DanielGoldfarb
Copy link
Collaborator

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:

  1. Call mpf.plot() twice. The first time, as above, but using the return_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 call mpf.plot() again with the additional mpf.make_addplot(...type='scatter'...) to plot markers to highlight where the moving averages meet.

  2. Calculate the moving averages yourself, find where they meet, and then call mpf.plot() with the appropriate mpf.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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants