如何根据特定的收盘蜡烛和时间帧绘制水平线



我希望根据特定时间和特定时间框架在交易视图(松树脚本(中绘制一条水平线。 例如,我想在 1600(美国东部标准时间下午 4 点(时间帧的 5m 蜡烛收盘价上绘制一条 hline。

我尝试了很多,但似乎无法弄清楚如何在松树脚本中具有历史价值。 这意味着您希望从下午 4 点开始绘制一条线,并在当天剩余时间和第二天开始将其显示在图表上。 使用 PS 中的函数 show_last = 1 来做到这一点很简单,但我无法弄清楚如何计算下午 5 点 4m 的收盘蜡烛?

我的一些代码不能完全工作

//@version=3
study("4pm_Line")
highTimeFrame = input("5", type = resolution)
sessSpec = input("1600-0930", type = session)
is_newbar(res, sess) =>
t = time(res, sess)
na(t[1]) and not na(t) or t[1] < t
newbar = is_newbar("5", sessSpec)
s2 = na
s2 := newbar ? close : nz(s2[1])
plot(s2, style=line, linewidth=1, color=lime, trackprice = true, 
show_last = 1)

绘图的线是关闭的,我不知道它是如何获得其值的。

实际上很容易。 我为你创建了一个脚本

//@version=4
//@author=lucemanb
study("Closing Time", overlay=true)
period  = input("5", "Period", input.resolution)
session = input("1500-1600", "Session", input.session)
float data = na
data := data[1]
getData() =>
float d = na
inSession = time(period, session)
if not inSession and inSession[1]
d := close[1]
d
d = security(syminfo.tickerid, period, getData())
if not na(d)
data := d
plot(data, "Line", color.yellow, 2, plot.style_line, true, show_last=1)

我们基本上将找到的值存储在我们在每根蜡烛上访问的变量中 我希望这有所帮助。享受