我正在尝试将策略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)
最佳答案
问题是您在boolean
中使用transp=
作为plotshape()
参数。transp
参数必须是从0
到100
的整数。
这将起作用:
//@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)
关于plot - Tradingview Pine Script plotshape函数不适用于条件序列-错误在哪里?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/65486865/