首页 > 解决方案 > tradingview pine 脚本中的 if 语句问题

问题描述

我尝试在我的 tradingview pine 脚本中添加一个简化的 switch 语句:

//@version=3
study("my_test",shorttitle="bands",overlay=true)

string VOLA_INDEX = ""

if (ticker == "USOIL")
   VOLA_INDEX := "OVX"
if (ticker == "GOLD")
   VOLA_INDEX := "GVZ"
if (ticker == "GER30")
   VOLA_INDEX := "DV1X"   


src = security(ticker,"D",close[1])
vola = security(VOLA_INDEX,"D",close[1])

bands1 = src * vola/100 * sqrt(0.00273972602) 
bands3 = src * vola/100 * sqrt(0.00821917808) 

upper1 = src + bands1
lower1 = src - bands1

plot( src, title="mean", color=black, style=linebr, linewidth=2, transp=100, trackprice = true,offset=-9999)
plot( upper1, title="upper", color=blue, style=linebr, linewidth=2, transp=40, trackprice = true,offset=-9999)
plot( lower1, title="lower", color=blue, style=linebr, linewidth=2, transp=40, trackprice = true,offset=-9999)

不知何故,这可能会失败。

有人知道语法有什么问题吗?

谢谢

标签: pine-script

解决方案


您需要在为其分配值之前启动 VOLA_INDEX。

字符串 VOLA_INDEX = ""


推荐阅读