如何将活动时间范围用作条件中的变量?

How to use the active time frame as a variable in a condition?

我想为 tradingview 编写一个指标,它应该根据活动时间范围在特定水平上绘制一条垂直线,例如在 5 分钟图上,指标应该在与 60 分钟图上不同的水平上画线。

我已经试过了"resolution"。这是代码片段:

x = (resolution == "5") ? 10 : (resolution == "60") ? 20 : 30

plot(x)

因此,如果图表在 5 分钟时间范围内,则应在级别 10 处绘制一条线,在 60 分钟时间范围内在级别 20 处绘制一条线,在所有其他时间范围内在级别 30 处绘制一条线.

但是总是在30级抽奖,所以代码一定是错误的。我已经研究过 "resolution" 是 "input" 函数的常数,所以它似乎不能在这个函数之外使用。

所以我的问题是:正确的代码是什么?谢谢!

我自己找到了答案:"period"

所以我的示例代码必须如下所示:

x = (period == '5') ? 10 : (period == '60') ? 20 : 30

plot(x)

对于 Pine Script v4,您要查找的变量称为 timeframe.period

例如'60' - 60 分钟,'D' - 每天,'W' - 每周,'M' - 每月,'5D' - 5 天,'12M' - 一年,'3M' - 一年季度

Pine reference