In a PineScript (v5), when I am trying to remove a duplicate using the following code snippet, getting a below error:
removeDuplicates(arrayData) =>
copyArrayData = array.copy(arrayData)
for i = 0 to (array.size(arrayData) == 0 ? na : array.size(arrayData) - 1)
data = array.get(arrayData, i)
for j = i to (array.size(arrayData) == 0 ? na : array.size(arrayData) - 1)
if (data == array.get(arrayData, j))
array.remove(copyArrayData, j)
copyArrayData
My arrayData is just a price array of 5 elements.
The error:
In array.remove() function. Index 5 is out of bound, array size is 5.
Attached the photo.
My call of the function is like this:
finalSupportArray := removeDuplicates(finalSupportArray)
finalResistanceArray := removeDuplicates(finalResistanceArray)