简体   繁体   中英

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

I'd like to draw a vertical dashed line at every first bar of a month (for daily and weekly charts) or a year (for monthly charts). How can I do that? I don't know how to get those bar indexes.

Addition: I read in this post that "line.new" has a restriction to 54 lines max per indicator. But when using the plot function in histogram style (=plot only single vertical histogram bars), I cannot plot dashed lines... and I prefer a solution with dashed lines...

This is an adaptation of midtownsk8rguy's code 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)

I happened to find a solution to this, but using bgcolor.

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

You get that at the first day of the month.

在此处输入图片说明

Though I'm not really sure if that's how it should work... But that's what it does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM