【发布时间】:2021-04-17 15:44:10
【问题描述】:
我使用 plot() 函数编写了一个脚本来绘制盘前高点,但我想使用 line.new() 函数在图表上制作更清晰的指标。
这是我使用 plot() 的原始指标。
//@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")
现在我一直在用这样的 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)
我已经使用任意值 bar_index[20] 来测试 x1,并且该指标似乎工作正常,但我希望能够获得盘前高蜡烛的 bar_index。
有没有办法获取变量 'day_high' 的 bar_index 值,因为它是我想要开始生产线的蜡烛?
我尝试过使用 barsince,但它不起作用,我被卡住了。我应该改用 xloc 吗?
谢谢!
【问题讨论】:
标签: pine-script