Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bar index on specific date

I am new to pine script. I want to compare the prices on 2 specific date.

But how would I get the bar_index on a particular date?

Thanks in advance

like image 716
Max Cheung Avatar asked Oct 27 '25 07:10

Max Cheung


1 Answers

Get bar index at specific date across all time frames.

  //@version=5

  anchorTime = input.time(timestamp("20 May 2022 15:00 -0500"), "Date")

  anchorBarIndex = (time - anchorTime) / (1000 * timeframe.in_seconds(timeframe.period))

  anchorBarsBack = bar_index - anchorBarIndex 
like image 189
Anthony Raimondo Avatar answered Oct 29 '25 08:10

Anthony Raimondo