Price Reversal for Renko or PNF
Closed this issue · 4 comments
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
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)
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).
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
listof 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 codedf = pd.DataFrame(cv)would do. That could certainly work as well).
Thank you so much.