I am trying to Plot array of integers as horizontal lines on chart tradingview pinescript, the array will have around 2000 numbers. I want to plot numbers that haven’t touched price today (9:15 am to 3:30 pm) and are 0.5% close to current price.Any guidance/snippet is appreciated
//@version=5
indicator("Price Pattern Highlighter", overlay=true)
// Define the array of specific prices to highlight
var float[] pricePatterns = array.from(44044, 43743, 43843, 44444, 44555, 43777, 42888, 43521, 48500)
var line[] lines = array.new_line() // Array to hold line objects
// Function to check if the current price is within 0.5% of any price pattern and draw lines
checkAndDrawPatterns(price) =>
tolerance = 0.005 // 0.5% tolerance
for i = 0 to array.size(pricePatterns) - 1
pattern = array.get(pricePatterns, i)
// Check if price is within the tolerance range
if price >= pattern * (1 - tolerance) and price <= pattern * (1 + tolerance)
// Check if we've already drawn a line for this pattern
if array.size(lines) <= i or array.get(lines, i) == na
// Draw a new line if none exists
l = line.new(bar_index, pattern, bar_index + 1, pattern, width=2, color=color.red, extend=extend.both)
array.set(lines, i, l)
else
// Update the line position to the current pattern price if it already exists
line.set_xy1(array.get(lines, i), bar_index, pattern)
line.set_xy2(array.get(lines, i), bar_index + 1, pattern)
else
// If price is out of the tolerance range, delete the line if it exists
if array.size(lines) > i and array.get(lines, i) != na
line.delete(array.get(lines, i))
array.set(lines, i, na)
// Check patterns on each bar update
checkAndDrawPatterns(close)