Tradingview Indicator from pine script v 2 to version 4

966 views Asked by At

I've been trying for the longest time to convert this script to Version 4.

It keeps giving me a global variable error. I started by adding csf = 0.0 to first declare csf from line 17, then changed line 17 to :=, but it kept giving me error after error. ugh...

Can someone help me with this? Thank you so much!!

// 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)
1

There are 1 answers

0
Help3924 On BEST ANSWER

Someone posted the answer for me, so just sharing here:

Change the calc_csf function to this:

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

and then put

//@version=3

in the top. Press the ... button and select convert to v4