Tom Mart
Tom Mart

Reputation: 57

1 hour Session high and Low

I want to see the first hours high and low and have it marked on my chart on the 5 minute timeframe

The issue I'm having it that the lines from the previous days hour high/low are going into the current session until the new current session high/low is drawn.

How and I plot the current days high/low up during the first hour and then plot have that plotted for the rest of the day?

Below is my code:

bartimeSess = time('D')
newbarSess = bartimeSess != bartimeSess[1]


high_range = ta.valuewhen(newbarSess,high,0) 
low_range = ta.valuewhen(newbarSess,low,0)

locHigh = request.security(syminfo.tickerid, "60", high_range)
locLow = request.security(syminfo.tickerid, "60", low_range)

up1= plot(time(timeframe.period) > 0 ? locHigh : na,title="IB High", color=color.lime, 
transp=20, linewidth=2)
down1 = plot(time(timeframe.period) > 0 ? locLow : na,title="IB Low", color=color.red, 
transp=20, linewidth=2)

fill(up1, down1, color = color.rgb(255, 255, 255, 83))

Upvotes: 0

Views: 938

Answers (1)

Sagittarius Trader
Sagittarius Trader

Reputation: 21

//@version=4   
showInitialBalance = input(true,title="Initial Balance")  
//Session Rules    
bartimeSess = time("D")
newbarSess = bartimeSess != bartimeSess[1]
high_range = valuewhen(newbarSess,high,0)
low_range = valuewhen(newbarSess,low,0)
adopt(r, s) => security(syminfo.tickerid, r, s,lookahead=barmerge.lookahead_on)

//Formula For Opening Range  
highRes = adopt(res, high_range)  
lowRes = adopt(res, low_range)

//Plot Statements For Opening Range Lines  
p1 = plot(showAll and showInitialBalance and highRes ? highRes : na, color=color.aqua, style=plot.style_circles, linewidth=2)  

p2 = plot(showAll and showInitialBalance and lowRes ? lowRes : na, color=color.aqua, style=plot.style_circles, linewidth=2)  

sixtyMinHigh = showAll and showInitialBalance and highRes ? label.new(bar_index, highRes, text=display_value ? ("                        1HrH"  + " " + tostring(nround(highRes))) : "1h-High",  style= label.style_none,size= size.normal) : na  

label.set_textcolor(sixtyMinHigh,textcolor=color.aqua)  
label.delete(sixtyMinHigh[1])  

sixtyMinLow = showAll and showInitialBalance and lowRes ? label.new(bar_index, lowRes, text=display_value ? ("                        1HrL"  + " " + tostring(nround(lowRes))) : "1h-Low",  style= label.style_none, size= size.normal) : na  

label.set_textcolor(sixtyMinLow,textcolor=color.aqua)  
label.delete(sixtyMinLow[1])  

fill(p1, p2, color=color.aqua, transp=95)

Upvotes: 2

Related Questions