尝试在 Tradingview 下画线时无法使用参数调用 'plot'

getting Cannot call 'plot' with arguments when trying to draw a line under Tradingview

我正在使用 Tradingview Pinescript 4.0

我的目标是创建一条改变颜色的线(基于输入值)。如果选择“短”,它将打印一条 20 根柱长的红线。如果选择“多头”,则条形图将为绿色。

我尝试了下面的代码

x_color     = color.yellow
x_transp    = 100.0

if enter_long 
    x_color  := color.teal
    x_transp := 0

if enter_short 
    x_color  := color.red
    x_transp := 0

plot(i_entry_level, color=x_color, transp=x_transp, linewidth=2, title="起始级别")

但我收到以下错误消息:

line 146: Cannot call 'plot' with arguments (input integer, color=series[color], transp=series[float], linewidth=literal integer, title=literal string); available overloads: plot(series[float], const string, series[color], input integer, input integer, input bool, input integer, input float, series[integer], input bool, series[float], const bool, input integer, const integer, string) => plot; plot(<arg_series_type>, const string, <arg_color_type>, input integer, input integer, input bool, input integer, input float, series[integer], input bool, series[float], const bool, input integer, const integer, string) => plot

transp参数不允许使用series。您可以使用解决方法。

x_color     = color.new(color.yellow, 100)
//x_transp    = 100.0

if enter_long 
    x_color  := color.new(color.teal, 0)
    //x_transp := 0

if enter_short 
    x_color  := color.new(color.red, 0)
    //x_transp := 0

plot(i_entry_level, color=x_color, linewidth=2, title="Start Level")