我希望简单地允许在绘图上进行变量替换,但我不断收到错误。
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
有什么想法吗? 谢谢 斯科特
最佳答案
I'm looking to simply allow a variable replacement on the plot, but I keep getting an error.
cannot call with arguments error使用该代码不断出现这种情况是因为 plot()
的参数之一不是可接受的格式。
如果我们看 the plot()
function ,我们看到它采用以下值,每个值都有自己的类型:
系列
(系列)标题
(常量字符串)颜色
(颜色)线宽
(整数)样式
(整数)transp
(整数)trackprice
( bool )histbase
( float )偏移量
(整数)加入
( bool )可编辑
(const bool)show_last
(常量整数)
现在,您的代码如何调用 plot()
:
cr20style = cr20_50up ? 1 : 2
plot(d1, title='%K SMA20', color=cr20_50_color, transp=0,style=cr20style)
问题是,这里我们将 style
参数设置为一个序列,而不是一个整数。这是因为 cr20style
有条件地设置为 1
或 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)
关于pine-script - 在绘图上使用样式变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50175998/