Pine script 需要使用line.new获得x1值的帮助吗

Pine script 需要使用line.new获得x1值的帮助吗,pine-script,Pine Script,我使用plot()函数编写了一个脚本来绘制市场前高点,但我想使用line.new()函数在图表上创建一个更清晰的指示器 这是我的原始指示器,绘图()正在工作 //@version=4 study("PreMarket High", shorttitle="preH", overlay=true) // Get the premarket high value t = time("1440", "0000-0930&quo

我使用plot()函数编写了一个脚本来绘制市场前高点,但我想使用line.new()函数在图表上创建一个更清晰的指示器

这是我的原始指示器,绘图()正在工作

//@version=4

study("PreMarket High", shorttitle="preH", overlay=true)

// Get the premarket high value 
t = time("1440", "0000-0930") 

is_first = na(t[1]) and not na(t) or t[1] < t
ending_hour = input(defval=9, title="Ending Hour", type=input.integer)
ending_minute = input(defval=30, title="Ending Minute", type=input.integer)

day_high = float(na)

if is_first and barstate.isnew and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    day_high := high
   
else
    day_high := day_high[1]
   
if high > day_high and ((hour < ending_hour or hour >= 16) and hour < 16 or hour == ending_hour and minute < ending_minute)
    day_high := high
    day_high

// Draw premarket high on chart
plot(day_high, style=plot.style_line, color=#ffeb3b, linewidth=1, trackprice = true, offset = -9999, title="PreHigh")
/@version=4
研究(“上市前高”,shorttitle=“preH”,overlay=true)
//获得上市前的高价值
t=时间(“1440”、“0000-0930”)
是_first=na(t[1]),而不是na(t)或t[1]=16或hour==ending_hour and minute天高和((小时<结束小时或小时>=16)和小时<16或小时==结束小时和分钟<结束分钟)
天高:=天高
天高
//在图表上画出市场前的高点
绘图(日高,样式=绘图。样式线,颜色=#ffeb3b,线宽=1,trackprice=真,偏移量=-9999,title=“PreHigh”)
现在我一直在使用line.new函数进行测试

//@version=4

study("PreMarket High", shorttitle="preH", overlay=true)

// Get the premarket high value 
t = time("1440", "0000-0930") 

is_first = na(t[1]) and not na(t) or t[1] < t
ending_hour = input(defval=9, title="Ending Hour", type=input.integer)
ending_minute = input(defval=30, title="Ending Minute", type=input.integer)

day_high = float(na)

if is_first and barstate.isnew and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    day_high := high
   
else
    day_high := day_high[1]
   
if high > day_high and ((hour < ending_hour or hour >= 16) and hour < 16 or hour == ending_hour and minute < ending_minute)
    day_high := high
    day_high

// Draw premarket high on chart

var line l = line.new(bar_index[20], day_high, bar_index, day_high, color=color.lime, width=2, extend=extend.right)
line.set_x1(l, bar_index[20])
line.set_x2(l, bar_index)
line.set_y1(l, day_high)
line.set_y2(l, day_high)
/@version=4
研究(“上市前高”,shorttitle=“preH”,overlay=true)
//获得上市前的高价值
t=时间(“1440”、“0000-0930”)
是_first=na(t[1]),而不是na(t)或t[1]=16或hour==ending_hour and minute天高和((小时<结束小时或小时>=16)和小时<16或小时==结束小时和分钟<结束分钟)
天高:=天高
天高
//在图表上画出市场前的高点
var line l=line.new(条形图索引[20],日高,条形图索引,日高,颜色=color.lime,宽度=2,延伸=extend.right)
行。设置_x1(l,条形索引[20])
行集合×2(l,条形索引)
行。设置为1(l,日高)
行。设置为y2(l,日高)
我使用了x1的任意bar_指数[20]值进行测试,指示器似乎在工作,但我希望能够获得上市前高烛光的bar_指数

有没有一种方法可以得到变量“day\u high”的bar\u索引值,因为它是我想开始这行的蜡烛

我试过使用barssince,但它不起作用,我被卡住了。我应该改用xloc吗


谢谢

使用timestamp函数计算出来

// Today's Session Start timestamp
y = year(timenow)
m = month(timenow)
d = dayofmonth(timenow)

// Start & End time for Today
start = timestamp(y, m, d, 07, 00)
end = start + 43200000

var line l_high = line.new(start, day_high, end, day_high, color=color.yellow, width=1, xloc=xloc.bar_time)
line.set_x1(l_high, start)
line.set_x2(l_high, end)
line.set_y1(l_high, day_high)
line.set_y2(l_high, day_high)