将Tradingview松树脚本从版本2更改为版本3(或4)时遇到问题

时间:2020-09-10 06:25:19

标签: pine-script

我正在尝试将此脚本转换为版本4(或至少转换为版本3,然后将其自动转换为版本4。目前,我认为代码位于版本2中。

从第16行开始,它一直给我“未声明的标识符”错误。我先尝试先声明i1 = 0,但这没有用。

有人可以帮我吗?非常感谢!!

study("Coral Trend Indicator [LazyBear] Buy-Sell with Alarm by coinsspor", overlay=true)
src=close
sm =input(21, title="Smoothing Period")
cd = input(0.4, title="Constant D")
ebc=input(false, title="Color Bars")
ribm=input(false, title="Ribbon Mode")
di = (sm - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (cd * cd + cd * cd * cd)
c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
i1 = c1*src + c2*nz(i1[1])
i2 = c1*i1 + c2*nz(i2[1])
i3 = c1*i2 + c2*nz(i3[1])
i4 = c1*i3 + c2*nz(i4[1])
i5 = c1*i4 + c2*nz(i5[1])
i6 = c1*i5 + c2*nz(i6[1])

bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
// --------------------------------------------------------------------------
// For the Pinescript coders: Determining trend based on the mintick step. 
// --------------------------------------------------------------------------
//bfrC = bfr - nz(bfr[1]) > syminfo.mintick ? green : bfr - nz(bfr[1]) < syminfo.mintick ? red : blue
bfrC = bfr > nz(bfr[1]) ? green : bfr < nz(bfr[1])  ? red : blue
tc=ebc?gray:bfrC
plot(ribm?na:bfr, title="Trend", linewidth=3, style=circles, color=tc)
bgcolor(ribm?bfrC:na, transp=50)
barcolor(ebc?bfrC:na)
KDbuy=bfr > nz(bfr[1])
KDsell= bfr < nz(bfr[1])
//last_signal= 0
long_final  = KDbuy  and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == -1)
short_final = KDsell and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == 1)
alertcondition(long_final or short_final, title="B/S Coral", message="{{interval}}, B/S Coral")
alertcondition(long_final, title="Buy Coral", message="{{interval}}, Buy Coral")
alertcondition(short_final, title="Sell Coral", message="{{interval}}, Sell Coral")

bgcolor( (nz(last_signal[1]) == 0 or nz(last_signal[1]) == -1) ? green : red, transp=93)

bgcolor( long_final? green : na, transp=93)
bgcolor( short_final? red : na, transp=93)



last_signal= long_final ? 1 : short_final ? -1 : last_signal[1]



plotshape(long_final, style=shape.cross, location=location.belowbar, color=#00ff00,size=size.tiny,title="buy label",text="BUY",textcolor=#00ff00, transp=0)
plotshape(short_final, style=shape.cross, location=location.abovebar, color=red,size=size.tiny,title="sell label",text="SELL",textcolor=red, transp=0)

1 个答案:

答案 0 :(得分:0)

这是v4版本。在v3和v4中,对变量的过去引用需要先声明,就像对ix变量所做的那样:

//@version=4
study("Coral Trend Indicator [LazyBear] Buy-Sell with Alarm by coinsspor", overlay=true)
src=close
sm =input(21, title="Smoothing Period")
cd = input(0.4, title="Constant D")
ebc=input(false, title="Color Bars")
ribm=input(false, title="Ribbon Mode")
di = (sm - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (cd * cd + cd * cd * cd)
c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
var i1 = 0.
var i2 = 0.
var i3 = 0.
var i4 = 0.
var i5 = 0.
var i6 = 0.
i1 := c1*src + c2*i1
i2 := c1*i1 +  c2*i2
i3 := c1*i2 +  c2*i3
i4 := c1*i3 +  c2*i4
i5 := c1*i4 +  c2*i5
i6 := c1*i5 +  c2*i6

bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
// --------------------------------------------------------------------------
// For the Pinescript coders: Determining trend based on the mintick step. 
// --------------------------------------------------------------------------
//bfrC = bfr - nz(bfr[1]) > syminfo.mintick ? green : bfr - nz(bfr[1]) < syminfo.mintick ? red : blue
bfrC = bfr > nz(bfr[1]) ? color.green : bfr < nz(bfr[1])  ? color.red : color.blue
tc=ebc?color.gray:bfrC
plot(ribm?na:bfr, title="Trend", linewidth=3, style=plot.style_circles, color=tc)
bgcolor(ribm?bfrC:na, transp=50)
barcolor(ebc?bfrC:na)
KDbuy=bfr > nz(bfr[1])
KDsell= bfr < nz(bfr[1])
last_signal = false
long_final = false
short_final = false
long_final := KDbuy  and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == -1)
short_final := KDsell and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == 1)
alertcondition(long_final or short_final, title="B/S Coral", message="{{interval}}, B/S Coral")
alertcondition(long_final, title="Buy Coral", message="{{interval}}, Buy Coral")
alertcondition(short_final, title="Sell Coral", message="{{interval}}, Sell Coral")

bgcolor( (nz(last_signal[1]) == 0 or nz(last_signal[1]) == -1) ? color.green : color.red, transp=93)

bgcolor( long_final? color.green : na, transp=93)
bgcolor( short_final? color.red : na, transp=93)



last_signal := long_final ? 1 : short_final ? -1 : last_signal[1]



plotshape(long_final, style=shape.cross, location=location.belowbar, color=#00ff00,size=size.tiny,title="buy label",text="BUY",textcolor=#00ff00, transp=0)
plotshape(short_final, style=shape.cross, location=location.abovebar, color=color.red,size=size.tiny,title="sell label",text="SELL",textcolor=color.red, transp=0)