获取 TradingView Pine Script 上特定柱的日期

Get the date of a specific bar on TradingView Pine Script

我正在写一个指标,我需要 "anchor" 它到某个感兴趣的日期。基本上是一个固定的 VWAP,我试图在其中自动找到 "anchor" 指标感兴趣的简单区域。

基本上,我试图获得回顾期内的最高值和最低值(在此示例中为 365,并尝试 "access" 该柱的日期,因此我可以初始化 t(时间) 从那个小节开始。

我可以用单独的输入来做到这一点,但不确定如何通过访问以前柱的 time/date 信息来做到这一点。谢谢!

h1 = highest(high, 365)
time(h1) (?)  *this is wrong* 
start = t == time 

为此你需要 highestbars(),returns 最高点的偏移量。它returns是一个负值,所以我们需要改变它的符号:

//@version=4
study("")
// Get bar index of highest high.
highIndex = -highestbars(high, 365)
// Get time at highest high.
t = time[highIndex]
plot(highIndex, "Index of highest high")
// Plot day of the month of highest high's bar.
plot(dayofmonth(t), "Day of the month", color.red)