sakopsn
Pine Script Rookie
Pine Script Rookie
Posts: 3
Joined: December 13th, 2020

Find values with equal distance in series

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

User avatar
Matthew
Site Admin
Site Admin
Posts: 92
Joined: July 1st, 2020
Location: Australia
Contact: Website Facebook Twitter TradingView Profile

Re: Find values with equal distance in series

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 :)

sakopsn
Pine Script Rookie
Pine Script Rookie
Posts: 3
Joined: December 13th, 2020

Re: Find values with equal distance in series

Thanks!

Return to “Pine Script Q&A”