0

I want to create an indicator that draws a horizontal line showing the daily last closing price and the line auto adjusts daily.

I'm expecting something like these:

Daily Last Close Line:

Daily Last Close Line

Daily Last Close visible on lower timeframe:

Daily Last Close visible on lower timeframe

Anton Menshov
  • 2,266
  • 14
  • 34
  • 55
Olorin
  • 1

1 Answers1

0

You should try this :

//@version=5
indicator("Yesterday Close", overlay=true)

indexHighTF = barstate.isrealtime ? 1 : 0
indexCurrTF = barstate.isrealtime ? 0 : 1
yesterday_close = request.security(syminfo.tickerid, "1D", 
close[indexHighTF])[indexCurrTF]
daily_line = line.new(bar_index, yesterday_close , bar_index-1, yesterday_close, extend= extend.both, color=color.yellow)
line.delete(daily_line[1])

It is based on the pinescript manual , see here : https://www.tradingview.com/pine-script-reference/v5/#fun_request{dot}security

G.Lebret
  • 2,826
  • 2
  • 16
  • 27