交易视图松树脚本绘图形状函数不适用于条件序列 - 错误在哪里?



我正试图将一个策略Pine Script转换为一个研究策略,只绘制买卖信号,但我不知道如何使函数plotshape工作。我不断收到错误消息:

Cannot call 'plotshape' with arguments (series[bool], style=const
string, text=literal string, color=const color, size=const string,
location=const string, transp=literal bool); 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(<arg_series_type>, const string, input
string, input string, <arg_color_type>, input integer,
series[integer], const string, <arg_textcolor_type>, const bool, const
string, input integer, const integer, string) =void

错误在哪里?

//@version=4 
study(title="Trend Following Long Only", overlay=true)
lookback_length = input(200, type=input.integer, minval=1,
title="Lookback Length") smoother_length = input(3,
type=input.integer, minval=1, title="Smoother Length") atr_length =
input(10, type=input.integer, minval=1, title="ATR Length")
atr_multiplier = input(0.5, type=input.float, minval=0.0, title="ATR
Multiplier")
vola = atr(atr_length) * atr_multiplier price = sma(close, 3)
l = ema(lowest(low, lookback_length), smoother_length) h =
ema(highest(high, lookback_length), smoother_length) center = (h + l)
* 0.5 upper = center + vola lower = center - vola trend = ema(price upper ? 1 : (price < lower ? -1 : 0), 3) c1 = trend < 0 ? upper :
(trend 0 ? lower: center)
buy_signal = crossover(trend, 0) plotshape(buy_signal ? true : na,style=shape.triangleup,text="Buy",color=color.green,size=size.small,location=location.belowbar,transp=false)
sell_signal  = crossunder(trend, 0) plotshape(sell_signal ? true : 
na,style=shape.triangledown,text="Sell",color=color.red,size=size.small,location=location.abovebar,transp=false)
phigh = plot(h, color=color.green) plow = plot(l, color=color.red)
pcenter = plot(center, color=color.black) pclose = plot(close,
transp=100)
clr = trend 0.0 ? color.green : (trend < -0.0 ? color.red :
color.yellow) fill(pcenter, pclose, color=clr, transp=85) fill(phigh,
pcenter, color=color.green, transp=95) fill(plow, pcenter,
color=color.red, transp=95)

问题是您在plotshape()中使用了boolean作为transp=参数
transp参数必须是从0100的整数。

这将起作用:

//@version=4 
study(title="Trend Following Long Only", overlay=true)
lookback_length = input(200, type=input.integer, minval=1, title="Lookback Length") 
smoother_length = input(3, type=input.integer, minval=1, title="Smoother Length") 
atr_length = input(10, type=input.integer, minval=1, title="ATR Length")
atr_multiplier = input(0.5, type=input.float, minval=0.0, title="ATR Multiplier")
vola = atr(atr_length) * atr_multiplier 
price = sma(close, 3)
l = ema(lowest(low, lookback_length), smoother_length) 
h = ema(highest(high, lookback_length), smoother_length) 
center = (h + l) * 0.5 
upper = center + vola 
lower = center - vola 
trend = ema(price > upper ? 1 : (price < lower ? -1 : 0), 3) 
c1 = trend < 0 ? upper : (trend > 0 ? lower : center)
buy_signal = crossover(trend, 0) 
plotshape(buy_signal,style=shape.triangleup,text="Buy",color=color.green,size=size.small,location=location.belowbar,transp=80)
sell_signal = crossunder(trend, 0) 
plotshape(sell_signal,style=shape.triangledown,text="Sell",color=color.red,size=size.small,location=location.abovebar,transp=80)
phigh = plot(h, color=color.green) 
plow = plot(l, color=color.red)
pcenter = plot(center, color=color.black) 
pclose = plot(close,transp=100)
clr = trend > 0.0 ? color.green : (trend < -0.0 ? color.red : color.yellow) 
fill(pcenter, pclose, color=clr, transp=85) 
fill(phigh, pcenter, color=color.green, transp=95) 
fill(plow, pcenter, color=color.red, transp=95)

最新更新