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 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 有条件地设置为 12。虽然它确实是一系列整数,但系列仍然不同于 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/

相关文章:

pine-script - pine 脚本中的指示器功能

pine-script - 如何延迟 pine 脚本中生成的警报,如果图表时间范围为 10m,任何人都可以帮助将警报延迟 n 秒吗?

pine-script - 在 Trading View 中对 Pine 脚本编写的策略进行回测时,出现 "No Data"错误的原因是什么?

algorithmic-trading - 为什么这段代码不能在 Pine Script 4 中运行? "Undeclared identifier"

pine-script - Pine 脚本绘图线连接两条线

pine-script - (Tradingview - Pine 脚本) 将 iff 函数转换为 v5 错误

pine-script - 计算值的小数精度

pine-script - 将系列转换为绘图文本的常量字符串时出现问题

pine-script - Tradingview Pine 脚本给出了线条绘制功能的分辨率错误

pine-script - 如何在 pine 脚本中以柱线开盘价输入多头/空头策略?