Page 1 of 1

Find values with equal distance in series

Posted: Sun Dec 13, 2020 7:28 pm
by sakopsn
Hi!

I am searching for a way in Pine Script to find values within a series that have the same “distance” to each other.

So for example within the arraw [1,2,3,5,7,8,9,10]

Those continous subarrays can be found:

Distance 1 = [1,2,3] + [7,8,9,10]

Distance 2 = [1,3,5,7,9] + [8, 10]

Distance 3 = [2,5,8]

Distance 4 = [1,5,9]

Distance 5 = [2,7] + [3,8] + [5,10]

Distance 6 = [1,7] + [2,8] + [3,9]

Distance 7 = [1,8] + [2,9] + [3,10]

Distance 8 = [1,9] + [2,10]

Distance 9 = [1,10]

Now I try to find the easiest way in Pine script to create a function for this which works with the following series as the array to look for equal distance values. The distance to look for is the bar distance. Meaning how many bars are between the pivot lows found:

//@version=4
study("PivotLow", overlay=true)
pl = pivotlow(close, 5, 5)
plot(pl, style=plot.style_cross, linewidth=5, color= color.blue)

Does anyone know how to build this or has allready build something similar?

Thanks!

Sascha

Re: Find values with equal distance in series

Posted: Fri Jan 15, 2021 7:31 am
by Matthew
Unfortunately I don't know of any inbuilt functions that would achieve this and I haven't come across any scripts that address this particular challenge either. This sounds like something you'd need to write your own solution for since it's so specific to your requirements. But good luck with your search and let us know if you find a solution :)