Pine Script 中的动态索引

Dynamic indexing in Pine Script

我正在尝试确定开盘区间(交易的前 30 分钟)的高点和低点。我在 5 分钟图表上执行此操作,因此 tz 计算自一天开始以来的五分钟柱数。 我希望结果(高点和低点)在开盘区间后保持不变,但事实并非如此。我认为这是与 this.

类似的问题
 //@version=4
study("opening", shorttitle = 'op', max_bars_back=500, overlay = false)
ttime=timestamp(2021, 01, 14, 09, 30,00)
t=time

ttz=int((time-ttime)/300000)
tz=ttz>6? ttz :6
offser(src, length) =>
    len=length>=0 ? src[length] : src[0]

highe=offser(highest(6),tz)//iff(tz>6,max(high[tz],high[tz-1],high[tz-2],high[tz-3],high[tz-4],high[tz-5],high[tz-6]),0)
lowe=offser(lowest(6),tz)  //iff(tz>6,min(low[tz],low[tz-1],low[tz-2],low[tz-3],low[tz-4],low[tz-5],low[tz-6]),0)
scr_label=tostring(tz)
lab_l = label.new(
          bar_index, 0, scr_label, 
          color=color.gray, 
          textcolor=color.black, 
          style =  label.style_labeldown,
          yloc = yloc.price)
label.set_size(lab_l, size.small)
plot(lowe, color=color.red)
plot(highe, color=color.blue)
plot(0, transp = 100)

我尝试在注释掉的部分用 highlow 做同样的事情,但同样不一致。 offser 只是一个重新定义的 offset.

如果我没有正确理解你的问题,那么最好这样做

//@version=4
study("Help (opening)", overlay=true)

time_int = input("0930-1000", "Time interval", input.session) //set the opening range you are interested in

in_time_int = time(timeframe.period, time_int)

var highe = 0.0
var lowe  = 10e10
if in_time_int
    if not in_time_int[1]
        highe := high
        lowe  := low
    else
        highe := max(high, highe)
        lowe  := min(low, lowe)

plot(not in_time_int ? highe : na, title="High", color=color.blue, linewidth=2, style=plot.style_linebr)
plot(not in_time_int ? lowe  : na, title="Low",  color=color.red,  linewidth=2, style=plot.style_linebr)