【问题标题】:Pine Script - How to get the UNIX time value of a variablePine Script - 如何获取变量的 UNIX 时间值
【发布时间】:2021-09-23 04:49:22
【问题描述】:

我有以下脚本获取上个月的最低点,并在该值处绘制一条线:

//@version=4
study(title="Low Lines", overlay=true)

pmonlow = security(syminfo.tickerid, 'M', low[1])

lowLine = line.new(x1=bar_index[1], y1=pmonlow ,x2=bar_index, y2=pmonlow, extend=extend.right,
         color=color.red, width=2)

lowLine 在前一个月低点的值处绘制一条线,向后一柱。

我想将线的起点放在实际出现低点的日期。

是否可以获取“pmonlow”变量的 UNIX 时间值,以便我可以使用 line.setxloc?

非常感谢,

【问题讨论】:

    标签: pine-script tradingview-api


    【解决方案1】:

    由于我们需要获取图表时间帧的低点时间戳,而不是较高时间帧的时间戳,因此我们需要在低点发生时获取低点,因为无法使用安全调用来检索它。您只能通过安全获取每月的开放时间。

    new_month = change(time("M")) != 0
    
    var float monthly_low = na
    var int monthly_low_time = na
    
    if new_month
        monthly_low := low
        monthly_low_time := time
    else if low < monthly_low
        monthly_low := low
        monthly_low_time := time
        
    var line monthly_low_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, xloc = xloc.bar_time, color = color.red)
    
    if barstate.islast
        line.set_xy1(monthly_low_line, x = monthly_low_time, y = monthly_low)
        line.set_xy2(monthly_low_line, x = time, y = monthly_low)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2022-01-07
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多