Search code examples
migrationpine-scriptpine-script-v5pine-script-v4transcrypt

Stuck migrating Pinescript v2 to v4


Noob learning here!

after a couple of days trying to convert a pinescript V2 to V4 from a extended script.. I cannot make a clean migration for the next part of the while script.

When save and it’s compiling, The recursive error messages don’t stop and been reading many instructions there, but it’s persistent

What do you think? Could anyone kingly help on this merge? Grateful enormously!!!

The errors are:

Undeclared identifier 'x';
Undeclared identifier 'x';
Undeclared identifier 'swap';
Undeclared identifier 'swap';
Undeclared identifier 'lime';
Undeclared identifier 'red';
Undeclared identifier 'lime';
Undeclared identifier 'red';
Undeclared identifier 'swap3';
Undeclared identifier 'swap2';
Undeclared identifier 'swap4';
Undeclared identifier 'lime';
Undeclared identifier 'red';
Undeclared identifier 'swap4';
Undeclared identifier 'red';
Undeclared identifier 'lime';
Undeclared identifier 'MA_s';

The source code is:

CCI = input(20, "Tend Magic:: Input for CCI")
CCI = input(20)
ATR = input(5, "Tend Magic:: Input for ATRc")
ATR = input(5)
Multiplier= input(1, "Tend Magic :: ATR Multiplier")
Multiplier=input(1,title='ATR Multiplier')
original=input(true,title='original coloring')
original= true
thisCCI = cci(close, CCI)
thisCCI = cci(close, CCI)
lastCCI = nz(thisCCI[1])
lastCCI = nz(thisCCI[1])
bufferDn= high + Multiplier * sma(tr,ATR)
bufferDn= high + Multiplier * sma(tr,ATR)
bufferUp= low - Multiplier * sma(tr,ATR)
bufferUp= low - Multiplier * sma(tr,ATR)
if (thisCCI >= 0 and lastCCI < 0)
if (thisCCI >= 0 and lastCCI < 0)
    bufferUp := bufferDn[1]
    bufferUp := bufferDn[1]
if (thisCCI <= 0 and lastCCI > 0)
if (thisCCI <= 0 and lastCCI > 0)
    bufferDn := bufferUp[1]
    bufferDn := bufferUp[1]
if (thisCCI >= 0)
if (thisCCI >= 0)
    if (bufferUp < bufferUp[1])
    if (bufferUp < bufferUp[1])
        bufferUp := bufferUp[1]
        bufferUp := bufferUp[1]
else
else
    if (thisCCI <= 0)
    if (thisCCI <= 0)
        if (bufferDn > bufferDn[1])
        if (bufferDn > bufferDn[1])
            bufferDn := bufferDn[1]
            bufferDn := bufferDn[1]
x=thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]
x=thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]
swap=x>x[1]?1:x<x[1]?-1:swap[1]
swap=x>x[1]?1:x<x[1]?-1:swap[1]
swap2=swap==1?lime:red
swap2=swap==1?lime:red
swap3=thisCCI >=0 ?lime:red
swap3=thisCCI >=0 ?lime:red
swap4=original?swap3:swap2
swap4=original?swap3:swap2
plot(x,color=swap4,transp=0,linewidth=3)
bullTrendMagic = swap4 == lime and swap4[1] == red
bearTrendMagic = swap4 == red and swap4[1] == lime

I tried to understand the issue and try some instructions that I have read on many resources in order to merge the code to V4 without success :(


Solution

  • Self referenced variables are not allowed anymore starting from v3.

    So something like this:

    //@version=2
    //...
    s = nz(s[1]) + close
    

    Will not work anymore and needs to be written like below:

    //@version=3
    //...
    s = 0.0
    s := nz(s[1]) + close
    

    Convert it to v3 by using this guide and then use the auto convert tool.