Pine script line.new绘制2条线,而不是1条线

Pine script line.new绘制2条线,而不是1条线,pine-script,Pine Script,考虑一下这个简单的Pine脚本 //@version=4 level1 = 3050 study("FutureLine", overlay=true) line.new(timestamp(year,month,dayofmonth,08,30), level1, timestamp(year,month,dayofmonth,13,30), level1, xloc=xloc.bar_time) 应该在最后一个酒吧的那天从08:30到13:30划一条线。 然而,它在最后一个酒吧的当天和之前

考虑一下这个简单的Pine脚本

//@version=4
level1 = 3050
study("FutureLine", overlay=true)
line.new(timestamp(year,month,dayofmonth,08,30), level1, timestamp(year,month,dayofmonth,13,30), level1, xloc=xloc.bar_time)
应该在最后一个酒吧的那天从08:30到13:30划一条线。
然而,它在最后一个酒吧的当天和之前一天画出了这条线。
知道为什么吗

示例为15分钟SPX棒

是脚本运行所在栏的年份<代码>年份(timenow)是当前年份。所发生的事情是,你用每个酒吧的年、月、日在每个酒吧上画了一条线,垃圾收集只保留最后一条。只有2个显示,但还有更多,重叠

此代码仅在数据集的第一个栏上创建一行,然后仅在脚本到达最后一个栏时对其进行修改,因此它使用该栏的日期:

//@version=4
study("FutureLine", overlay=true)
level1 = 3050
start = timestamp(year,month,dayofmonth,08,30)
stop  = timestamp(year,month,dayofmonth,13,30)
var line ln = line.new(start, level1, stop, level1, xloc=xloc.bar_time)
if barstate.islast
    line.set_x1(ln, start)
    line.set_x2(ln, stop)
修改现有行比删除并创建新行更有效,而删除并创建新行只需要保留最后一行