【问题标题】:Need help using line.new to get x1 value需要帮助使用 line.new 来获取 x1 值
【发布时间】: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


    【解决方案1】:

    使用时间戳功能弄清楚了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2019-12-31
      • 2012-05-10
      • 2020-02-09
      相关资源
      最近更新 更多