我如何提出一个好问题?为什么使用plotshape时会出现错误?

mly*_*own 1 pine-script

var x = '123'
x := x + '211'
plotshape(true, style=shape.labelup, color=close>open ?color.green:color.red, text= x, location=location.belowbar)
Run Code Online (Sandbox Code Playgroud)

将出现错误“第 39 行:无法使用plotshape参数调用(文字 bool、style=const string、color=series[color]、text=string、location=const string);可用的重载:plotshape(series [bool],const string,输入字符串,输入字符串,series [color],输入整数,series [integer],const string,series [color],const bool,const string,输入整数,字符串) => 无效;plotshape(fun_arg__,常量字符串,输入字符串,输入字符串,fun_arg__,输入整数,系列[整数],常量字符串,fun_arg__,常量布尔,常量字符串,输入整数,字符串)=> void'

Pin*_*ucF 5

plotshape()text=参数需要一个const 字符串,并且您正在使用一系列字符串参数: https://www.tradingview.com/pine-script-reference/v4/#fun_plotshape

在此输入图像描述

//@version=4
study("", "", true)
barColor = close > open ? color.green : color.red
a = "Bar is\n" + (barColor == color.green ? "green" : "red")
if bar_index % 10 == 0
    label.new(bar_index, na, a, yloc = yloc.belowbar, color = barColor, textcolor = barColor, style = label.style_triangleup)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 不会。但是您可以使用 `var a = 'a' + 'b'` 因为变量 `a` 将是编译时已知的 *const string* 类型。请注意,您可以使用标签绘制系列文本,这将为您提供更大的灵活性,前提是您不需要显示超过最后约 50 个标签。在我的答案中添加了一个代码片段。 (2认同)