[Pine script] 我想在每个工作日的特定时间(例如 11:30 GMT 和 15:30 GMT)绘制两条垂直线(虚线)。但我无法做我想做的事。它不会在超过一定时间后绘制线条,也不会绘制虚线。下面是我尝试过的代码。
请帮忙..
//@version=5
indicator('Timegap', overlay=true, max_lines_count=500, max_bars_back=4999)
weekday = (dayofweek != dayofweek.saturday and dayofweek != dayofweek.sunday)
t1 = timestamp("GMT", year, month, dayofmonth, 11, 30, 00)
t2 = timestamp("GMT", year, month, dayofmonth, 15, 30, 00)
timeIsOk = (time >= t1) and (time <= t2)
if timeIsOk and weekday
line.new(t1, low, t1, high, xloc.bar_time, extend.both, color.rgb(255, 255, 0), line.style_dashed, 1)
line.new(t2, low, t2, high, xloc.bar_time, extend.both, color.rgb(255, 255, 0), line.style_dashed, 1)
您的代码有效,但您应该更换您的条件:
timeIsOk = (time >= t1) and (time <= t2)
由
timeIsOk = (time == t1) or (time == t2)
我在下面提供了应该适合您的代码,方法是调整 GMT 时区(我对印度使用 GMT+5:30,上午 9:15 到下午 15:30),然后在计算 t1 和 t2 时定义您所在位置的确切时间
//@版本=5 指标('会话线',overlay=true,max_lines_count=500,max_bars_back=4999)
t1 = 时间戳("GMT+5:30", 年, 月, 月日, 09, 15, 00) t2 = 时间戳("GMT+5:30", 年, 月, 月日, 15, 30, 00)
如果时间==t1 线。新(t1,低,t1,高,xloc.bar_time,extend.both,color.rgb(255,255,0),line.style_dashed,1)
如果时间==t2 线。 New(t2, low, t2, high, xloc.bar_time, 延长。两者, color.rgb(0, 255, 255), line.style_dashed, 1)