【问题标题】:Draw vertical line at the first bar of the month in tradingview's pine script在 tradingview pine 脚本中在当月的第一个柱上绘制垂直线
【发布时间】:2020-02-15 21:41:45
【问题描述】:

我想在每个月的第一条柱(对于日线图和周线图)或一年(对于月线图)绘制一条垂直虚线。 我怎样才能做到这一点?我不知道如何获取那些条形索引。

补充: 我读了 this post "line.new" 限制每个指标最多 54 行。但是当以直方图样式使用绘图功能时(=仅绘制单个垂直直方图条),我无法绘制虚线......我更喜欢用虚线的解决方案......

【问题讨论】:

    标签: plot line draw pine-script


    【解决方案1】:

    这是对midtownsk8rguy的代码here的改编:

    //@version=4
    study("Periodic Vline", overlay=true)
    p = timeframe.ismonthly ? "12M" : "M"
    vline(BarIndex, Color, LineStyle, LineWidth) =>
        return = line.new(BarIndex, low - tr, BarIndex, high + tr, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)
    if change(time(p))
        vline(bar_index, #FF800080, line.style_dashed, 1)
    

    【讨论】:

    • 抱歉回复晚了,非常感谢您的帮助!我确信它可以完成这项工作。但我刚刚收到一个错误“找不到函数或函数参考 line.new”...你知道这是从哪里来的吗?
    • 啊,明白了...我的脚本是第 3 版的...将其更改为第 4 版,现在可以使用了 :-) 谢谢 :-)
    【解决方案2】:

    我碰巧找到了解决方案,但使用 bgcolor。

    targetTimeRed = timestamp(year, month, dayofweek.sunday, 00, 00, 00)
    bgcolor(targetTimeRed == time ? color.red : na, transp=70, editable=false)
    

    你会在每月的第一天得到它。

    虽然我不确定它是否应该这样工作......但这就是它的作用。

    【讨论】:

      猜你喜欢
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多