获得X位置蜡烛的高位

问题描述

我正在尝试根据某些条件来提高x位置蜡烛的价格。下面是我的代码。但是我收到错误消息“不能使用可变变量作为安全功能的参数”。有什么方法可以实现?

i = 0
if(condition1)
    i := 7
else if(condition2)
    i := 8
else if(condition2)
    i := 9
x = security(syminfo.tickerid,'60',high[i])
plot(x)

解决方法

您只需要使用非可变变量,例如:

i = condition1 ? 7 : condition2 ? 8 : condition3 ? 9 : 0
h = high[i]
x = security(syminfo.tickerid,'60',high[i])
plot(x)