Not sure if that's exactly what you're looking for? https://www.tradingview.com/script/cgHGBnH9-Naked-Intrabar-POC/
You can first define number of bars from last bar that you want to check for open/close. At the last bar you can run for loop for that many bars. At each iteration of loop you can keep calculating the maxiumum high and minimum lows that occured after the selected bar. If open/close is not breaching them, then draw the line. Example below
//@version=5
indicator(title="Unbreached High/Low by Rohit", shorttitle="URR",overlay=true,max_lines_count=500,max_labels_count=500,max_bars_back=1500)
var maxbars = input.int(20,title="max bars")
var maxhigh=high
var minlow=low
if barstate.islast
var openclosearray=array.new_float()
maxhigh:=high
minlow:=low
for i = 1 to maxbars
if open[i]<close[i] and open[i]<minlow
line.new(bar_index-i,open[i],bar_index,open[i],extend=extend.right)
if open[i]>close[i] and open[i]>maxhigh
line.new(bar_index-i,open[i],bar_index,open[i],extend=extend.right)
if close[i]<open[i] and close[i]<minlow
line.new(bar_index-i,close[i],bar_index,close[i],extend=extend.right)
if close[i]>open[i] and close[i]>maxhigh
line.new(bar_index-i,close[i],bar_index,close[i],extend=extend.right)
if low[i]<minlow
minlow:=low[i]
if high[i]>maxhigh
maxhigh:=high[i]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.