Above 0.5 is supposed to indicate a trend is present.
Below 0.5 is noise.
0.5 is supposed to be Brownian Motion or regular market noise.
If you have corrections to the code you want to share, please post it.
I'm not an expert in math or coding, so this shouldn't be copied / ported.
This code didn't work very well as a filter, but you may have a fix or other use.