pine-script - 在绘图上使用样式变量
问题描述
我希望简单地允许在情节上进行变量替换,但我不断收到错误消息。
cr20_50up = cross(d1,d9) and d1 > d9
cr20style = cr20_50up ? 1 : 2
plot(d1, title='%K SMA20', color=cr20_50_color, transp=0,style=cr20style)
但它不起作用。
line 54: Cannot call `plot` with arguments (series, title=literal string, color=series[color], transp=literal integer, style=series[integer]); available overloads: plot(series, const string, series[color], integer, integer, bool, integer, float, series[integer], bool, series, const bool, const integer, string) => plot; plot(fun_arg__<arg_series_type>, const string, fun_arg__<arg_color_type>, integer, integer, bool, integer, float, series[integer], bool, series, const bool, const integer, string) => plot
有什么想法吗?谢谢斯科特
解决方案
我希望简单地允许在情节上进行变量替换,但我不断收到错误消息。
由于's 参数之一不是可接受的格式,因此您不断收到该代码的cannot call with arguments 错误。plot()
如果我们查看function ,我们会plot()
看到它采用以下值,每个值都有自己的类型:
series
(系列)title
(常量字符串)color
(颜色)linewidth
(整数)style
(整数)transp
(整数)trackprice
(布尔)histbase
(漂浮)offset
(整数)join
(布尔)editable
(常量布尔)show_last
(常量整数)
现在这是您的代码调用方式plot()
:
cr20style = cr20_50up ? 1 : 2
plot(d1, title='%K SMA20', color=cr20_50_color, transp=0,style=cr20style)
问题是这里我们将style
参数设置为不是整数,而是一个系列。那是因为cr20style
有条件地设置为1
or 2
。虽然它确实是一系列整数,但系列仍然不同于 TradingView Pine 中的常规整数。
不幸的是,这也意味着以下内容:您不能plot()
有条件地设置函数的样式。
对于您的代码,最好的解决方法可能是创建两个图,每个图都有自己的风格。然后禁用基于cr20style
. 例如:
plot(cr20style == 1 ? d1 : na, title='%K SMA20',
color=cr20_50_color, transp=0,style=1)
plot(cr20style == 2 ? d1 : na, title='%K SMA20',
color=cr20_50_color, transp=0,style=2)
推荐阅读
- hazelcast - Hazelcast 管理中心队列统计
- tensorflow-serving - 使用 Tensorflow Serving 为多个模型提供服务时,Prometheus 指标上的标签
- c# - Unity sprite 翻转超出相机范围
- r - 同一张图中的两个馅饼 - Highcharter
- html - 在 XSLT 中按总和分组
- reactjs - 客户端通过服务器重定向:CORS 错误
- laravel - 多个文件和图像没有在没有循环的情况下在 laravel 中上传
- sql - 每组最多加入
- sql - 在 Oracle SQL 中将日期转换为特定格式
- javascript - 小数字的科学记数法