title: How to find the closest value in pinescript array?
body: <p>In pine script, I have an array called levels. In there, I am adding several values and sorting it out.
  Now I want to find the closest value from that array to the current price. How do I do that?</p>
  <pre><code>levels = array.new_float(size = 3, initial_value = na)
  
  // push all value into array
  array.push(levels, valOne) 
  array.push(levels, valTwo) 
  array.push(levels, valThree) 
  .......
  
  // sort the array
  array.sort(levels, order.ascending)
  
  // get s r value
  supportForLong = array.min(levels) // I want to find the closest value in level and not min
  resistanceForLong = array.max(levels)
  
  
  plot(supportForLong, color = black)
  plot(resistanceForLong, color = black)
  // clear all element for next iteration
  array.clear()
  </code></pre>