pine-script - 如何在 Pinescript 中为系列字符串输入添加复选框选项
问题描述
我想弄清楚如何允许以交叉样式格式绘制系列字符串,但作为复选框功能。不幸的是,我找不到任何提供此类用例示例的资源,所以让我们创建一个。
首先,这是一个工作标准输入字符串的示例,它在绘制时可以作为选项启用。
testfunction = sma(rsi, 7)
show_testfunction = input(false, "Show testfunction", type=input.bool)
plot(show_testfunction ? testfunction : na, "Test Function", color.white, transp=30, linewidth=2)
但是,当想要为系列字符串使用相同类型的复选框选项时,如果它允许style=plot.cross_style
,我会遇到以下错误:
Syntax error at input 'series'.
我编写以下代码来解决问题:
Testfunctionseries = sma (rsi, 3)
show_testfunctionseries = input(false, "Show series testfunction", type=input.bool)
plot(show_testfunctionseries ? series=testfunctionseries : na, "Test Function Series With Cross Style", style=plot.style_cross, color.white, transp=30, linewidth=2)
以下是在没有复选框选项的情况下绘制同一行代码的工作方式:
plot(series=testfunctionseries, style=plot.style_cross, color=color.purple, title="Testfunction Series Cross", transp=70, linewidth=2)
另外,我希望这个帖子对不了解这些类型功能的 pine 开发人员有所帮助。
解决方案
您错误地使用了参数名称series=
。应该将整个表达式show_testfunctionseries ? testfunctionseries : na
传递给series=
您的代码才能工作。以下是代码应该如何寻找它以正确编译:
//@version=4
study("My Script")
rsi = rsi(close, 14)
testfunctionseries = sma(rsi, 3)
show_testfunctionseries = input(false, "Show series testfunction", type=input.bool)
plot(series = show_testfunctionseries ? testfunctionseries : na, title = "Test Function Series With Cross Style", style=plot.style_cross, color=color.white, transp=30, linewidth=2)
请注意,我还在那里添加了title=
和color=
。一旦您使用关键字来引用参数(在您的情况下为series=
),您就不能再在同一个函数调用中使用位置参数,您必须使用关键字来编译代码。只有当所有位置参数都在第一个关键字参数之前时,您才能同时使用位置参数和关键字参数:
plot(show_testfunctionseries ? testfunctionseries : na, "Test Function Series With Cross Style", style=plot.style_cross, color=color.white, transp=30, linewidth=2)
推荐阅读
- r - 将属性(性别)添加到边缘列表中的顶点
- python - 获取 Pandas DataFrame 中列括号之间的文本
- r - 有没有办法根据它们在 R 中的值来选择和按比例排列行?
- html - 路径中带有用户名的网站,例如:website.com/username
- python - 正则表达式不适用于 Python(旧版本)
- python - 如何获取当前用户名作为相关字段odoo
- dax - DAX 期初余额按天计算在月份和年份上不正确
- ios - Xcode 11.6 (11E708) 中的 Interface Builder 以 XML 格式显示故事板
- java - ConsumerRecord在apache spring kafka中包含双引号“”xxxxxxxxxxxxxx“”内的键值
- javascript - 如何忽略谷歌浏览器中的这个错误?