如何获取特定日期的条形索引

How to get bar index on specific date

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

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

提前致谢

时间戳函数将 return 指定日期和时间的 UNIX 时间。

如果以毫秒为单位的时间超过 1 月 3 日,则抓住低点。 对于盘中,在时间戳函数中指定分钟数。

//@version=4
study("low on specific date")

specificDate = time >= timestamp(2019, 1, 3, 00, 00)

var float lowOnDate= na
if specificDate and not specificDate[1]
    lowOnDate := low
plot(lowOnDate)

假设您想要获取 6 月 30 日凌晨 3 点 GMT+8 的 1 小时时间范围内的蜡烛图数据

x1 = (time - timestamp("GMT+8",2021,06,30,03,00,00))/3600000

candleHigh = high[x1]

如果您在不同的 TF 中,只需将其转换为毫秒

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

  //@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