th3r1singking
th3r1singking

Reputation: 131

How do you draw a vertical line ever 4 hours?

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

Answers (1)

vitruvius
vitruvius

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)

enter image description here

Upvotes: 1

Related Questions