pine-script - 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)
不知何故,这可能会失败。
有人知道语法有什么问题吗?
谢谢
解决方案
您需要在为其分配值之前启动 VOLA_INDEX。
字符串 VOLA_INDEX = ""
推荐阅读
- python - redis如何使不同哈希中的密钥过期
- reactjs - 如何使用 Django-rest 和 React js 对用户进行身份验证
- google-sheets - 按周范围和行值查询数据
- json - 如何从 HTTP 响应正文中读取错误
- javascript - 在自定义错误页面中无法从 getInitialProps 返回道具
- java - 如何验证 List 类型的 @RequestParam 的大小
- python-2.7 - 在机器人测试中调用 python 关键字时得到不正确的输出
- javascript - 如何在 litelement 组件中显示对象
- haskell - 如何检查列表的最后一个元素是否是另一个列表的成员?
- autohotkey - 在按键上播放音频