1

I'm trying to plot something from the first bar of the second last session that is loaded on the graph.

Since the bar count per session varies and for example a monday can be preceded by a sunday, friday or thursday, and not every session covers the same amount of time, I find it hard to pinpoint the session that is preceding the last session.

I want an indicator that works on multiple tickers.

Tried calculating the bar_index by subtracting it from last_bar_index but when the second last session starts you don't know yet how many bars there will be in the last session.

frik
  • 11
  • 1

1 Answers1

0

Try session.isfirstbar and session.islastbar
You can also use session.isfirstbar_regular and session.islastbar_regular

Something like this:

//@version=5
indicator('session', overlay = true)

plotshape(
  session.isfirstbar,
  text       = 'isfirstbar',
  color      = color.gray,
  textcolor  = color.white,
  style      = shape.labelup,
  size       = size.small,
  location   = location.belowbar)
plotshape(
  session.islastbar,
  text       = 'islastbar',
  color      = color.gray,
  textcolor  = color.white,
  style      = shape.labeldown,
  size       = size.small,
  location   = location.abovebar)
Gu5tavo71
  • 706
  • 1
  • 4
  • 11
  • Thanks for the response! I want this to only show on 1 session; not the last session on the graph but the second last. Any suggestions for that part? – frik Jul 09 '23 at 10:43