Search code examples
pine-scriptpine-script-v5pine-script-v4

How to convert Well Wilders MA to v4?


wwma(l,p) =>

wwma = (nz(wwma[1]) * (l - 1) + p) / l

I'm going to convert it to v4, but I got a error, Undeclared identifier 'wwma'. Then changed to:

wwma = 0.

wwma := (nz(wwma[1]) * (l - 1) + p) / l

Still an error:

Undeclared identifier 'l';
Undeclared identifier 'p';
'wwma' is not a function.

Any help would be appreciated.


Solution

  • Create a function f_wwma with l and p arguments as shown below:

    f_wwma(l, p) =>
        wwma = 0.
        wwma := (nz(wwma[1]) * (l - 1) + p) / l
    

    Then you can call that function with defined length (l) and source (p) arguments:

    wwma = f_wwma(50, close)
    
    plot(wwma)