需要帮助使用 line.new 获取 x1 值

问题描述

我编写了一个脚本来使用 plot() 函数绘制盘前高点,但我想使用 line.new() 函数在图表上制作一个更清晰的指标。

这是我使用 plot() 工作的原始指标。

#version 450 core

layout(triangles,invocations = 6) in;
layout(triangle_strip,max_vertices = 3) out;

void main()
{
    for(int i = 0; i < 3; i++) 
    { 
        gl_Layer = gl_InvocationID ;
        gl_Position = gl_in[i].gl_Position + vec4(vec3(gl_InvocationID)/5,1);
        EmitVertex();
    }
    EndPrimitive();
} 

现在我一直在使用 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")

我对 x1 使用了任意值 bar_index[20] 进行测试,该指标似乎有效,但我希望能够获得上市前最高价蜡烛的 bar_index。

有没有办法获取变量“day_high”的 bar_index 值,因为它是我想从中开始的蜡烛?

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

谢谢!

解决方法

使用时间戳函数计算出来的。

// 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,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)