TradingView
everget
7 de Mar. de 2019 1:33

[RESEARCH] Percentrank Bug 

XRP / DollarBitfinex

Descripción

I found a bug with built-in percentrank function. Sometimes it gives unexpected and incorrect results. You can see a one of them on the chart.

ALL scripts which use percentrank function are affected. No matter which version they use, no matter who is their author - ALL scripts which use this built-in function can work incorrectly.

If you want to avoid this bug use _percentrank function (the "shim") - you can find it in the script.

NOTE: Don't push on TradingView Support or Pine Core Team because they already know about this issue and work on the fix. I publish it to warn you.
Comentarios
LucF
Good find. Discrepancies aren't as important on long lengths.
Think ">=" in function should be ">".
everget
@LucF, Hi, thank you.
I followed the built-in percentrank() description: "Percent rank is the percents of how many previous values was less than or equal to the current value of given series."
LucF
@everget, Ah yes. Right. Sry.
gorx1
Found the common bug in both percentile functions (both nearest rank & linear one), at least numpy calculates it a bit different, and I lean towards numpy in terms of accuracy
everget
@gorx1, Could you provide more detail? There is a special Trello board with TradingView staff where script developers report bugs and request new features, so you could participate in it too
gorx1
@everget, after further investigation it turned out that numpy calculates percentiles, quantiles etc using some kinda unorthodox methods, for some reason they mess with indexing of elements, while on TradingView the classic methods are being used (checked again, they are implemented right). Now I lean back towards TradingView again xd

More info about how they do it in NumPy:
github.com/numpy/numpy/issues/8821

EDIT:
This is a good article about the different ways how to calculate percentiles
analyse-it.com/blog/2013/2/quantiles-percentiles-why-so-many-ways-to-calculate-them
everget
FIXED by TradingView
Más