first hour high and low by akash maurya
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © akash_maurya

//@version=5
indicator(title='first hour high and low', shorttitle='FIRST HOUR', overlay=true,explicit_plot_zorder=true)


t = time('1440', session.regular)
//3600000
var line fhHLine = na
var line fhLLine = na
var line vLine = na
var line secLineLow = na
var line secLineHigh = na
hourHigh = request.security(syminfo.tickerid, '60', high)
hourLow = request.security(syminfo.tickerid, '60', low)
isShowEverywhere   = input.bool(false, "Show lines daily",   inline = "01")
isShowVert   = input.bool(true, "show vertical line")

isLastBar() =>
    not na(t[1]) and na(t) or t[1] < t
// setLastBar(lineValue)=>
//     if isLastBar()
//         line.set_xy2(lineValue, bar_index[0], hourHigh[1])

if time - t == 3600000
    if not isShowEverywhere
        line.delete(fhHLine)
    line.delete(secLineLow)
    line.delete(secLineHigh)
    line.set_x2(fhHLine, bar_index)

    line.set_extend(fhHLine, extend.none)
    fhHLine := line.new(na,na,na,na, style=line.style_solid, color=color.green, extend=extend.right)
    line.set_xy1(fhHLine,bar_index[1], hourHigh[1])
    line.set_xy2(fhHLine, bar_index, hourHigh[1])
    // setLastBar(fhHLine)
    // if isLastBarValue
    //     line.set_xy2(fhHLine, bar_index[1], hourHigh[1])
        
    if not isShowEverywhere
        line.delete(fhLLine)
    
    line.set_x2(fhLLine, bar_index)
    line.set_extend(fhLLine, extend.none)
    fhLLine := line.new(bar_index[1], hourLow[1], bar_index, hourLow[1], style=line.style_solid, color=color.red, extend=extend.right)
    
    if not isShowVert
        line.delete(vLine)
    vLine := line.new(bar_index[1], hourHigh[1], bar_index[1], hourLow[1], color=color.yellow, width=3)
    
    perCh = ((hourHigh[1]-hourLow[1])/hourHigh[1]) * 100
    
    if perCh > 1.5
        secLineLow := line.new(bar_index[1], hourLow[1]+2, bar_index, hourLow[1]+2, style=line.style_solid, color=color.new(color.red,50), extend=extend.right)
        secLineHigh := line.new(bar_index[1], hourHigh[1]-2, bar_index, hourHigh[1]-2, style=line.style_solid, color=color.new(color.green,50), extend=extend.right)
    color labelCol = if perCh > 1.5
        color.green
    else
        color.red
    
    labelTextCol = if perCh >= 1.5
        color.white
    else
        color.white
     
    upperLabel = label.new(x=bar_index[1], y=hourHigh[1] + 0.5,color=labelCol,textcolor= labelTextCol, text=str.format('{0,number,#.#} %',perCh)) 

