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

What is the most elegant way to implement ribbons? #668

Open
fxhuhn opened this issue Apr 26, 2024 · 4 comments
Open

What is the most elegant way to implement ribbons? #668

fxhuhn opened this issue Apr 26, 2024 · 4 comments
Labels
question Further information is requested

Comments

@fxhuhn
Copy link
Contributor

fxhuhn commented Apr 26, 2024

I am currently thinking about the most elegant way to display 1-2 scatter lines below the chart.
Are there any ideas from others who have already implemented this?

These are my first ideas:
image

import mplfinance as mpf

output = sp_500 ['2021-01-01':].copy()

output["sma_above"] = np.where (output.Close > output.sma, output.sma, np.nan)
output["sma_below"] = np.where (output.Close < output.sma, output.sma, np.nan)

output["ribbon_above"] = np.where (output.Close > output.sma, 1, np.nan)
output["ribbon_below"] = np.where (output.Close < output.sma, 1, np.nan)



add_plt = [
    mpf.make_addplot(output["sma_above"],color="green"),
    mpf.make_addplot(output["sma_below"],color="red"),
    mpf.make_addplot(output["ribbon_above"], panel=1, color="g", type='scatter'),    
    mpf.make_addplot(output["ribbon_below"], panel=1, color="r", type='scatter'),    
    ]

mpf.plot(
    output,
    addplot=add_plt,
    figsize=(16, 9),
    style="charles",
    type="candle",
    title='S&P 500 - weekly',
    datetime_format='%d.%m.%y',xrotation=45,
)
@fxhuhn fxhuhn added the question Further information is requested label Apr 26, 2024
@DanielGoldfarb
Copy link
Collaborator

@fxhuhn
Markus, I don't understand what you mean by ribbons here. Ribbons that I have seen are typically called "moving average ribbons" and look like this: Is this what you are talking about?

image

@fxhuhn
Copy link
Contributor Author

fxhuhn commented Apr 28, 2024

oh @DanielGoldfarb sorry for the confusion. That's for me a rainbow ;-)
I mean something similar to the bottom line from this chart:
image

@DanielGoldfarb
Copy link
Collaborator

I think what you've done makes a lot of sense, but perhaps try type='bar' instead of type='scatter'?

@fxhuhn
Copy link
Contributor Author

fxhuhn commented May 3, 2024

You're right for the bars, although the circles also look quite good in the first attempt.
Do you have any idea how to implement multiple stacked rows with these signals?

Is it possible to set the height of the panel so that the distances to the rows are minimal?

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