matplotlib / mplfinance

Financial Markets Data Visualization using Matplotlib
https://pypi.org/project/mplfinance/
Other
3.48k stars 613 forks source link

PNF ATR Boxsize #662

Closed fivethreeo closed 4 months ago

fivethreeo commented 4 months ago

I am doing my own point and figure processor in javascript. But my implementation does not have atr box sizes yet. So i am looking at different libs that do this already.

Looking at your code I see you calculate the atr box size once. Should it not take a new atr box size when reaching a new box or a reversal?

DanielGoldfarb commented 4 months ago

Box size should be constant throughout any given PnF chart. Otherwise the chart becomes meaningless and difficult to interpret. While I can certainly understand perhaps wanting to plot the same data once with one box size, and again with another box size ... to compare and see the effect adjusting the box size (which reflects sensitivity of the plot); it none-the-less makes no sense to modify the box size in the middle of a plot.

That said, if you can provide a reference that discusses some advantage of modifying the box size throught a single plot, I will review the reference and consider it. In the meantime, here is a good article for better understanding box size: https://www.investopedia.com/terms/b/boxsize.asp

fivethreeo commented 4 months ago

Maybe atr just makes sense for assets that have a more stable range.

But if the first 14 periods vary less or more than the rest of the periods, won't the box size be too small or too large?

Or that the point of having a atr box size?

DanielGoldfarb commented 4 months ago

A few points to consider:

  1. ATR uses the most recent N periods (not the first N periods); the idea being that the most recent periods reflect current market conditions more accurately.

  2. ATR is just a method for coming up with a reasonable box size that you might want to use. It gives a box size that is reasonable for the data.

  3. Ultimately the box size you choose depends on the level of granularity you want, which in turn depends on how frequently you like to trade. A smaller box size will give trade signals more frequently.

  4. You can set the atr_length='total' in which case the entire data set will be used to calculate the ATR. This obviates any worry that the box size calculated by ATR is reasonable for only the most recent portion of the data. (Although it is typically only the most recent portion of the data that is going to affect your next trade decision).

  5. You don't have to use ATR, you can (obviously) set any specific box size you want. Additionally if you pass box_size as a string with a percent sign (for example '5%') then the box size will be set to that percentage of the most recent close price. This is another method of finding a reasonable box size to start with.

fivethreeo commented 4 months ago

Ah, ofcourse latest, then it makes sense. Been porting pypnf to javascript so starting to have a goid grasp on percentage and normal box sizes. Thanks for clearing up the atr confusion on my part.