我可以使用pine脚本';s三元运算符指定plotshape()中的样式参数或plotchar()中的字符参数?

我可以使用pine脚本';s三元运算符指定plotshape()中的样式参数或plotchar()中的字符参数?,plot,conditional-operator,pine-script,Plot,Conditional Operator,Pine Script,我想我正在要求pine脚本做一些它不是设计用来做的事情,但我想我无论如何都会提出这个问题 我是否可以使用pine脚本的三元运算符指定plotshape()中的style参数或plotchar()中的char参数 例如,类似这样的内容: plotshape( volume, style = (close[0] >= close[1]) ? shape.square : shape.xcross, color = color.red ) plotch

我想我正在要求pine脚本做一些它不是设计用来做的事情,但我想我无论如何都会提出这个问题

我是否可以使用pine脚本的三元运算符指定plotshape()中的style参数或plotchar()中的char参数

例如,类似这样的内容:

plotshape(
     volume, 
     style = (close[0] >= close[1]) ? shape.square : shape.xcross,
     color = color.red
     )
plotchar(
     volume, 
     char  = (close[0] >= close[1]) ? "#" : "•",
     color = color.red
     )
或者像这样:

plotshape(
     volume, 
     style = (close[0] >= close[1]) ? shape.square : shape.xcross,
     color = color.red
     )
plotchar(
     volume, 
     char  = (close[0] >= close[1]) ? "#" : "•",
     color = color.red
     )
编辑:添加了应用于卷窗格的
label.new()
,但无法正确指定
y
y\u loc
样式的示例:


不,你不能<代码>样式
的类型是
样式(输入字符串)
,这意味着在执行脚本之前必须知道其值。为了在运行时确定它的值,它需要是
类型的“series[string]”

如果您试图编译您正试图执行的操作,您可以知道这一点

您将得到以下错误

line 7: Cannot call 'plotshape' with arguments (series=series[bool], title=literal string, style=series[string], location=const string); available overloads: plotshape(series[bool], const string, input string, input string, series[color], input integer, series[integer], const string, series[color], const bool, const string, input integer, const integer, string) => void; plotshape(fun_arg__<arg_series_type>, const string, input string, input string, fun_arg__<arg_color_type>, input integer, series[integer], const string, fun_arg__<arg_textcolor_type>, const bool, const string, input integer, const integer, string) => void

不,你不能<代码>样式的类型是
样式(输入字符串)
,这意味着在执行脚本之前必须知道其值。为了在运行时确定它的值,它需要是
类型的“series[string]”

如果您试图编译您正试图执行的操作,您可以知道这一点

您将得到以下错误

line 7: Cannot call 'plotshape' with arguments (series=series[bool], title=literal string, style=series[string], location=const string); available overloads: plotshape(series[bool], const string, input string, input string, series[color], input integer, series[integer], const string, series[color], const bool, const string, input integer, const integer, string) => void; plotshape(fun_arg__<arg_series_type>, const string, input string, input string, fun_arg__<arg_color_type>, input integer, series[integer], const string, fun_arg__<arg_textcolor_type>, const bool, const string, input integer, const integer, string) => void

如果要打印不同的字符,请使用v4
标签。
其中的字符串可以是非常量

例如:

如果要打印不同的字符,请使用v4
标签。
其中的字符串可以是非常量

例如:

Andre:v4标签”指的是在脚本开头指定
/@version=4
?如果是这样的话,我在版本4中测试了这个想法,但是遗漏了我认为对我的问题可能必要的任何信息。然而,根据@Baris Yakut的说法,这似乎并不重要,因为在Pine的框架内,我的意图似乎是不可能的。你相信有其他方法可以在一个
plotchar()
语句中有条件地绘制两个字符中的一个吗?嘿,Zwi,我用一个例子更新了我的答案,这个例子可能会让你找到你想要的,使用一个
标签。new()
。但是,使用单个
plotchar()
执行此操作是不可能的。感谢您澄清(并提供示例)您实际上指的是
label.new()
。我考虑过使用标签,但它们往往会把图表弄得乱七八糟,因此我决定只满足于将颜色作为相关信息的标记(而不是我最初打算的颜色/形状对)。也就是说,我过去曾使用标签在图表上显示或有文本,因此我应该能够理解您所指的内容…我计划提供一个我所做的示例,但我没有找到发布照片的选项?我只是想到我可以使用您的
标签。new()
建议并指定
stye=label.style\u none
,以保持图表干净,同时还能临时操纵字符和颜色。谢谢安德烈:“v4标签”是指在脚本开头指定
/@version=4
?如果是这样的话,我在版本4中测试了这个想法,但是遗漏了我认为对我的问题可能必要的任何信息。然而,根据@Baris Yakut的说法,这似乎并不重要,因为在Pine的框架内,我的意图似乎是不可能的。你相信有其他方法可以在一个
plotchar()
语句中有条件地绘制两个字符中的一个吗?嘿,Zwi,我用一个例子更新了我的答案,这个例子可能会让你找到你想要的,使用一个
标签。new()
。但是,使用单个
plotchar()
执行此操作是不可能的。感谢您澄清(并提供示例)您实际上指的是
label.new()
。我考虑过使用标签,但它们往往会把图表弄得乱七八糟,因此我决定只满足于将颜色作为相关信息的标记(而不是我最初打算的颜色/形状对)。也就是说,我过去曾使用标签在图表上显示或有文本,因此我应该能够理解您所指的内容…我计划提供一个我所做的示例,但我没有找到发布照片的选项?我只是想到我可以使用您的
标签。new()
建议并指定
stye=label.style\u none
,以保持图表干净,同时还能临时操纵字符和颜色。谢谢谢谢@Baris Yakut。我希望可以有一些后门方法,在一次调用
plotchar()
中有条件地绘制n个字符中的一个,这与我们使用颜色的方式类似。然而,我肯定会相信你的话,它在结构上是不可能的。请参阅我的编辑以了解可能的解决方法。这就是你想要的吗?再次感谢你的建议。实际上,我试图摆脱这种特定的方法:为每个可能的场景/条件编写一个完整的
plotchar()
。为了保持代码简洁,也因为64项的输出限制,我希望有一种方法可以将调节器潜入单个绘图语句中。例如,允许用户访问一个下拉框,从中选择各种不同的形状或字符,而不必直接操作代码,这将是非常好的。然而,提供这些众多选项所需的代码(考虑到Pine脚本的局限性)最终会变得非常混乱,并且很快会消耗到输出限制,因为这可能对用户有帮助,但坐在那里不使用会浪费资源。谢谢@Baris Yakut。我希望会有一些后门的方式