Paste this indicator into Pine Editor, add it to a standard candlestick chart and set the quote-unit step and tick tolerance for that symbol. The default 5.0 step and 2-tick tolerance are demonstration inputs. Invalid steps or overlapping tolerance zones stop the script with an explanatory error.
Seven nearby horizontal levels; integer-tick proximity; confirmed-close entry condition. Syntax checked on 2026-10-17.pinescript
//@version=6
indicator("Round-number grid and distance", overlay=true, max_lines_count=7)
stepPrice = input.float(5.0, "Grid step in quote units", minval=0.00000001)
toleranceTicks = input.int(2, "Proximity in ticks", minval=0)
tick = syminfo.mintick
stepTicks = int(math.round(stepPrice / tick))
if barstate.isfirst
if stepTicks < 1 or math.abs(stepPrice / tick - stepTicks) > 0.000001
runtime.error("Grid step must be a positive whole number of ticks.")
if toleranceTicks * 2 >= stepTicks
runtime.error("Proximity must be less than half the grid step.")
priceTicks = int(math.round(close / tick))
nearestTicks = int(math.round(float(priceTicks) / stepTicks)) * stepTicks
nearestPrice = math.round_to_mintick(nearestTicks * tick)
distanceTicks = math.abs(priceTicks - nearestTicks)
near = distanceTicks <= toleranceTicks
entered = bar_index > 0 and near and (not near[1] or nearestTicks != nearestTicks[1])
signal = barstate.isconfirmed and entered
var grid = array.new_line()
if barstate.isfirst
for i = 0 to 6
array.push(grid, line.new(bar_index, close, bar_index + 1, close, extend=extend.both, color=color.new(color.blue, 55)))
if barstate.islast
for i = 0 to 6
level = math.round_to_mintick((nearestTicks + (i - 3) * stepTicks) * tick)
levelLine = array.get(grid, i)
line.set_xy1(levelLine, bar_index, level)
line.set_xy2(levelLine, bar_index + 1, level)
plot(nearestPrice, "Nearest grid level", display=display.data_window)
plot(distanceTicks, "Distance in ticks", display=display.data_window)
plotshape(signal, title="Entered proximity at close", style=shape.circle, location=location.belowbar, color=color.blue, size=size.tiny)
alertcondition(signal, "Entered round-number proximity", "Close entered a round-number zone. Check the chart and saved settings.")