![](/img/trans.png)
[英]Pine Script Beginner - Cannot use 'plotshape' in local scope
[英]Can I use pine script's ternary operator to specify the style argument in plotshape() or the char argument in plotchar()?
我想我是在要求 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
)
编辑:添加了应用于卷窗格的label.new()
示例,但无法正确指定y
、 y_loc
或style
:
你不能。 style
的类型是style (input string)
,这意味着在脚本执行之前必须知道它的值。 为了在运行时确定它的值,它需要是"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
在第一个括号中,它告诉您它不能使用style=series[string]
调用此 function ,这是您尝试通过传递一个在运行时可能具有不同值的变量来执行的操作。
编辑:您始终可以在 plot 的series
参数中组合您的条件。 如果系列评估为true
,它将仅 plot 。 因此,两个 plot 对两种形状起作用。
//@version=4
study("My Script", overlay=true)
mainCond = close > 0
circleCond = close > open
squareCond = open >= close
plotshape(series=mainCond and circleCond, title="Circle", style=shape.circle, location=location.belowbar, color=color.green)
plotshape(series=mainCond and squareCond, title="Square", style=shape.square, location=location.belowbar, color=color.red)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.