在 tradingview 的 pine 脚本中的月份的第一个柱上绘制垂直线

Draw vertical line at the first bar of the month in tradingview's pine script

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

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

这是对 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)

我碰巧找到了解决方法,但使用的是 bgcolor。

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

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

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