Page 1 of 1

Find values with equal distance in series

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

I am looking 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)

Is there any buildIn function that helps me with that or will I have to write the every part of it with basic math functions?

Thanks!

Sascha

Re: Find values with equal distance in series

Posted: Fri Jan 15, 2021 1:22 am
by Matthew
Sorry sakopsn but I don't believe there is a built-in function for this, you're going to need to create your own to achieve this. I'll let you know if I find anything that could help :)

Re: Find values with equal distance in series

Posted: Fri Jan 15, 2021 1:27 am
by sakopsn
Thanks!