pine-script - 在 TradingView Pine Script 上获取特定柱的日期
问题描述
我正在编写一个指标,我需要将它“锚定”到某个感兴趣的日期。基本上是一个锚定的 VWAP,我试图在其中自动找到容易“锚定”指标的感兴趣区域。
基本上,我试图在回溯期内获得最高和最低值(在本例中为 365,并尝试“访问”该条的日期,因此我可以将 t(时间)初始化为从该条开始。
我可以通过单独的输入来做到这一点,但不确定如何通过访问之前栏的时间/日期信息来做到这一点。谢谢!
h1 = highest(high, 365)
time(h1) (?) *this is wrong*
start = t == time
解决方案
您将需要highestbars()
它,它返回最高点的偏移量。它返回一个负值,所以我们需要改变它的符号:
//@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)