plot - 我可以使用 pine 脚本的三元运算符来指定 plotshape() 中的 style 参数或 plotchar() 中的 char 参数吗?
问题描述
我想我是在要求 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)
,这意味着在脚本执行之前必须知道它的值。为了在运行时确定它的值,它需要是 type "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]
,这是您尝试通过传递一个在运行时可能具有不同值的变量来执行的操作。
编辑:
您始终可以在series
绘图参数中组合您的条件。只有当系列评估为 时,它才会绘图true
。因此,两个形状的两个绘图函数。
//@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)
推荐阅读
- c# - 通过在实体框架中按月份分组来获取总金额
- flutter - 如何测试从异步生成器抛出的异常?
- javascript - React中从父组件传递给子组件的“未定义”?
- flutter - 使用单个 Tabs 栏制作多个脚手架
- sql - 如何在 SQL 中找到两列的差异
- vim - 在 vim 中打开本机终端
- extjs - 如何设置网格的列数据索引,如depart.name
- python - 我想将给定的输入(数字、字符串、浮点数等)置换为长度(给定)
- sql - NodeJS:即使密码正确,bcrypt 也会返回 false
- javascript - 如何在 ESP32 应用程序中使用 ajax 脚本解析 json