0

I try to collect Support/Resistance levels into an array but my code bele never adds data to the array so its size always remains 0. What do I do wrong? (Of course, there is another similar code for lowest values, with different length sizes, the code is simplified for you.)

upper = ta.highest(50) 
prec = 2 // its GBPUSD btw.

var SupportResistance = array.new_float() 

if math.round(upper[0], prec) < math.round(upper[1], prec)
    if array.size(SupportResistance) == 0 // first data to the array, how could its size be zero?
        array.push(SupportResistance, math.round(upper[1], prec))
    else 
        for i = 0 to array.size(SupportResistance) - 1
            if math.round(upper[1], prec) != array.get(SupportResistance, i) // no duplications
                array.push(SupportResistance, math.round(upper[1], prec))
Vendrel
  • 865
  • 9
  • 19
  • 1
    Oh, it does add to array. And it adds quite a bit (`2^n`) because your implementation is off. On what timeframe and ticker id are you running this? – vitruvius Jul 27 '23 at 12:59

1 Answers1

1

try this:

//@version=5
indicator("My script")

upper = ta.highest(50) 
prec = 2 // its GBPUSD btw.

var SupportResistance = array.new_float() 

if math.round(upper[0], prec) < math.round(upper[1], prec)
    if not array.includes(SupportResistance, math.round(upper[1], prec)) 
        SupportResistance.push(math.round(upper[1], prec))

plot(SupportResistance.size())

Starr Lucky
  • 1,578
  • 1
  • 7
  • 8