从 pine 脚本 v 2 到版本 4 的 Tradingview 指标

Tradingview Indicator from pine script v 2 to version 4

我花了很长时间尝试将此脚本转换为版本 4。

它一直给我一个 global variable 错误。我首先添加 csf = 0.0 以首先从第 17 行声明 csf,然后将第 17 行更改为 :=,但它不断给我错误.呃...

有人可以帮我解决这个问题吗?非常感谢!!

// DecisionPoint Price Momentum Oscillator [LazyBear]
// https://www.tradingview.com/script/5e9WBJwE-DecisionPoint-Price-Momentum-Oscillator-LazyBear/
// @version=2
study(title="DecisionPoint Price Momentum Oscillator [LazyBear]", shorttitle="DPMO_LB")
src=input(close, title="Source")
length1=input(35, title="First Smoothing")
length2=input(20, title="Second Smoothing")
siglength=input(10, title="Signal Smoothing")
fr=input(true, title="Fill Region")
ehc=input(true, title="Enable Histo Color")
ebc=input(false, title="Enable Bar Colors")
soh=input(false, title="Show Only Histo")
slvl=input(false, title="Show OB/OS Levels")
oblvl=input(2.5, title="OB Level"), oslvl=input(-2.5, title="OS Level")
calc_csf(src, length) => 
    sm = 2.0/length
    csf=(src - nz(csf[1])) * sm + nz(csf[1])
    csf
i=(src/nz(src[1], src))*100
pmol2=calc_csf(i-100, length1)
pmol=calc_csf( 10 * pmol2, length2)
pmols=ema(pmol, siglength)
d=pmol-pmols
duml=plot(not soh and fr?(d>0?pmol:pmols):na, style=circles, color=gray, linewidth=0, title="DummyL")
plot(0, title="MidLine")
hc=d>0?d>d[1]?lime:green:d<d[1]?red:orange
plot(d, style=columns, color=ehc?hc:gray, transp=0, title="Histo")
sigl=plot(soh?na:pmols, title="PMO Signal", color=gray, linewidth=2, title="Signal")
mdl=plot(soh?na:pmol, title="PMO", color=black, linewidth=2, title="PMO")
fill(duml, sigl, green, transp=0, title="PosFill")
fill(duml, mdl, red, transp=0, title="NegFill", transp=0)
barcolor(ebc?hc:na)
plot(not soh and slvl?oblvl:na, title="OB Level", color=gray, linewidth=2, transp=0)
plot(not soh and slvl?oslvl:na, title="OS Level", color=gray, linewidth=2, transp=0)

有人帮我贴出答案,所以在这里分享一下:

将 calc_csf 函数更改为:

calc_csf(src, length) =>
    sm = 2.0 / length
    csf = 0.0
    csf := (src - nz(csf[1])) * sm + nz(csf[1])
    csf

然后放

//@version=3

在顶部。按 ... 按钮 select 转换为 v4