30 Second Futures Session Open Range
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SamRecio

//Insipired by Tradingview User @Emmonspired

//@version=5
indicator("30 Second Futures Session Open Range",shorttitle = "30 Sec OR", overlay = true, max_lines_count = 500)

or_time = hour(time,"America/Chicago") + minute(time,"America/Chicago")*0.01

l_high = request.security_lower_tf(syminfo.tickerid,"30S",high)
l_low = request.security_lower_tf(syminfo.tickerid,"30S",low)

get_or(_time) =>
    hi = ta.valuewhen(or_time == _time and second == 0,array.size(l_high)>0?array.get(l_high,0):0,0)
    lo = ta.valuewhen(or_time == _time and second == 0,array.size(l_low)>0?array.get(l_low,0):0,0)
    [hi,lo]

asn = 17.00
eur = 2.00
ny = 8.30

[asn_h,asn_l] = get_or(asn)
[eur_h,eur_l] = get_or(eur)
[ny_h,ny_l] = get_or(ny)

asn_m = math.avg(asn_h,asn_l)
eur_m = math.avg(eur_h,eur_l)
ny_m = math.avg(ny_h,ny_l)

plot(ny_h, color = color.aqua, title = "RTH OR High", display = display.pane+display.price_scale, style = plot.style_stepline)
plot(ny_m, color = color.yellow, title = "RTH OR Mid", linewidth = 2, display = display.pane+display.price_scale, style = plot.style_stepline)
plot(ny_l, color = color.aqua, title = "RTH OR Low", display = display.pane+display.price_scale, style = plot.style_stepline)

plot(asn_h, color = color.orange, title = "Globex OR High", display = display.pane+display.price_scale, style = plot.style_stepline)
plot(asn_m, color = color.fuchsia, title = "Globex OR Mid", linewidth = 2, display = display.pane+display.price_scale, style = plot.style_stepline)
plot(asn_l, color = color.orange, title = "Globex OR Low", display = display.pane+display.price_scale, style = plot.style_stepline)

plot(eur_h, color = color.olive, title = "Europe OR High", display = display.pane+display.price_scale, style = plot.style_stepline)
plot(eur_m, color = color.lime, title = "Europe OR Mid", linewidth = 2, display = display.pane+display.price_scale, style = plot.style_stepline)
plot(eur_l, color = color.olive, title = "Europe OR Low", display = display.pane+display.price_scale, style = plot.style_stepline)

lab(_text,_color,_value) => 
    lab = label.new(bar_index+1, _value, style = label.style_label_left,color = color.rgb(0,0,0,100), textcolor = _color, text = str.tostring(_value,"##.00"),tooltip = _text, size = size.small)
    label.delete(lab[1])

lab("RTH OR-H",color.aqua,ny_h)
lab("RTH OR-M",color.yellow,ny_m)
lab("RTH OR-L",color.aqua,ny_l)

lab("GLOBEX OR-H",color.orange,asn_h)
lab("GLOBEX OR-M",color.fuchsia,asn_m)
lab("GLOBEX OR-L",color.orange,asn_l)

lab("EUROPE OR-H",color.olive,eur_h)
lab("EUROPE OR-M",color.lime,eur_m)
lab("EUROPE OR-L",color.olive,eur_l)


//Price Targets//

t_tog = input.bool(true, title = "Display RTH Targets", group = "Targets")
t_perc = input.float(50, title = "Target %", group = "Targets", inline = "1")*0.01
t_color = input.color(color.new(color.silver,50), title = "", group = "Targets", inline = "1")
t_style = input.string("- - -", title = "Style", options = ["___","- - -",". . .","none"], group = "Targets", inline = "2")
t_width = input.int(1, minval = 1, title = "Width", group = "Targets", inline = "2")

extend_lines(_linearray) =>
    if array.size(_linearray) > 0
        for i = 0 to array.size(_linearray) - 1
            lx = array.get(_linearray,i)
            line.set_x2(lx,bar_index)

linestyle(_input) =>
    _input == "___"?line.style_solid:
     _input == "- - -"?line.style_dashed:
     _input == ". . ."?line.style_dotted:
     na


reset = or_time == ny
width = ny_h-ny_l
value = math.max(width*t_perc,syminfo.mintick)
var roof = ny_h
var floor = ny_l
all_lines = line.all
if reset 
    roof := ny_h
    floor := ny_l
    if array.size(all_lines) > 0
        for i = 0 to array.size(all_lines) - 1
	        line.delete(array.get(all_lines, i))
if close<floor and t_tog
    down_count = math.ceil((floor-close)/value)
    for i = 1 to down_count
        line.new(bar_index,floor-(i*value),bar_index,floor-(i*value),color = t_color, width = t_width, style = linestyle(t_style))
    floor := floor-(down_count*value)
if close>roof and t_tog
    up_count = math.ceil((close-roof)/value)
    for i = 1 to up_count
        line.new(bar_index,roof+(i*value),bar_index,roof+(i*value),color = t_color, width = t_width, style = linestyle(t_style))
    roof := roof+(up_count*value)
extend_lines(all_lines)





