[RESEARCH] Percentrank Bug

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.


A list of Free indicators:

A list of Paid indicators:

Earn $30:

Toss a coin to your witcher:


Good find. Discrepancies aren't as important on long lengths.
Think ">=" in function should be ">".
+2 返信
@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."
+1 返信
LucF everget
@everget, Ah yes. Right. Sry.
+3 返信
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
+1 返信
everget gorx1
@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
@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:

This is a good article about the different ways how to calculate percentiles
+1 返信
FIXED by TradingView
ホーム 株式スクリーナー FXスクリーナー 仮想通貨スクリーナー 経済指標カレンダー アバウト チャート機能 価格 友達紹介 ハウスルール ヘルプセンター ウェブサイト&ブローカー向けソリューション ウィジェット チャートソリューション 軽量チャートライブラリ ブログ&ニュース ツイッター