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

Price Reversal for Renko or PNF #687

Closed
manojjenago opened this issue Dec 23, 2024 · 4 comments
Closed

Price Reversal for Renko or PNF #687

manojjenago opened this issue Dec 23, 2024 · 4 comments
Labels
question Further information is requested

Comments

@manojjenago
Copy link

Hi,

First of all, I want to express my gratitude for such a beautiful charting library—it's truly impressive.

I have a question regarding a strategy I'm developing. Specifically, I would like to mark the price level of a particular chart. For example, when the price crosses above the first red Renko/PnF bar, I want to trigger a buy. My question is: How can I retrieve the levels and other relevant details from the chart in order to implement this strategy?

Thank you for your help!

Thanks ,
MJ

@manojjenago manojjenago added the question Further information is requested label Dec 23, 2024
@DanielGoldfarb
Copy link
Collaborator

@manojjenago
Copy link
Author

@manojjenago

https://github.com/matplotlib/mplfinance/wiki/Access-to-mplfinance-Calculated-Values

hth. --Daniel

Thank you so much.
So I guess I need to convert to pandas Data frame to get the index of the values. I have the following line of code . Is this correct way ?

cv = {}
mpf.plot(daily,renko_params=dict(brick_size='atr', atr_length=2),style='blueskies',return_calculated_values=cv)

df = pd.DataFrame(cv)

@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Dec 26, 2024

@manojjenago

You don't have to convert it to a dataframe. It will be returned to you as a dict, and you can do whatever you want with it.

It does seem reasonable, for your stated goals, to convert to a dataframe, as one way to find the crossover points that you are looking for. However you need to be careful because, due to the nature of renko and pnf, the datetimes returned for renko and pnf will not correspond point-for-point with the datetime index in your data. Furthermore it is possible that some datetimes in the renko_dates or pnf_dates return may repeat themselves.

So, it is entirely up to you, whether you simply grab the list of brick/box prices out of the returned cv dict, and do your processing on the list to find the crossover (and then grab the corresponding datetime for the dates list in the dict), or first convert to a dataframe before processing. It really doesn't matter. I would choose whichever seems easier to you. Personally I would lean towards not converting, and just process as lists of prices and dates, at least as a initial draft of coding it. (You can always refactor your code to process as a dataframe later. The reason I would shy away from a dataframe on a first pass is because the datetimes returned are not monotonic. That said, you can keep the datetimes as a column in the dataframe and simply let the index be a range of integers, which I suspect, without testing, is what your code df = pd.DataFrame(cv) would do. That could certainly work as well).

@manojjenago
Copy link
Author

@manojjenago

You don't have to convert it to a dataframe. It will be returned to you as a dict, and you can do whatever you want with it.

It does seem reasonable, for your stated goals, to convert to a dataframe, as one way to find the crossover points that you are looking for. However you need to be careful because, due to the nature of renko and pnf, the datetimes returned for renko and pnf will not correspond point-for-point with the datetime index in your data. Furthermore it is possible that some datetimes in the renko_dates or pnf_dates return may repeat themselves.

So, it is entirely up to you, whether you simply grab the list of brick/box prices out of the returned cv dict, and do your processing on the list to find the crossover (and then grab the corresponding datetime for the dates list in the dict), or first convert to a dataframe before processing. It really doesn't matter. I would choose whichever seems easier to you. Personally I would lean towards not converting, and just process as lists of prices and dates, at least as a initial draft of coding it. (You can always refactor your code to process as a dataframe later. The reason I would shy away from a dataframe on a first pass is because the datetimes returned are not monotonic. That said, you can keep the datetimes as a column in the dataframe and simply let the index be a range of integers, which I suspect, without testing, is what your code df = pd.DataFrame(cv) would do. That could certainly work as well).

Thank you so much.

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