TradingView
HayeTrading
28 déc. 2021 16:17

ROC Percentile 

Bitcoin / TetherUSBinance

Description

Rate Of Change Percentile calculates the current ROC (user defined length) as a percentile rank.

We use 2 separate arrays, one for all positive ROC values and one for all negative values within a defined lookback period. Then the current ROC value is compared to those arrays to find it's percentile ranking.
For example, a ranking of 75 means the ROC is in the 75th percentile of all POSITIVE ROC values over the lookback period.
A ranking of -80 is in the 80th percentile of all NEGATIVE ROC values over the lookback period.

Most ROC scripts use raw ROC values (or smoothed or otherwise altered), or have stochastic formula applied to them, I've not seen one that displays ROC as percentile ranking of previous positive/negative values.

What is the advantage?

Raw ROC data only gives half the picture. What we want to do is compare the ROC to previous ROC values, to give a sense of scale. Raw ROC values don't give you that context and you can only compare visually, usually limited to the number of bars you can see on your screen.
Using a percentile ranking gives us the context of current Rate of Change relative to the previous Rate of Change over a large lookback period, and not just visually but mathematically.

Why not using a long stochastic ROC? The problem with stochastics in general is that an outlier data point can ruin the data for the rest of the lookback period.
For example, imagine a huge outlier 8% ROC. The 2nd largest ROC is 4% and the 3rd largest is 2%, with all other values below this.
In this example, a stochastic ROC would display the 8% outlier as 100, the 4% as 50, the 2% as 25 and all other data would be squeezed down between 0-25.
Additionally, a value of 60 may have vastly different meaning depending on whether the lookback period contains a large outlier or not.

With a percentile ranking, that 8% outlier would still have a value of 100. But the 4% and 2% would be 99 and 98 respectively (this assumes 100 data points in the series, in reality values will usually be decimals).
This effectively flattens the curve and gives a more consistent and dependable experience, allowing you to more accurately assess the relative importance of the current ROC.

The line of circles is set at the 50 and -50 values for quick comparison.
Values > 50 represent ROC greater than 50% of previous positive ROC values.
Values < -50 represent ROC greater than 50% of previous negative ROC values.
Commentaires
Prle99
Hi mate,

just to tell appreciated the effort , but somehow i cant not grasp your indicator. At lower time frames its totally inaccurate , where there is minimum change in price your indicator stay in high % zone for quite some time. I do understand that your aim was to show long range changes , but the negative of low accuracy in recent change is very high for me. Maybe you can make few ranges that would check on each other ? So to make low rage of 21 then next range of 21-42 and so on? Maybe that way you could keep accuracy for long and have graphical representation of long range? Also not sure but to me it seems that pos and neg values are not affecting each other , or i just missed that part? Idea seems nice tho. Thank you
HayeTrading
@Prle99, thanks for the feedback, but I’m quite sure the code works as intended.
Can you post a screenshot of an example where you believe the values to be incorrect?

Remember that the default value is a ROC of 10 bars eg the difference between current value and the value 10 bars previous, and then this value is ranked - positive values against all positive values, negative against negative. It sounds like you want the indicator to be more responsive, in which case you can change the ROC value to a lower number. Try a ROC of 3, or even 1 and you might find it more appropriate for your intended use.

Regarding pos and neg not affecting each other, perhaps try swapping line 38 and 39 to line plots and this may make more sense; you’re right, they don’t affect each other, they’re entirely separate values. The current ROC value will either be positive or negative. If it’s positive, it will have a ranking value within the pos array, but the ranking within the neg array will be 0, and vice versa. Both values are being plotted at the same time, which will be obvious in a line plot. We use plot.style_columns as a way to visually ignore the 0 values.
This isn’t a bug or a workaround, it’s an intended feature, to ensure we are comparing apples to apples.
DracmaCapital
You did an amazing job here. Is there a way to add alerts?
UnknownUnicorn40403838
perfect thank you so much works great cheers
HayeTrading
I'm happy to answer any questions, or if you have feedback for changes/improvements you'd like to see please leave a comment.
Plus