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

PNF Box Dates & Renko reversal size #623

Open
Pipsopath opened this issue Jun 7, 2023 · 7 comments
Open

PNF Box Dates & Renko reversal size #623

Pipsopath opened this issue Jun 7, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@Pipsopath
Copy link

First of all my big appreciation to Daniel and all other contributors for this great resource!

I have a request regarding the 'pnf' resp. 'renko' chart:

  1. Is it possible to include to the return_calculated_values an additional array, that contains the dates for each box (e.g. pnf_box_date), that is matching the pnf_values? I guess it can be created easily in the same step when the pnf_values is processed.

  2. I tried to get the dates from the renko return_calculated_values, but since there is no reversal size considered and therefore not equivalent to the 'pnf' chart, it was not possible. This would lead to my 2nd proposal to add reversal brick according to the 'pnf' logic.

@Pipsopath Pipsopath added the enhancement New feature or request label Jun 7, 2023
@DanielGoldfarb
Copy link
Collaborator

Please take a look at the Output from cell In [6] and from cell In [9] in the following notebook: https://github.com/matplotlib/mplfinance/blob/master/examples/scratch_pad/price-movement_ret_calc_vals.ipynb

Is that not what you are looking for??

@Pipsopath
Copy link
Author

Pipsopath commented Jun 7, 2023

Hi Daniel,
thanks for the quick reply.

In [9] gives the Dates for each column (start of the trend), but I am looking for the dates within each column for the X/O boxes. Currently there is the pnf_values and my requested dates would give the time of reaching these pnf_values.
I tried to work around by generate these dates by using the dates from the return_calculated_values of renko charts In[6] (which should in theory be working), but as renko does not consider reverse parameter, I can not pass over same set of parameters for renko and pnf.

From performance point of view it would also consume more calcuation time to run pnf and renko. I guess a solution would be, where there is the trigger to fill the pnf_values array, in the same time the requested pnf_box_date array can be filled with the date of the tick. The overall idea is to have the exact dates of signals that can be then used to transfer to a candlestick chart.

Nevertheless, an reversal parameter in the renko would also be great, like it was added to the pnf.

@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Jun 7, 2023

OK. I did some playing around with the dates, and I've added a new key to the return_calculated_values dict for PNF.

Try this:
pip install "git+https://github.com/DanielGoldfarb/mplfinance.git@issue623_pnf"

The new key is called pnf_detail. It contains the same information as pnf_values but also contains a timestamp for each box in each column. Let me know if that's what you had in mind.

Regarding dates for renko, they are already there, under the key renko_dates. Renko bricks do not stack up vertically (as do pnf boxes) therefore there is exactly one date for each brick.

As a general rule, to see what is in the calculated values dict, you can use code similar to this:

cv= {}
mpf.plot( df, type='renko', return_calculated_values=cv, volume=True)

print('\ncv.keys()=',cv.keys(),'\n')

import pprint
pp = pprint.PrettyPrinter()
pp.pprint(cv)

The above will show you everthing in the return_calculated_values dict, so there is no need to remember what key each item is listed under.

@SSTrader100
Copy link

Many thanks for this wonderful resource!
I have a query regarding the atr used in Renko (and PnF).
Say, I plot data from 100 to 175 bars as a Renko chart. Which atr is used to calculate the box size?
(The atr for the first brick, i.e. bar number 100, or the atr for the last brick, i.e. bar number 175 or atr for the previous brick or some other method?)
Thanks in advance.

@DanielGoldfarb
Copy link
Collaborator

@SSTrader100
The ATR used is that calculated for the most recent data point.

@SSTrader100
Copy link

Thanks for the clarification. I am plotting 5 minute bars as Renko and I refresh the chart every five minutes. The starting date and time do not change. So, after refresh, often the previous Renko bars change since the latest ATR has changed. After your clarification, I have used pandas_ta to calculate the ATR for the bar just before my starting price bar. In order to avoid unnecessary calculations, I am creating a small DF t get this single ATR value. this ATR does not change during refresh and even when I plot the data from the same starting price bar anytime. This is the code I used:

Calculate the ATR based on the df_for_atr using pandas_ta

        atr_series = ta.atr(df_for_atr['High'], df_for_atr['Low'], df_for_atr['Close'], length=atr_length)
        atr = atr_series.iloc[-1]
        brick_size = atr if brick_size == 'atr' else brick_size

@DanielGoldfarb
Copy link
Collaborator

@SSTrader100
As you have apparently noticed, mplfinance allows you to pass in the brick size. Calculating the ATR outside of mplfinance and passing it in as the brick size is perfectly fine. Alternatively, if you want, you can allow mplfinance to calculate the ATR as it makes the initial plot, and then pass it in on subsequent calls when updating the plot. To access the 'renko_size' that mplfinance calculated, use the return_calculated_values kwarg when calling mpf.plot(). Just wanted you to be aware of this alternative; either technique is fine; do whichever you feel works best for your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants