Pine script 在绘图上使用样式变量

Pine script 在绘图上使用样式变量,pine-script,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 str

我只是想简单地允许在绘图上替换变量,但我一直得到一个错误

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
第54行:无法使用参数调用'plot'(series,title=literal字符串,color=series[color],transp=literal整数,style=series[integer]);可用重载:绘图(系列、常量字符串、系列[颜色]、整数、整数、布尔、整数、浮点、系列[整数]、布尔、系列、常量布尔、常量整数、字符串)=>绘图;绘图(fun_arg_uuuu,常量字符串,fun_arg_uuu,整数,整数,布尔,整数,浮点,系列[integer],布尔,系列,常量布尔,常量整数,字符串)=>绘图
有IDE吗? 谢谢 斯科特

我只是想简单地允许在绘图上替换变量,但我一直得到一个错误

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)
由于
plot()
的一个参数不是可接受的格式,因此您在该代码中不断遇到的错误

如果我们看一下,我们会发现它采用以下值,每个值都有自己的类型:

  • 系列
    (系列)
  • 标题
    (常量字符串)
  • 颜色
    (颜色)
  • 线宽
    (整数)
  • 样式
    (整数)
  • transp
    (整数)
  • trackprice
    (bool)
  • histbase
    (浮动)
  • 偏移量(整数)
  • 加入
    (bool)
  • 可编辑
    (常量布尔)
  • show_last
    (常量整数)
下面是您的代码如何调用
plot()

问题在于,这里我们将
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)

你找到解决办法了吗?