Speed Diamond
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SamRecio

//@version=5
indicator("Speed Diamond",shorttitle ="♦", overlay = true)

in_target = input.float(1,step = 1, title = "Target", minval = 0)
select = input.string("Percent", options = ["Percent", "Ticks", "Price"], title = "Target Type")
green = input.color(color.rgb(38,208,124), inline = "c")
red = input.color(color.rgb(237,29,36), inline = "c")

target = select == "Percent"?close*(in_target*0.01):select == "Ticks"?in_target*0.25:select == "Price"?in_target:na
lowpt = close - (target)
highpt = close + (target) 

speed = for i = 0 to 3600
    outside = close < lowpt[i] or close > highpt[i]
    if outside
        break
    i

prg = close > close[speed]?green:close < close[speed]?red:color.gray
ud = close > close[speed]?close - target:close < close[speed]?close + target:close[speed]

var label point = label.new(bar_index - speed , close, color = prg, style = label.style_diamond, size = size.small)
var line line1 = line.new(bar_index - speed, close[speed], bar_index + 1, close[speed], color = prg)
var label num = label.new(bar_index, ud, color = prg, style = label.style_none, text = str.tostring(speed))

if 0 == 0
    label.set_x(point,bar_index - speed)
    label.set_y(point,close)
    label.set_color(point,prg)
    line.set_x1(line1, bar_index - speed)
    line.set_y1(line1,ud)
    line.set_x2(line1,bar_index + 1)
    line.set_y2(line1,ud)
    line.set_color(line1,prg)
    label.set_x(num, bar_index)
    label.set_y(num, ud)
    label.set_text(num,str.tostring(speed))
    label.set_textcolor(num,prg)