Reputation: 131
I'm working on a strategy and I need to draw a vertical line every 4 hours. How would you draw a vertical line every 4 hours on Trading view?
Upvotes: 0
Views: 386
Reputation: 21121
You can use the vline() function.
//@version=5
indicator("My Script", overlay=true)
f_resInMinutes() =>
_resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
vline(BarIndex, Color, LineStyle, LineWidth) =>
line.new(BarIndex, low - ta.tr, BarIndex, high + ta.tr, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=true)
bars_4h = 240 / f_resInMinutes()
if((bar_index % bars_4h) == 0)
vline(bar_index, #FF8000ff, line.style_solid, 1)
Upvotes: 1