-1

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...

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
cody
  • 6,389
  • 15
  • 52
  • 77

2 Answers2

5

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)
PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
  • Sry for the late reply, thanks a lot for your help! I'm convinced that does the job. But I just got an error "Could not find function or function reference line.new"... do you have any idea where this comes from? – cody Feb 23 '20 at 20:13
  • Ahh, got it... my script was for version 3 ...changed it to 4 and now it works :-) Thank you :-) – cody Feb 23 '20 at 20:21
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.

enter image description here

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

carloswm85
  • 1,396
  • 13
  • 23