Search code examples
pine-scriptpine-script-v4

Undeclared Identifier error in Pinescript while updating to V4


I'm using public indicators to build other public strategies or indicators. I have some issues with this one where i'm getting Undeclared Identifier error and I cannot find the last one to convert from V1 to V4.

Here the original script ( https://fr.tradingview.com/v/5e9WBJwE/ ) and the script i'm working on :

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(false, 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=plot.style_circles, color=color.gray, linewidth=0, title="DummyL")
plot(0, title="MidLine")

hc = d>0?d>d[1]?color.lime:color.green:d<d[1]?color.red:color.orange
plot(d, style=plot.style_columns, color=ehc?hc:color.gray, title="Histo")
sigl = plot(soh?na:pmols, title="PMO Signal", color=color.gray, linewidth=2, title="Signal")
mdl =plot(soh?na:pmol, title="PMO", color=color.black, linewidth=2, title="PMO")

fill(duml, sigl, color.new(color.green, 70), title="PosFill")
fill(duml, mdl, color.new(color.red, 70), title="NegFill")
barcolor(ebc?hc:na)

plot(not soh and slvl?oblvl:na, title="OB Level", color=color.gray, linewidth=2)
plot(not soh and slvl?oslvl:na, title="OS Level", color=color.gray, linewidth=2)

The last error :

line 21: Undeclared identifier 'csf'

Any help would be greatly appreciated.

Thanks


Solution

  • Just to change :

    csf = 0.0
    csf := (src - nz(csf[1])) * sm + nz(csf[1])