如何获取特定日期的柱状图索引

Max*_*ung 4 pine-script pine-script-v4

我是松树脚本的新手。我想比较 2 个特定日期的价格。

但是我如何获得特定日期的 bar_index 呢?

提前致谢

Ant*_*ndo 5

获取所有时间范围内特定日期的柱形指数。

  //@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 
Run Code Online (Sandbox Code Playgroud)