Search code examples
pine-scriptpine-script-v5

PineScript V3 to V5


x1=thisCCI >= 0 ?bufferUp1:thisCCI <= 0 ?bufferDn1:x1[1]

The above code in Pinescript V3 shows no error. It works.

In Pinescript V5, shows the following error message, referring to the last variable in the ternary -> x1[1] :

Undeclared identifier 'x1'

How is this resolved?


Solution

  • Starting v3, Self-referenced variables are removed. So, you need to declare the variable first.

    x1 = 0.0
    x1 := thisCCI >= 0 ? bufferUp1 : thisCCI <= 0 ? bufferDn1 : x1[1]